This documentation is archived and is not being maintained.
MethodAttributes Enumeration
Visual Studio 2010
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.
Namespace: System.ReflectionAssembly: mscorlib (in mscorlib.dll)
| Member name | Description | |
|---|---|---|
![]() | MemberAccessMask | Retrieves accessibility information. |
![]() | PrivateScope | Indicates that the member cannot be referenced. |
![]() | Private | Indicates that the method is accessible only to the current class. |
![]() | FamANDAssem | Indicates that the method is accessible to members of this type and its derived types that are in this assembly only. |
![]() | Assembly | Indicates that the method is accessible to any class of this assembly. |
![]() | 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. |
![]() | Public | Indicates that the method is accessible to any object for which this object is in scope. |
![]() | Static | Indicates that the method is defined on the type; otherwise, it is defined per instance. |
![]() | Final | Indicates that the method cannot be overridden. |
![]() | Virtual | Indicates that the method is virtual. |
![]() | HideBySig | Indicates that the method hides by name and signature; otherwise, by name only. |
| CheckAccessOnOverride | Indicates that the method can only be overridden when it is also accessible. | |
![]() | VtableLayoutMask | Retrieves vtable attributes. |
![]() | ReuseSlot | Indicates that the method will reuse an existing slot in the vtable. This is the default behavior. |
![]() | NewSlot | Indicates that the method always gets a new slot in the vtable. |
![]() | Abstract | Indicates that the class does not provide an implementation of this method. |
![]() | SpecialName | Indicates that the method is special. The name describes how this method is special. |
![]() | PinvokeImpl | Indicates that the method implementation is forwarded through PInvoke (Platform Invocation Services). |
![]() | UnmanagedExport | Indicates that the managed method is exported by thunk to unmanaged code. |
![]() | RTSpecialName | Indicates that the common language runtime checks the name encoding. |
![]() | ReservedMask | Indicates a reserved flag for runtime use only. |
![]() | HasSecurity | Indicates that the method has security associated with it. Reserved flag for runtime use only. |
![]() | RequireSecObject | Indicates that the method calls another method containing security code. Reserved flag for runtime use only. |
The following example displays the attributes of the specified method.
using namespace System; using namespace System::Reflection; using namespace System::Runtime::InteropServices; public ref class AttributesSample { public: void Mymethod( int int1m, [Out]interior_ptr<String^> str2m, interior_ptr<String^> str3m ) { *str2m = "in Mymethod"; } }; void PrintAttributes( Type^ attribType, int iAttribValue ) { if ( !attribType->IsEnum ) { Console::WriteLine( "This type is not an enum." ); return; } array<FieldInfo^>^fields = attribType->GetFields( static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Static) ); for ( int i = 0; i < fields->Length; i++ ) { int fieldvalue = safe_cast<Int32>(fields[ i ]->GetValue( nullptr )); if ( (fieldvalue & iAttribValue) == fieldvalue ) { Console::WriteLine( fields[ i ]->Name ); } } } int main() { 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 = {0}", Mymethodbase ); // Get the MethodAttribute enumerated value. MethodAttributes Myattributes = Mymethodbase->Attributes; // Display the flags that are set. PrintAttributes( System::Reflection::MethodAttributes::typeid, (int)Myattributes ); return 0; }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show:
