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
특성

필드

Name Description
PrivateScope 0

멤버를 참조할 수 없음을 나타냅니다.

ReuseSlot 0

메서드가 vtable의 기존 슬롯을 다시 사용한다는 것을 나타냅니다. 이 옵션은 기본 동작입니다.

Private 1

메서드가 현재 클래스에만 액세스할 수 있음을 나타냅니다.

FamANDAssem 2

이 형식의 멤버와 이 어셈블리에만 있는 파생 형식이 메서드에 액세스할 수 있음을 나타냅니다.

Assembly 3

이 어셈블리의 모든 클래스에서 메서드에 액세스할 수 있음을 나타냅니다.

Family 4

이 클래스의 멤버와 해당 파생 클래스에서만 메서드에 액세스할 수 있음을 나타냅니다.

FamORAssem 5

어셈블리의 모든 클래스뿐만 아니라 어디에서나 파생 클래스에 메서드에 액세스할 수 있음을 나타냅니다.

Public 6

이 개체가 범위에 있는 모든 개체에 메서드에 액세스할 수 있음을 나타냅니다.

MemberAccessMask 7

접근성 정보를 검색합니다.

UnmanagedExport 8

관리되는 메서드가 thunk에 의해 관리되지 않는 코드로 내보내지 않음을 나타냅니다.

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

적용 대상