Use GetCustomAttribute
using System;
using System.Reflection;
class Starter {
static void Main() {
Type tObj = typeof(Starter);
MethodInfo method = tObj.GetMethod("AMethod");
Attribute attrib = Attribute.GetCustomAttribute(method, typeof(ObsoleteAttribute));
ObsoleteAttribute obsolete = (ObsoleteAttribute)attrib;
Console.WriteLine("Obsolete Message: " + obsolete.Message);
}
[Obsolete("Deprecated function.", false)]
public void AMethod() {
}
}
|
HTML code for linking to this page:
Related in same category :
-
|