MethodAttributes Enumeration
This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.
Namespace: System.ReflectionAssembly: mscorlib (in mscorlib.dll)
[SerializableAttribute] [FlagsAttribute] [ComVisibleAttribute(true)] public enum MethodAttributes
/** @attribute SerializableAttribute() */ /** @attribute FlagsAttribute() */ /** @attribute ComVisibleAttribute(true) */ public enum MethodAttributes
SerializableAttribute FlagsAttribute ComVisibleAttribute(true) public enum MethodAttributes
| Member name | Description | |
|---|---|---|
![]() | Abstract | Indicates that the class does not provide an implementation of this method. |
![]() | Assembly | Indicates that the method is accessible to any class of this assembly. |
| CheckAccessOnOverride | Indicates that the method can only be overridden when it is also accessible. | |
![]() | FamANDAssem | Indicates that the method is accessible to members of this type and its derived types that are in this assembly only. |
![]() | Family | Indicates that the method is accessible only to members of this class and its derived classes. |
![]() | FamORAssem | Indicates that the method is accessible to derived classes anywhere, as well as to any class in the assembly. |
![]() | Final | Indicates that the method cannot be overridden. |
![]() | HasSecurity | Indicates that the method has security associated with it. Reserved flag for runtime use only. |
![]() | HideBySig | Indicates that the method hides by name and signature; otherwise, by name only. |
![]() | MemberAccessMask | Retrieves accessibility information. |
![]() | NewSlot | Indicates that the method always gets a new slot in the vtable. |
![]() | PinvokeImpl | Indicates that the method implementation is forwarded through PInvoke (Platform Invocation Services). |
![]() | Private | Indicates that the method is accessible only to the current class. |
![]() | PrivateScope | Indicates that the member cannot be referenced. |
![]() | Public | Indicates that the method is accessible to any object for which this object is in scope. |
![]() | RequireSecObject | Indicates that the method calls another method containing security code. Reserved flag for runtime use only. |
![]() | ReservedMask | Indicates a reserved flag for runtime use only. |
![]() | ReuseSlot | Indicates that the method will reuse an existing slot in the vtable. This is the default behavior. |
![]() | RTSpecialName | Indicates that the common language runtime checks the name encoding. |
![]() | SpecialName | Indicates that the method is special. The name describes how this method is special. |
![]() | Static | Indicates that the method is defined on the type; otherwise, it is defined per instance. |
![]() | UnmanagedExport | Indicates that the managed method is exported by thunk to unmanaged code. |
![]() | Virtual | Indicates that the method is virtual. |
![]() | VtableLayoutMask | Retrieves vtable attributes. |
The following example displays the attributes of the specified method.
using System; using System.Reflection; class AttributesSample { public void Mymethod (int int1m, out string str2m, ref string str3m) { str2m = "in Mymethod"; } public static int Main(string[] args) { Console.WriteLine ("Reflection.MethodBase.Attributes Sample"); // Get the type of the chosen class. Type MyType = Type.GetType("AttributesSample"); // Get the method Mymethod on the type. MethodBase Mymethodbase = MyType.GetMethod("Mymethod"); // Display the method name and signature. Console.WriteLine("Mymethodbase = " + Mymethodbase); // Get the MethodAttribute enumerated value. MethodAttributes Myattributes = Mymethodbase.Attributes; // Display the flags that are set. PrintAttributes(typeof(System.Reflection.MethodAttributes), (int) Myattributes); return 0; } public static void PrintAttributes(Type attribType, int iAttribValue) { if (!attribType.IsEnum) {Console.WriteLine("This type is not an enum."); return;} FieldInfo[] fields = attribType.GetFields(BindingFlags.Public | BindingFlags.Static); for (int i = 0; i < fields.Length; i++) { int fieldvalue = (Int32)fields[i].GetValue(null); if ((fieldvalue & iAttribValue) == fieldvalue) { Console.WriteLine(fields[i].Name); } } } }
import System.*;
import System.Reflection.*;
class AttributesSample
{
public void MyMethod(int int1m,
/** @ref
*/ String str2m,
/** @ref
*/ String str3m)
{
str2m = "in MyMethod";
} //MyMethod
public static void main(String[] args)
{
Console.WriteLine("Reflection.MethodBase.Attributes Sample");
// Get the type of the chosen class.
Type myType = Type.GetType("AttributesSample");
// Get the method MyMethod on the type.
MethodBase myMethodBase = myType.GetMethod("MyMethod");
// Display the method name and signature.
Console.WriteLine(("myMethodBase = " + myMethodBase));
// Get the MethodAttribute enumerated value.
MethodAttributes myAttributes = myMethodBase.get_Attributes();
// Display the flags that are set.
PrintAttributes(System.Reflection.MethodAttributes.class.ToType(),
(int)(myAttributes));
} //main
public static void PrintAttributes(Type attribType, int iAttribValue)
{
if (!(attribType.get_IsEnum())) {
Console.WriteLine("This type is not an enum.");
return ;
}
FieldInfo fields[] = attribType.GetFields(
(BindingFlags.Public | BindingFlags.Static));
for(int i=0; i < fields.length; i++) {
int fieldValue = (int)((Int32)(fields[i].GetValue(null)));
if ((fieldValue & iAttribValue) == fieldValue ) {
Console.WriteLine(fields[i].get_Name());
}
}
} //PrintAttributes
} //AttributesSample
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
