public static void Main()
Console.WriteLine("Hello World");
Console.WriteLine(test.getProp2Attribute());
Console.WriteLine(test.getClassAttribute());
[MyAttribute(Name = "Test A Class")]
public override string prop1 {get; set;}
[MyAttribute(Name = "Test Prop2")]
public string prop2 {get; set;}
public virtual string prop1 { get; set; }
public string getProp2Attribute()
var type = this.GetType();
var memInfo = type.GetMember("prop2");
var myAttributes = memInfo[0].GetCustomAttributes(typeof(MyAttribute), false);
if (myAttributes.Length > 0)
MyAttribute myAttribute = myAttributes[0] as MyAttribute;
public string getClassAttribute()
var type = this.GetType();
var myAttributes = type.GetCustomAttributes(true);
if (myAttributes.Length > 0)
MyAttribute myAttribute = myAttributes[0] as MyAttribute;
public class MyAttribute : Attribute
public string Name {get;set;}