MethodAttributes 列挙型

定義

メソッド属性のフラグを指定します。 これらのフラグは corhdr.h ファイルで定義されています。

この列挙体は、メンバー値のビットごとの組み合わせをサポートしています。

public enum class MethodAttributes
[System.Flags]
public enum MethodAttributes
[System.Flags]
[System.Serializable]
public enum MethodAttributes
[System.Flags]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum MethodAttributes
[<System.Flags>]
type MethodAttributes = 
[<System.Flags>]
[<System.Serializable>]
type MethodAttributes = 
[<System.Flags>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type MethodAttributes = 
Public Enum MethodAttributes
継承
MethodAttributes
属性

フィールド

名前 説明
PrivateScope 0

メンバーを参照できないことを示します。

ReuseSlot 0

メソッドが vtable 内の既存のスロットを再利用することを示します。 これは既定の動作です。

Private 1

メソッドが現在のクラスにのみアクセス可能であることを示します。

FamANDAssem 2

このアセンブリ内にあるこの型とその派生型のメンバーがメソッドにアクセス可能であることを示します。

Assembly 3

このアセンブリの任意のクラスからメソッドにアクセス可能であることを示します。

Family 4

このクラスとその派生クラスのメンバーのみがメソッドにアクセス可能であることを示します。

FamORAssem 5

メソッドが、任意の場所の派生クラスとアセンブリ内の任意のクラスからアクセス可能であることを示します。

Public 6

このオブジェクトがスコープ内にある任意のオブジェクトからメソッドにアクセス可能であることを示します。

MemberAccessMask 7

アクセシビリティ情報を取得します。

UnmanagedExport 8

マネージド メソッドがサンクによってアンマネージ コードにエクスポートされることを示します。

Static 16

メソッドが型で定義されていることを示します。それ以外の場合は、インスタンスごとに定義されます。

Final 32

メソッドをオーバーライドできないことを示します。

Virtual 64

メソッドが仮想であることを示します。

HideBySig 128

メソッドが名前とシグネチャで非表示であることを示します。それ以外の場合は名前のみ。

NewSlot 256

メソッドが常に vtable 内の新しいスロットを取得することを示します。

VtableLayoutMask 256

vtable 属性を取得します。

CheckAccessOnOverride 512

メソッドにアクセスできる場合にのみ、メソッドをオーバーライドできることを示します。

Abstract 1024

クラスがこのメソッドの実装を提供していないことを示します。

SpecialName 2048

メソッドが特殊であることを示します。 この名前は、このメソッドが特殊な方法を表します。

RTSpecialName 4096

共通言語ランタイムが名前のエンコードをチェックすることを示します。

PinvokeImpl 8192

メソッドの実装が PInvoke (プラットフォーム呼び出しサービス) を介して転送されることを示します。

HasSecurity 16384

メソッドにセキュリティが関連付けられていることを示します。 ランタイム専用の予約済みフラグ。

RequireSecObject 32768

メソッドがセキュリティ コードを含む別のメソッドを呼び出したことを示します。 ランタイム専用の予約済みフラグ。

ReservedMask 53248

ランタイムでのみ使用する予約済みフラグを示します。

次の例では、指定したメソッドの属性を表示します。

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 = (int)fields[i].GetValue(null);
            if ((fieldvalue & iAttribValue) == fieldvalue)
            {
                Console.WriteLine(fields[i].Name);
            }
        }
    }
}
Imports System.Reflection

Class AttributesSample

    Public Sub Mymethod(ByVal int1m As Integer, ByRef str2m As String, ByRef str3m As String)
        str2m = "in Mymethod"
    End Sub


    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
End Class

適用対象