A System.Reflection.MethodAttributes value that signifies the attributes of the method reflected by the current instance.
All members have a set of attributes, which are defined in relation to the specific type of member.
To get the System.Reflection.MethodAttributes, first get the type. From the type, get the method. From the method, get the System.Reflection.MethodAttributes.
The following example demonstrates using this property to obtain the attributes of three methods.
C# Example
using System; using System.Reflection; abstract class MyBaseClass { abstract public void MyPublicInstanceMethod(); } class MyDerivedClass : MyBaseClass { public override void MyPublicInstanceMethod() {} private static void MyPrivateStaticMethod() {} } class MethodAttributesExample { static void PrintMethodAttributes(Type t) { string str; MethodInfo[] miAry = t.GetMethods( BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly ); foreach (MethodInfo mi in miAry) { Console.WriteLine("Method {0} is: ", mi.Name); str = ((mi.Attributes & MethodAttributes.Static) != 0) ? "Static" : "Instance"; Console.Write(str + " "); str = ((mi.Attributes & MethodAttributes.Public) != 0) ? "Public" : "Not-Public"; Console.Write(str + " "); str = ((mi.Attributes & MethodAttributes.HideBySig) != 0) ? "HideBySig" : "Hide-by-name"; Console.Write(str + " "); str = ((mi.Attributes & MethodAttributes.Abstract) != 0) ? "Abstract" : String.Empty; Console.WriteLine(str); } } public static void Main() { PrintMethodAttributes(typeof(MyBaseClass)); PrintMethodAttributes(typeof(MyDerivedClass)); } }
The output is
Method MyPublicInstanceMethod is: