¿Las bibliotecas de clases portátiles manejan declaraciones / referencias condicionales?

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?

preguntado el 01 de febrero de 12 a las 04:02

1 Respuestas

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.

Respondido 01 Feb 12, 08:02

Thanks. I hadn't considered reflection. - Matt Johnson-Pinta

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.