C# !Conditional attribute?

前端 未结 7 1331
既然无缘
既然无缘 2020-12-08 18:08

Does C# have a not Conditional (!Conditional, NotConditional, Conditional(!)) attribute?


i know C#

7条回答
  •  一个人的身影
    2020-12-08 18:43

    True we can't 'NOT' ConditionalAttribute, but we can 'NOT' the condition as presented below.

    // at the begining of the code before uses
    #if DUMMY
    #undef NOT_DUMMY
    #else
    #define NOT_DUMMY
    #endif
    
    // somewhere in class
    [Conditional("NOT_DUMMY")]
    public static void ShowDebugStringNOTDUMMY(string s)
    {
      Debug.Print("ShowDebugStringNOTDUMMY");
    }
    
    
    [Conditional("DUMMY")]
    public static void ShowDebugStringDUMMY(string s)
    {
      Debug.Print("ShowDebugStringDUMMY");
    }
    

    hope this helps you solve your problem ;)

提交回复
热议问题