Reputation: 241515
I have a class library that I am sharing between .Net Framework and Silverlight using two linked projects and the linked-files technique.
I'd like to convert that to a single Portable Class Library, but I have one bit of code that is different between the two. I currently use a conditional compiler statements to separate the implementations of this one file.
#if SILVERLIGHT
...
#else
...
#endif
Will this be honored in the PCL?
Also, the part of code that is NOT silverlight makes reference to a third-party regular .Net class library. The PCL still compiles, but I cannot use it in Silverlight because of this reference. Is there any way to tell the PCL to only include it for the .Net usage?
Upvotes: 1
Views: 1185
Reputation: 27343
That pattern implements compile-time portability instead of run-time portability.
If you have tons of Silverlight-specific code, then you don't really have a portable library--you should consider factoring out the Silverlight-specific code to a separate assembly and having that specialized assembly take a dependency on your PCL.
If you have very little Silverlight-specific code, you could consider binding to your Silverlight dependencies dynamically at run-time using reflection. Your PCL can then be used in any context, but will "gracefully upgrade" to Silverlight if Silverlight is present.
Upvotes: 1