//====水之真谛====//
//上善若水,润物无声//
/* http://blog.csdn.net/FantasiaX */
//#define NOBUG
//#define BUGED // C#的宏定义必须出现在所有代码之前。当前我们只让BUGED宏有效。
//#define LI
#define ZHANG
using System;
using System.Diagnostics; // 注意:这是为了使用包含在此名称空间中的ConditionalAttribute特性
namespace AttributeDemo1
{
class ToolKit
{
[ConditionalAttribute("LI")] // Attribute名称的长记法
[ConditionalAttribute("BUGED")]
public static void Method1() { Console.WriteLine("Created By Li, Buged."); }
[ConditionalAttribute("LI")]
[ConditionalAttribute("NOBUG")]
public static void Method2() { Console.WriteLine("Created By Li, NoBug."); }
[Conditional("ZHANG")] // Attribute名称的短记法
[Conditional("BUGED")]
public static void Method3() { Console.WriteLine("Created By Zhang, Buged."); }
[Conditional("ZHANG")]
[Conditional("NOBUG")]
public static void Method4() { Console.WriteLine("Created By Zhang, NoBug."); }
}
class Program
{
static void Main(string[] args)
{
// 虽然方法都被调用了,但只有符合条件的才会被执行。
ToolKit.Method1();
ToolKit.Method2();
ToolKit.Method3();
ToolKit.Method4();
/*
Created By Zhang, Buged.
Created By Zhang, NoBug.
请按任意键继续. . .
*/
}
}
}