A custom attribute based on bool value
using System;
public class TrueFalseAttribute : Attribute
{
bool bWritten;
public bool Written()
{
return bWritten;
}
public TrueFalseAttribute(bool Written)
{
bWritten = Written;
}
}
[TrueFalseAttribute(true)]
public class Class1
{
}
[TrueFalseAttribute(false)]
public class Class2
{
}
class MainClass
{
public static void Main()
{
TrueFalseAttribute u;
Console.Write("Class1 TrueFalseAttribute attribute: ");
u = (TrueFalseAttribute) Attribute.GetCustomAttribute(typeof(Class1), typeof(TrueFalseAttribute));
Console.WriteLine(u.Written());
Console.Write("Class2 TrueFalseAttribute attribute: ");
u = (TrueFalseAttribute) Attribute.GetCustomAttribute(typeof(Class2), typeof(TrueFalseAttribute));
Console.WriteLine(u.Written());
}
}
Output Class1 TrueFalseAttribute attribute: True
Class2 TrueFalseAttribute attribute: False
|
HTML code for linking to this page:
Related in same category :
-
-
-
-
-
-
|