extends Attribute
using System;
public class MainClass
{
public static void Main()
{
UnitTest u;
Console.Write("Class1 UnitTest attribute: ");
u = (UnitTest) Attribute.GetCustomAttribute(typeof(Class1), typeof(UnitTest));
Console.WriteLine(u.Written());
Console.Write("Class2 UnitTest attribute: ");
u = (UnitTest) Attribute.GetCustomAttribute(typeof(Class2), typeof(UnitTest));
Console.WriteLine(u.Written());
}
}
public class UnitTest : Attribute
{
bool bWritten;
public bool Written()
{
return bWritten;
}
public UnitTest(bool Written)
{
bWritten = Written;
}
}
// apply the UnitTest attribute to two classes
[UnitTest(true)]
public class Class1
{
}
[UnitTest(false)]
public class Class2
{
}
Related examples in the same category