本文整理匯總了C#中System.Diagnostics.ConditionalAttribute類的典型用法代碼示例。如果您正苦於以下問題:C# ConditionalAttribute類的具體用法?C# ConditionalAttribute怎麽用?C# ConditionalAttribute使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ConditionalAttribute類屬於System.Diagnostics命名空間,在下文中一共展示了ConditionalAttribute類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Method1
#define CONDITION1
#define CONDITION2
using System;
using System.Diagnostics;
class Test
{
static void Main()
{
Console.WriteLine("Calling Method1");
Method1(3);
Console.WriteLine("Calling Method2");
Method2();
Console.WriteLine("Using the Debug class");
Debug.Listeners.Add(new ConsoleTraceListener());
Debug.WriteLine("DEBUG is defined");
}
[Conditional("CONDITION1")]
public static void Method1(int x)
{
Console.WriteLine("CONDITION1 is defined");
}
[Conditional("CONDITION1"), Conditional("CONDITION2")]
public static void Method2()
{
Console.WriteLine("CONDITION1 or CONDITION2 is defined");
}
}
輸出:
Calling Method1 CONDITION1 is defined Calling Method2 CONDITION1 or CONDITION2 is defined Using the Debug class DEBUG is defined