MethodAttributes Enumeration
Specifies flags for method attributes. These flags are defined in the corhdr.h file.
This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.
[Visual Basic] <Flags> <Serializable> Public Enum MethodAttributes [C#] [Flags] [Serializable] public enum MethodAttributes [C++] [Flags] [Serializable] __value public enum MethodAttributes [JScript] public Flags Serializable enum MethodAttributes
Members
| Member name | Description | Value |
|---|---|---|
| Abstract Supported by the .NET Compact Framework. | Indicates that the class does not provide an implementation of this method. | 1024 |
| Assembly Supported by the .NET Compact Framework. | Indicates that the method is accessible to any class of this assembly. | 3 |
| CheckAccessOnOverride | Indicates that the method can only be overridden when it is also accessible. | 512 |
| FamANDAssem Supported by the .NET Compact Framework. | Indicates that the method is accessible to members of this type and its derived types that are in this assembly only. | 2 |
| Family Supported by the .NET Compact Framework. | Indicates that the method is accessible only to members of this class and its derived classes. | 4 |
| FamORAssem Supported by the .NET Compact Framework. | Indicates that the method is accessible to derived classes anywhere, as well as to any class in the assembly. | 5 |
| Final Supported by the .NET Compact Framework. | Indicates that the method cannot be overridden. | 32 |
| HasSecurity Supported by the .NET Compact Framework. | Indicates that the method has security associated with it. Reserved flag for runtime use only. | 16384 |
| HideBySig Supported by the .NET Compact Framework. | Indicates that the method hides by name and signature; otherwise, by name only. | 128 |
| MemberAccessMask Supported by the .NET Compact Framework. | Retrieves accessibility information. | 7 |
| NewSlot Supported by the .NET Compact Framework. | Indicates that the method always gets a new slot in the vtable. | 256 |
| PinvokeImpl Supported by the .NET Compact Framework. | Indicates that the method implementation is forwarded through PInvoke (Platform Invocation Services). | 8192 |
| Private Supported by the .NET Compact Framework. | Indicates that the method is accessible only to the current class. | 1 |
| PrivateScope Supported by the .NET Compact Framework. | Indicates that the member cannot be referenced. | 0 |
| Public Supported by the .NET Compact Framework. | Indicates that the method is accessible to any object for which this object is in scope. | 6 |
| RequireSecObject Supported by the .NET Compact Framework. | Indicates that the method calls another method containing security code. Reserved flag for runtime use only. | 32768 |
| ReservedMask Supported by the .NET Compact Framework. | Indicates a reserved flag for runtime use only. | 53248 |
| ReuseSlot Supported by the .NET Compact Framework. | Indicates that the method will reuse an existing slot in the vtable. This is the default behavior. | 0 |
| RTSpecialName Supported by the .NET Compact Framework. | Indicates that the common language runtime checks the name encoding. | 4096 |
| SpecialName Supported by the .NET Compact Framework. | Indicates that the method is special. The name describes how this method is special. | 2048 |
| Static Supported by the .NET Compact Framework. | Indicates that the method is defined on the type; otherwise, it is defined per instance. | 16 |
| UnmanagedExport Supported by the .NET Compact Framework. | Indicates that the managed method is exported by thunk to unmanaged code. | 8 |
| Virtual Supported by the .NET Compact Framework. | Indicates that the method is virtual. | 64 |
| VtableLayoutMask Supported by the .NET Compact Framework. | Retrieves vtable attributes. | 256 |
Example
[Visual Basic, C#, C++] The following example displays the attributes of the specified method.
[Visual Basic] Imports System Imports System.Reflection Imports Microsoft.VisualBasic Class AttributesSample Public Sub Mymethod(ByVal int1m As Integer, ByRef str2m As String, ByRef str3m As String) str2m = "in Mymethod" End Sub 'Mymethod Public Shared Function Main(ByVal args() As String) As Integer Console.WriteLine("Reflection.MethodBase.Attributes Sample") ' Get the type of a chosen class. Dim MyType As Type = Type.GetType("AttributesSample") ' Get the method Mymethod on the type. Dim Mymethodbase As MethodBase = MyType.GetMethod("Mymethod") ' Display the method name and signature. Console.WriteLine("Mymethodbase = {0}", Mymethodbase) ' Get the MethodAttribute enumerated value. Dim Myattributes As MethodAttributes = Mymethodbase.Attributes ' Display the flags that are set. PrintAttributes(GetType(System.Reflection.MethodAttributes), CInt(Myattributes)) Return 0 End Function 'Main Public Shared Sub PrintAttributes(ByVal attribType As Type, ByVal iAttribValue As Integer) If Not attribType.IsEnum Then Console.WriteLine("This type is not an enum.") Return End If Dim fields As FieldInfo() = attribType.GetFields((BindingFlags.Public Or BindingFlags.Static)) Dim i As Integer For i = 0 To fields.Length - 1 Dim fieldvalue As Integer = CType(fields(i).GetValue(Nothing), Int32) If (fieldvalue And iAttribValue) = fieldvalue Then Console.WriteLine(fields(i).Name) End If Next i End Sub 'PrintAttributes End Class 'AttributesSample [C#] 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); } } } } [C++] #using <mscorlib.dll> using namespace System; using namespace System::Reflection; using namespace System::Runtime::InteropServices; public __gc class AttributesSample { public: void Mymethod (int int1m, [Out] String** str2m, String** str3m) { *str2m = S"in Mymethod"; } }; void PrintAttributes(Type* attribType, int iAttribValue) { if (!attribType->IsEnum) {Console::WriteLine(S"This type is not an enum."); return;} FieldInfo* fields[] = attribType->GetFields(static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Static)); for (int i = 0; i < fields->Length; i++) { int fieldvalue = *dynamic_cast<Int32*>(fields[i]->GetValue(0)); if ((fieldvalue & iAttribValue) == fieldvalue) { Console::WriteLine(fields[i]->Name); } } } int main() { Console::WriteLine (S"Reflection.MethodBase.Attributes Sample"); // Get the type of the chosen class. Type* MyType = Type::GetType(S"AttributesSample"); // Get the method Mymethod on the type. MethodBase* Mymethodbase = MyType->GetMethod(S"Mymethod"); // Display the method name and signature. Console::WriteLine(S"Mymethodbase = {0}", 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; }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Reflection
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework
Assembly: Mscorlib (in Mscorlib.dll)