다음을 통해 공유


MethodBase.Attributes 속성

이 메서드와 관련된 특성을 가져옵니다.

네임스페이스: System.Reflection
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
Public MustOverride ReadOnly Property Attributes As MethodAttributes
‘사용 방법
Dim instance As MethodBase
Dim value As MethodAttributes

value = instance.Attributes
public abstract MethodAttributes Attributes { get; }
public:
virtual property MethodAttributes Attributes {
    MethodAttributes get () abstract;
}
/** @property */
public abstract MethodAttributes get_Attributes ()
public abstract function get Attributes () : MethodAttributes

속성 값

MethodAttributes 값 중 하나입니다.

설명

모든 멤버에는 특정 형식의 멤버와의 관계로 정의된 일련의 특성이 있습니다.

MethodAttributes를 가져오려면 먼저 형식을 가져옵니다. 이 형식에서 메서드를 가져옵니다. 메서드에서 MethodAttributes를 가져옵니다.

구현자 참고 사항 메서드가 public, private, final, virtual 등의 메서드인지 여부를 확인하려면 Attributes 속성을 사용합니다.

예제

다음 코드 예제에서는 사용자 정의 메서드 Mymethod의 특성을 표시합니다.

Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic

Class AttributesSample

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

    Public Shared Function Main(ByVal args() As String) As Integer
        Console.WriteLine("Reflection.MethodBase.Attributes Sample")

        ' Get the type.
        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.
        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 'PrintAttributes
End Class 'AttributesSample
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.
        Type MyType = Type.GetType("AttributesSample");
 
        // Get the method Mymethod on the type.
        MethodBase Mymethodbase = MyType.GetMethod("Mymethod");
 
        // Display the method name.
        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);
            }
        }
    }
}
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.
   Type^ MyType = Type::GetType( "AttributesSample" );

   // Get the method Mymethod on the type.
   MethodBase^ Mymethodbase = MyType->GetMethod( "Mymethod" );

   // Display the method name.
   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;
}
import System.*;
import System.Reflection.*;

class AttributesSample
{   
    public void MyMethod(int int1m,
        /** @ref
         */ String str2m,
        /** @ref
         */ String str3m)
    {
        str2m = "in MyMethod";
    } //MyMethod

    public static void main(String[] args)
    {
        Console.WriteLine("Reflection.MethodBase.Attributes Sample");

        // Get the type.
        Type myType = Type.GetType("AttributesSample");

        // Get the method MyMethod on the type.
        MethodBase myMethodBase = myType.GetMethod("MyMethod");

        // Display the method name.
        Console.WriteLine(("myMethodBase = " + myMethodBase));

        // Get the MethodAttribute enumerated value.
        MethodAttributes myAttributes = myMethodBase.get_Attributes();

        // Display the flags that are set.
        PrintAttributes(System.Reflection.MethodAttributes .class.ToType(),
            (int)(myAttributes));
    } //main

    public static void PrintAttributes(Type attribType, int iAttribValue)
    {
        if (!(attribType.get_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) ((Int32)(fields[i].GetValue(null)));
            if ((fieldValue & iAttribValue) == fieldValue  ) {
                Console.WriteLine(fields[i].get_Name());
            }
        } 
    } //PrintAttributes
} //AttributesSample
 import System;
 import System.Reflection;
 
 class AttributesSample
 {
    public function Mymethod (int1m : int) : void
    {
    }
 
    public static function Main() : void
    {      
       Console.WriteLine ("Reflection.MethodBase.Attributes Sample");
       
       // Get our type
       var MyType : Type = Type.GetType("AttributesSample");
 
       // Get the method Mymethod on our type
       var Mymethodbase : MethodBase = MyType.GetMethod("Mymethod");
 
       // Print out the method
       Console.WriteLine("Mymethodbase = " + Mymethodbase);
 
       // Get the MethodAttribute enumerated value
       var Myattributes : MethodAttributes = Mymethodbase.Attributes;
 
       // print out the flags set
       PrintAttributes( System.Reflection.MethodAttributes, int(Myattributes) );
    }
 
 
    public static function PrintAttributes( attribType : Type, iAttribValue : int ) : void 
    {
       if ( ! attribType.IsEnum ) { Console.WriteLine( "This type is not an enum" ); return; }
 
       var fields : FieldInfo[] = attribType.GetFields(BindingFlags.Public | BindingFlags.Static);
       for ( var i:int = 0; i < fields.Length; i++ )
       {
          var fieldvalue : int = int(fields[i].GetValue(null));
          if ( (fieldvalue & iAttribValue) == fieldvalue )
          {
             Console.WriteLine( "\t" + fields[i].Name );
          }
       }
    }
 }
 AttributesSample.Main();
/* 
 This code produces the following output:
 
Reflection.MethodBase.Attributes Sample
Mymethodbase = Void Mymethod(Int32)
        PrivateScope
        FamANDAssem
        Family
        Public
        Virtual
        HideBySig
        VtableLayoutMask
        ReuseSlot
        NewSlot
*/

이 코드는 다음과 같이 출력됩니다.

Reflection.MethodBase.Attributes Sample

Mymethodbase = Void Mymethod(Int32, System.String ByRef, System.String ByRef)

PrivateScope

FamANDAssem

Family

Public

HideBySig

ReuseSlot

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

MethodBase 클래스
MethodBase 멤버
System.Reflection 네임스페이스
MethodAttributes 열거형