User Tools

Site Tools

blog:2023-09-22_c_debug_and_release_mode_conditional_function



2023-09-22 C#: DEBUG and RELEASE mode conditional function

  • When writing a program, in some cases you may want a certain piece of code to be executed only in Debug mode but not in Release mode.
  • Using
    [Conditional("DEBUG")]
    for conditional execution between DEBUG and RELEASE modes.
  • With [Conditional(“DEBUG”)] declaration, the function only been executed in DEBUG mode

Example

  • [Conditional("DEBUG")]
    private static void DEBUG_DumpCanSendMessage()
    {
      Console.WriteLine(">> " 
        + Global.CanMsgSend.ID.ToString("X03") + ":"
        + " " + Global.CanMsgSend.DATA[0].ToString("X02")
        + " " + Global.CanMsgSend.DATA[1].ToString("X02")
        + " " + Global.CanMsgSend.DATA[2].ToString("X02")
        + " " + Global.CanMsgSend.DATA[3].ToString("X02")
        + " " + Global.CanMsgSend.DATA[4].ToString("X02")
        + " " + Global.CanMsgSend.DATA[5].ToString("X02")
        + " " + Global.CanMsgSend.DATA[6].ToString("X02")
        + " " + Global.CanMsgSend.DATA[7].ToString("X02")
        );
    }
    
    [Conditional("DEBUG")]
    private static void DEBUG_DumpCanReceivedMessage()
    {
      Console.WriteLine("<< "
        + Global.CanMsgReceived.ID.ToString("X03") + ":"
        + " " + Global.CanMsgReceived.DATA[0].ToString("X02")
        + " " + Global.CanMsgReceived.DATA[1].ToString("X02")
        + " " + Global.CanMsgReceived.DATA[2].ToString("X02")
        + " " + Global.CanMsgReceived.DATA[3].ToString("X02")
        + " " + Global.CanMsgReceived.DATA[4].ToString("X02")
        + " " + Global.CanMsgReceived.DATA[5].ToString("X02")
        + " " + Global.CanMsgReceived.DATA[6].ToString("X02")
        + " " + Global.CanMsgReceived.DATA[7].ToString("X02")
        );
    }

TAGS

  • 54 person(s) visited this page until now.

Permalink blog/2023-09-22_c_debug_and_release_mode_conditional_function.txt · Last modified: 2023/09/22 13:21 by jethro

oeffentlich