英語で読む

次の方法で共有


MethodAttributes 列挙型

定義

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

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

C#
[System.Flags]
public enum MethodAttributes
C#
[System.Flags]
[System.Serializable]
public enum MethodAttributes
C#
[System.Flags]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum MethodAttributes
継承
MethodAttributes
属性

フィールド

名前 説明
Abstract 1024

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

Assembly 3

このアセンブリのすべてのクラスがメソッドにアクセスできることを示します。

CheckAccessOnOverride 512

アクセス可能な場合に限りオーバーライドできるメソッドであることを示します。

FamANDAssem 2

この型と、このアセンブリ内の派生した型のメンバーだけが、メソッドにアクセスできることを示します。

Family 4

このクラスとこのクラスの派生クラスのメンバーだけがメソッドにアクセスできることを示します。

FamORAssem 5

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

Final 32

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

HasSecurity 16384

メソッドにセキュリティが関連付けられていることを示します。 Runtime 専用に予約されているフラグです。

HideBySig 128

メソッドが名前とシグネチャで隠ぺいされることを示します。このフラグが設定されていない場合は、メソッドは名前だけで隠ぺいされます。

MemberAccessMask 7

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

NewSlot 256

メソッドが vtable で必ず新しいスロットを取得することを示します。

PinvokeImpl 8192

メソッドの実装が PInvoke (Platform Invocation Services) を通じて転送されることを示します。

Private 1

現在のクラスだけからメソッドにアクセスできることを示します。

PrivateScope 0

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

Public 6

このオブジェクトがスコープ内に入っている全オブジェクトからメソッドにアクセスできることを示します。

RequireSecObject 32768

メソッドが、セキュリティ コードを含んでいる別のメソッドを呼び出すことを示します。 Runtime 専用に予約されているフラグです。

ReservedMask 53248

Runtime 専用に予約されているフラグを示します。

ReuseSlot 0

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

RTSpecialName 4096

共通言語ランタイムが名前のエンコーディングを確認することを示します。

SpecialName 2048

メソッドが特別であることを示します。 メソッドが特別である理由は名前で説明します。

Static 16

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

UnmanagedExport 8

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

Virtual 64

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

VtableLayoutMask 256

vtable 属性を取得します。

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

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

適用対象

製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0