Preprocessor Directives Reflection Injection

…衆ロ難τιáo~ 提交于 2019-12-11 15:41:18

问题


How to inject C# Preprocessor Directives to an interface by Reflection ?

Example :
I want to inject #if SILVERLIGHT to any WCF service contract interface.


回答1:


Short answer: you can't.
Slightly longer answer: you question doesn't even make sense in the first place.

Preprocessor directives are processed before compilation. The result of that processing is the new, modified, source code. That source code then gets compiled.

For example, if the SILVERLIGHT symbol is not defined at the time of compilation, then the whole code between #if SiLVERLIGHT and #endif will be completely ignored by the compiler as if it wasn't even there.




回答2:


That's not possible. As per the name, preprocessor directives exist only just before compile time. Nowhere else.



来源:https://stackoverflow.com/questions/12023791/preprocessor-directives-reflection-injection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!