Can I use the #if processor on a static / const member?

I have a class in my project that contains a global configuration, as follows:

public class Config {
    public const bool LOGGING_ENABLED = false;
}

Then I want to use this element to write a preprocessor directive, for example:

#if LOGGING_ENABLED
    [Logging]
    public class MyClass: ContextBoundObject
#else
    public class MyClass
#endif
    {
        ...
    }

But it is clear that it LOGGING_ENABLEDwill appear as undefined, since in fact it does not refer to Config.LOGGING_ENABLED. Is there a way to refer to constant members in another class? I do not want to put #define LOGGING_ENABLEDat the beginning of each class file, which is detrimental to the whole purpose of this.

+4
source share
3 answers

. # #. "" #. , #if .

, #. .

. , LOGGING_ENABLED ( ).

, . , , , , . . , . , .

+2

#define LOGGING_ENABLED , // , .

+1

#, :

  • 2 : , . , LOGGING_ENABLED.

  • System.Diagnostics.Conditional.

+1

All Articles