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 enum MethodAttributes

Member nameDescription
Supported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsAbstractIndicates that the class does not provide an implementation of this method.
Supported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsAssemblyIndicates that the method is accessible to any class of this assembly.
Supported by Portable Class LibrarySupported in .NET for Windows Store appsCheckAccessOnOverrideIndicates that the method can only be overridden when it is also accessible.
Supported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsFamANDAssemIndicates that the method is accessible to members of this type and its derived types that are in this assembly only.
Supported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsFamilyIndicates that the method is accessible only to members of this class and its derived classes.
Supported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsFamORAssemIndicates that the method is accessible to derived classes anywhere, as well as to any class in the assembly.
Supported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsFinalIndicates that the method cannot be overridden.
Supported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsHasSecurityIndicates that the method has security associated with it. Reserved flag for runtime use only.
Supported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsHideBySigIndicates that the method hides by name and signature; otherwise, by name only.
Supported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsMemberAccessMaskRetrieves accessibility information.
Supported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsNewSlotIndicates that the method always gets a new slot in the vtable.
Supported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsPinvokeImplIndicates that the method implementation is forwarded through PInvoke (Platform Invocation Services).
Supported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsPrivateIndicates that the method is accessible only to the current class.
Supported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsPrivateScopeIndicates that the member cannot be referenced.
Supported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsPublicIndicates that the method is accessible to any object for which this object is in scope.
Supported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsRequireSecObjectIndicates that the method calls another method containing security code. Reserved flag for runtime use only.
Supported by the XNA FrameworkReservedMaskIndicates a reserved flag for runtime use only.
Supported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReuseSlotIndicates that the method will reuse an existing slot in the vtable. This is the default behavior.
Supported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsRTSpecialNameIndicates that the common language runtime checks the name encoding.
Supported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsSpecialNameIndicates that the method is special. The name describes how this method is special.
Supported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsStaticIndicates that the method is defined on the type; otherwise, it is defined per instance.
Supported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsUnmanagedExportIndicates that the managed method is exported by thunk to unmanaged code.
Supported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsVirtualIndicates that the method is virtual.
Supported by the XNA FrameworkSupported in .NET for Windows Store appsVtableLayoutMaskRetrieves 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);
            }
        }
    }
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft