當前位置: 首頁>>代碼示例>>C#>>正文


C# Switch類代碼示例

本文整理匯總了C#中System.Diagnostics.Switch的典型用法代碼示例。如果您正苦於以下問題:C# Switch類的具體用法?C# Switch怎麽用?C# Switch使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Switch類屬於System.Diagnostics命名空間,在下文中一共展示了Switch類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1:

// The following are possible values for the new switch.
public enum MethodTracingSwitchLevel
{
    Off = 0,
    EnteringMethod = 1,
    ExitingMethod = 2,
    Both = 3,
}
開發者ID:.NET開發者,項目名稱:System.Diagnostics,代碼行數:8,代碼來源:Switch

示例2: MyMethodTracingSwitch

public class MyMethodTracingSwitch : Switch
{
     protected bool outExit;
     protected bool outEnter;
     protected MethodTracingSwitchLevel level;

     public MyMethodTracingSwitch(string displayName, string description) :
         base(displayName, description)
     {
     }

     public MethodTracingSwitchLevel Level
     {
         get
         {
             return level;
         }
         set
         {
             SetSwitchSetting((int)value);
         }
     }

     protected void SetSwitchSetting(int value)
     {
         if (value < 0)
         {
             value = 0;
         }
         if (value > 3)
         {
             value = 3;
         }

         level = (MethodTracingSwitchLevel)value;

         outEnter = false;
         if ((value == (int)MethodTracingSwitchLevel.EnteringMethod) ||
             (value == (int)MethodTracingSwitchLevel.Both))
         {
             outEnter = true;
         }

         outExit = false;
         if ((value == (int)MethodTracingSwitchLevel.ExitingMethod) ||
             (value == (int)MethodTracingSwitchLevel.Both))
         {
             outExit = true;
         }
     }

     public bool OutputExit
     {
         get
         {
             return outExit;
         }
     }

     public bool OutputEnter
     {
         get
         {
             return outEnter;
         }
     }
 }
開發者ID:.NET開發者,項目名稱:System.Diagnostics,代碼行數:67,代碼來源:Switch

示例3: MyMethodTracingSwitch

public class Class1
{
    /* Create an instance of MyMethodTracingSwitch.*/
    static MyMethodTracingSwitch mySwitch =
        new MyMethodTracingSwitch("Methods", "Trace entering and exiting method");

    public static void Main()
    {
        // Add the console listener to see trace messages as console output
        Trace.Listeners.Add(new ConsoleTraceListener(true));
        Debug.AutoFlush = true;

        // Set the switch level to both enter and exit
        mySwitch.Level = MethodTracingSwitchLevel.Both;

        // Write a diagnostic message if the switch is set to entering.
        Debug.WriteLineIf(mySwitch.OutputEnter, "Entering Main");

        // Insert code to handle processing here...

        // Write another diagnostic message if the switch is set to exiting.
        Debug.WriteLineIf(mySwitch.OutputExit, "Exiting Main");
    }
}
開發者ID:.NET開發者,項目名稱:System.Diagnostics,代碼行數:24,代碼來源:Switch

示例4: BooleanSwitch

private static BooleanSwitch boolSwitch = new BooleanSwitch("mySwitch",
    "Switch in config file");

public static void Main( )
{
    //...
    Console.WriteLine("Boolean switch {0} configured as {1}",
        boolSwitch.DisplayName, boolSwitch.Enabled.ToString());
    if (boolSwitch.Enabled)
    {
        //...
    }
}
開發者ID:.NET開發者,項目名稱:System.Diagnostics,代碼行數:13,代碼來源:Switch


注:本文中的System.Diagnostics.Switch類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。