Export (0) Print
Expand All
Expand Minimize

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.

Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)

<SerializableAttribute> _
<FlagsAttribute> _
<ComVisibleAttribute(True)> _
Public Enumeration MethodAttributes
Dim instance As MethodAttributes

/** @attribute SerializableAttribute() */ 
/** @attribute FlagsAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public enum MethodAttributes
public enum MethodAttributes

 Member nameDescription
Supported by the .NET Compact FrameworkAbstractIndicates that the class does not provide an implementation of this method. 
Supported by the .NET Compact FrameworkAssemblyIndicates that the method is accessible to any class of this assembly. 
CheckAccessOnOverrideIndicates that the method can only be overridden when it is also accessible. 
Supported by the .NET Compact FrameworkFamANDAssemIndicates that the method is accessible to members of this type and its derived types that are in this assembly only. 
Supported by the .NET Compact FrameworkFamilyIndicates that the method is accessible only to members of this class and its derived classes. 
Supported by the .NET Compact FrameworkFamORAssemIndicates that the method is accessible to derived classes anywhere, as well as to any class in the assembly. 
Supported by the .NET Compact FrameworkFinalIndicates that the method cannot be overridden. 
Supported by the .NET Compact FrameworkHasSecurityIndicates that the method has security associated with it. Reserved flag for runtime use only. 
Supported by the .NET Compact FrameworkHideBySigIndicates that the method hides by name and signature; otherwise, by name only. 
Supported by the .NET Compact FrameworkMemberAccessMaskRetrieves accessibility information. 
Supported by the .NET Compact FrameworkNewSlotIndicates that the method always gets a new slot in the vtable. 
Supported by the .NET Compact FrameworkPinvokeImplIndicates that the method implementation is forwarded through PInvoke (Platform Invocation Services). 
Supported by the .NET Compact FrameworkPrivateIndicates that the method is accessible only to the current class. 
Supported by the .NET Compact FrameworkPrivateScopeIndicates that the member cannot be referenced. 
Supported by the .NET Compact FrameworkPublicIndicates that the method is accessible to any object for which this object is in scope. 
Supported by the .NET Compact FrameworkRequireSecObjectIndicates that the method calls another method containing security code. Reserved flag for runtime use only. 
Supported by the .NET Compact FrameworkReservedMaskIndicates a reserved flag for runtime use only. 
Supported by the .NET Compact FrameworkReuseSlotIndicates that the method will reuse an existing slot in the vtable. This is the default behavior. 
Supported by the .NET Compact FrameworkRTSpecialNameIndicates that the common language runtime checks the name encoding. 
Supported by the .NET Compact FrameworkSpecialNameIndicates that the method is special. The name describes how this method is special. 
Supported by the .NET Compact FrameworkStaticIndicates that the method is defined on the type; otherwise, it is defined per instance. 
Supported by the .NET Compact FrameworkUnmanagedExportIndicates that the managed method is exported by thunk to unmanaged code. 
Supported by the .NET Compact FrameworkVirtualIndicates that the method is virtual. 
Supported by the .NET Compact FrameworkVtableLayoutMaskRetrieves vtable attributes. 

The following example displays the attributes of the specified method.

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.")
        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
            End If
        Next i
    End Sub 'PrintAttributes
End Class 'AttributesSample

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.
    } //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  ) {
    } //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.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

© 2015 Microsoft