CSharp examples for Custom Type:Attribute
Use Conditional attribute
// csc /define:DEBUG Main.cs using System;/*from ww w.j a v a2 s. c o m*/ using System.Diagnostics; //The ConditionalAttribute lives here public class Foo { [Conditional("DEBUG")] public void OnlyWhenDebugIsDefined( ) { Console.WriteLine("DEBUG is defined"); } } public class AttributeTest { public static void Main( ) { Foo f = new Foo( ); f.OnlyWhenDebugIsDefined( ); } }