public class A
{
[Description("This method does something")]
public void TestMethod()
{
//Do Something
}
}
My question is how do I get the string value of the Description Attribute using reflection.
public class A
{
[Description("This method does something")]
public void TestMethod()
{
//Do Something
}
}
My question is how do I get the string value of the Description Attribute using reflection.
var description = ((DescriptionAttribute)typeof (A).GetMethod("TestMethod")
.GetCustomAttribute(typeof (DescriptionAttribute))).Description;
You can try like this:
MethodBase m = typeof(A).GetMethod("TestMethod");;
Description d = (Description)m.GetCustomAttributes(typeof(Description), true)[0] ;
string str= d.Value;