问题
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