Use GetCustomAttribute : Attributes : Reflection C# Source Code


Custom Search

C# Source Code » Reflection » Attributes »

 

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:

Follow Navioo On Twitter

C# Source Code

 Navioo Reflection
» Attributes