简体   繁体   中英

Preprocessor Directives Reflection Injection

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

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM