static void New( ) { }
public static void Main( )
{
Old( );
}
}
//---------------------------------
using System;
using System.Diagnostics;
class Class1
{
[Conditional("DEBUG")]
public static void debugMethod()
{
Console.WriteLine("Debug Mode Method");
}
public static void releaseMethod()
{
Console.WriteLine("Release mode method");
}
public static void Main()
{
Class1.debugMethod(); // called only in debug mode
Class1.releaseMethod(); // called only in Release mode
Console.ReadLine();
}
}
//---------------------------------------
using System;
[AttributeUsage(AttributeTargets.All)]
public class Developer : System.Attribute
{
//Private fields.
private string name;
private string level;
public Developer(string name,string level)
{
this.name = name;
this.level = level;
}
public virtual string Name
{
get {return name;}
}
public virtual string Level
{
get {return level;}
}
}
[Developer("sliit", "25")]
class MainApp
{
public static void Main()
{
//Call function to get and display the attribute.
GetAttribute(typeof(MainApp));
}
public static void GetAttribute(Type t)
{
//Get instance of the attribute.
Developer MyAttribute = (Developer) Attribute.GetCustomAttribute(t,
typeof (Developer));
if(null == MyAttribute)
{
Console.WriteLine("The attribute was not found.");
}
else
{
//Get the Name value.
Console.WriteLine("The Name Attribute is: {0}." , MyAttribute.Name);
Console.WriteLine("The Level Attribute is: {0}." ,
MyAttribute.Level);
}
}
}