does it make sense to use #If Debug Then and #If LIVE Then

Or should we use another practice to execute certain code if we re in debug while we execute another code while we are in release. what is a good practice to do that pls.

Thanks




Answer this question

does it make sense to use #If Debug Then and #If LIVE Then

  • Kent Waldrop Fe08

    R.Tutus wrote:

    Perfect. That answers my question.

    How about if we want to include several methods in debug only. that means we should include as many

    [System.Diagnostics.Conditional("DEBUG")] as methods or can we use a single

    [System.Diagnostics.Conditional("DEBUG")] with multiple methods and close it at the end. is that possible.

    Thanks a lot

    The ConditionalAttribute can be applied to methods or classes. If you wanted all members of a class to be debug-only you could apply Conditional("DEBUG") to the entire class. Otherwise, you'll need to apply the ConditionalAttribute to each and every method you want debug-only.

  • Bryan_Ta

    The ConditionalAttribute was added in .NET to avoid having to use the preprocessor to filter out debug code during release builds. Generally, it's suggested that ConditionalAttribute be used on a method definition in order for the method to be "empty" during release builds. For example:

    [System.Diagnostics.Conditional("DEBUG")]

    void DebugOnly()

    {

    // do something knowing it will only be performed in debug mode.

    }

    The benefit to this is no #if DEBUG...#endif need be added to calls to DebugOnly()...



  • mr4100

    Thanks Peter

  • Emanuel Dejanu

    just in code. how can we know if we in debug or in release mode so that in case we are in release mode, we perform certain tasks that we don t want to do in debug mode.

    Thanks



  • kgkidd

    Perfect. That answers my question.

    How about if we want to include several methods in debug only. that means we should include as many

    [System.Diagnostics.Conditional("DEBUG")] as methods or can we use a single

    [System.Diagnostics.Conditional("DEBUG")] with multiple methods and close it at the end. is that possible.

    Thanks a lot



  • does it make sense to use #If Debug Then and #If LIVE Then