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

필드

Abstract 1024

클래스에서 이 메서드를 구현하지 않습니다.

Assembly 3

이 어셈블리의 모든 클래스에서 메서드에 액세스할 수 있습니다.

CheckAccessOnOverride 512

메서드에 액세스할 수 있을 때만 메서드를 재정의할 수 있음을 나타냅니다.

FamANDAssem 2

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

Family 4

이 클래스 및 파생 클래스의 멤버만 메서드에 액세스할 수 있습니다.

FamORAssem 5

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

Final 32

메서드를 재정의할 수 없음을 나타냅니다.

HasSecurity 16384

메서드에 이와 관련된 보안이 있습니다. 런타임 전용의 예약된 플래그입니다.

HideBySig 128

메서드를 이름 및 시그니처별로 숨깁니다. 그렇지 않으면 이름별로만 숨깁니다.

MemberAccessMask 7

액세스 가능성 정보를 검색합니다.

NewSlot 256

메서드가 항상 vtable에 새 슬롯을 가져옵니다.

PinvokeImpl 8192

메서드 구현이 PInvoke(Platform Invocation Services)를 통해 전달됩니다.

Private 1

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

PrivateScope 0

멤버를 참조할 수 없습니다.

Public 6

이 개체 범위 내의 개체만 메서드에 액세스할 수 있습니다.

RequireSecObject 32768

메서드가 보안 코드를 포함하는 다른 메서드를 호출합니다. 런타임 전용의 예약된 플래그입니다.

ReservedMask 53248

런타임 전용의 예약된 플래그를 나타냅니다.

ReuseSlot 0

메서드에서 vtable의 기존 슬롯을 다시 사용합니다. 기본 동작입니다.

RTSpecialName 4096

공용 언어 런타임에서 이름 인코딩을 확인합니다.

SpecialName 2048

특수한 메서드입니다. 메서드의 이름은 이 메서드가 특수함을 나타냅니다.

Static 16

메서드가 형식에 정의되어 있습니다. 그렇지 않으면 인스턴스 단위로 정의됩니다.

UnmanagedExport 8

썽크에서 관리되는 메서드를 비관리 코드로 보냅니다.

Virtual 64

가상 메서드입니다.

VtableLayoutMask 256

vtable 특성을 검색합니다.

예제

다음 예제에서는 지정된 메서드의 특성을 표시합니다.

using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;

public ref class AttributesSample
{
public:
   void Mymethod( int int1m, [Out]interior_ptr<String^> str2m, interior_ptr<String^> str3m )
   {
       *str2m = "in Mymethod";
   }
};

void PrintAttributes( Type^ attribType, int iAttribValue )
{
   if (  !attribType->IsEnum )
   {
      Console::WriteLine( "This type is not an enum." );
      return;
   }

   array<FieldInfo^>^fields = attribType->GetFields( static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Static) );
   for ( int i = 0; i < fields->Length; i++ )
   {
      int fieldvalue = safe_cast<Int32>(fields[ i ]->GetValue( nullptr ));
      if ( (fieldvalue & iAttribValue) == fieldvalue )
      {
         Console::WriteLine( fields[ i ]->Name );
      }
   }
}

int main()
{
   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 = {0}", Mymethodbase );

   // Get the MethodAttribute enumerated value.
   MethodAttributes Myattributes = Mymethodbase->Attributes;

   // Display the flags that are set.
   PrintAttributes( System::Reflection::MethodAttributes::typeid, (int)Myattributes );
   return 0;
}
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

적용 대상