MethodAttributes MethodAttributes MethodAttributes MethodAttributes Enum

Definition

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.

public enum class MethodAttributes
[System.Flags]
[System.Runtime.InteropServices.ComVisible(true)]
public enum MethodAttributes
type MethodAttributes = 
Public Enum MethodAttributes
Inheritance
MethodAttributesMethodAttributesMethodAttributesMethodAttributes
Attributes

Fields

Abstract Abstract Abstract Abstract 1024

Indicates that the class does not provide an implementation of this method.

Assembly Assembly Assembly Assembly 3

Indicates that the method is accessible to any class of this assembly.

CheckAccessOnOverride CheckAccessOnOverride CheckAccessOnOverride CheckAccessOnOverride 512

Indicates that the method can only be overridden when it is also accessible.

FamANDAssem FamANDAssem FamANDAssem FamANDAssem 2

Indicates that the method is accessible to members of this type and its derived types that are in this assembly only.

Family Family Family Family 4

Indicates that the method is accessible only to members of this class and its derived classes.

FamORAssem FamORAssem FamORAssem FamORAssem 5

Indicates that the method is accessible to derived classes anywhere, as well as to any class in the assembly.

Final Final Final Final 32

Indicates that the method cannot be overridden.

HasSecurity HasSecurity HasSecurity HasSecurity 16384

Indicates that the method has security associated with it. Reserved flag for runtime use only.

HideBySig HideBySig HideBySig HideBySig 128

Indicates that the method hides by name and signature; otherwise, by name only.

MemberAccessMask MemberAccessMask MemberAccessMask MemberAccessMask 7

Retrieves accessibility information.

NewSlot NewSlot NewSlot NewSlot 256

Indicates that the method always gets a new slot in the vtable.

PinvokeImpl PinvokeImpl PinvokeImpl PinvokeImpl 8192

Indicates that the method implementation is forwarded through PInvoke (Platform Invocation Services).

Private Private Private Private 1

Indicates that the method is accessible only to the current class.

PrivateScope PrivateScope PrivateScope PrivateScope 0

Indicates that the member cannot be referenced.

Public Public Public Public 6

Indicates that the method is accessible to any object for which this object is in scope.

RequireSecObject RequireSecObject RequireSecObject RequireSecObject 32768

Indicates that the method calls another method containing security code. Reserved flag for runtime use only.

ReservedMask ReservedMask ReservedMask ReservedMask 53248

Indicates a reserved flag for runtime use only.

ReuseSlot ReuseSlot ReuseSlot ReuseSlot 0

Indicates that the method will reuse an existing slot in the vtable. This is the default behavior.

RTSpecialName RTSpecialName RTSpecialName RTSpecialName 4096

Indicates that the common language runtime checks the name encoding.

SpecialName SpecialName SpecialName SpecialName 2048

Indicates that the method is special. The name describes how this method is special.

Static Static Static Static 16

Indicates that the method is defined on the type; otherwise, it is defined per instance.

UnmanagedExport UnmanagedExport UnmanagedExport UnmanagedExport 8

Indicates that the managed method is exported by thunk to unmanaged code.

Virtual Virtual Virtual Virtual 64

Indicates that the method is virtual.

VtableLayoutMask VtableLayoutMask VtableLayoutMask VtableLayoutMask 256

Retrieves vtable attributes.

Examples

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;
}
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);
            }
        }
    }
}
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

Applies to