Need .NET code to execute only when in debug configuration

前端 未结 8 925
闹比i
闹比i 2021-01-30 10:38

I have some code that access an API out on the web. One of the API\'s parameters allows me to let them know that I am testing.

I would like to only set this parameter in

8条回答
  •  再見小時候
    2021-01-30 11:23

    The following is safe to use:

    var isDebug = false;
    #if DEBUG
        isDebug = System.Diagnostics.Debugger.IsAttached;
    #endif
    
    if (isDebug) {
        // Do something
    }
    

提交回复
热议问题