C# !Conditional attribute?

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

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


i know C#

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-08 18:51

    Just adding my 2 cents, three years down the line :-) ... I use a [Conditional("DEBUG")] method to set an IsDebugMode property to check the reverse. Hacky, but it works:

    private bool _isDebugMode = false;
    public bool IsDebugMode
    {
        get
        {
            CheckDebugMode();
            return _isDebugMode;
        }
    }
    
    [Conditional("DEBUG")]
    private void CheckDebugMode()
    {
        _isDebugMode = true;
    }
    
    private void DisplaySplashScreen()
    {
        if (IsDebugMode) return;
    
        var splashScreenViewModel = new SplashScreenVM(500)
        {
            Header = "MyCompany Deals",
            Title = "Main Menu Test",
            LoadingMessage = "Creating Repositories...",
            VersionString = string.Format("v{0}.{1}.{2}",
                GlobalInfo.Version_Major, GlobalInfo.Version_Minor, GlobalInfo.Version_Build)
        };
    
        SplashScreenFactory.CreateSplashScreen(splashScreenViewModel);
    }
    

提交回复
热议问题