Attribute.GetCustomAttributes 메서드

정의

어셈블리, 모듈, 형식 멤버 또는 메서드 매개 변수에 적용된 사용자 지정 특성의 배열을 검색합니다.

오버로드

GetCustomAttributes(ParameterInfo, Boolean)

메서드 매개 변수에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 메서드 매개 변수 및 상위 메서드 매개 변수의 검색 여부를 지정합니다.

GetCustomAttributes(MemberInfo, Type, Boolean)

형식 멤버에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 멤버, 검색할 사용자 지정 특성의 형식 및 상위 멤버의 검색 여부를 지정합니다.

GetCustomAttributes(ParameterInfo, Type, Boolean)

메서드 매개 변수에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 메서드 매개 변수, 검색할 사용자 지정 특성 형식 및 상위 메서드 매개 변수의 검색 여부를 지정합니다.

GetCustomAttributes(Module, Type, Boolean)

모듈에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 모듈, 검색할 사용자 지정 특성의 형식 및 무시된 검색 옵션을 지정합니다.

GetCustomAttributes(MemberInfo, Type)

형식 멤버에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 멤버와 검색할 사용자 지정 특성의 형식을 지정합니다.

GetCustomAttributes(Assembly, Type, Boolean)

어셈블리에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 어셈블리, 검색할 사용자 지정 특성의 형식 및 무시된 검색 옵션을 지정합니다.

GetCustomAttributes(Module, Type)

모듈에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 모듈과 검색할 사용자 지정 특성의 형식을 지정합니다.

GetCustomAttributes(ParameterInfo, Type)

메서드 매개 변수에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 메서드 매개 변수와 검색할 사용자 지정 특성의 형식을 지정합니다.

GetCustomAttributes(MemberInfo, Boolean)

형식 멤버에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 멤버, 검색할 사용자 지정 특성의 형식 및 상위 멤버의 검색 여부를 지정합니다.

GetCustomAttributes(Assembly, Type)

어셈블리에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 어셈블리와 검색할 사용자 지정 특성의 형식을 지정합니다.

GetCustomAttributes(Assembly, Boolean)

어셈블리에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 어셈블리와 무시된 검색 옵션을 지정합니다.

GetCustomAttributes(ParameterInfo)

메서드 매개 변수에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 메서드 매개 변수를 지정합니다.

GetCustomAttributes(Module)

모듈에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 모듈을 지정합니다.

GetCustomAttributes(MemberInfo)

형식 멤버에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수는 멤버를 지정합니다.

GetCustomAttributes(Assembly)

어셈블리에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수로 어셈블리를 지정합니다.

GetCustomAttributes(Module, Boolean)

모듈에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 모듈과 무시된 검색 옵션을 지정합니다.

GetCustomAttributes(ParameterInfo, Boolean)

메서드 매개 변수에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 메서드 매개 변수 및 상위 메서드 매개 변수의 검색 여부를 지정합니다.

public:
 static cli::array <Attribute ^> ^ GetCustomAttributes(System::Reflection::ParameterInfo ^ element, bool inherit);
public static Attribute[] GetCustomAttributes (System.Reflection.ParameterInfo element, bool inherit);
static member GetCustomAttributes : System.Reflection.ParameterInfo * bool -> Attribute[]
Public Shared Function GetCustomAttributes (element As ParameterInfo, inherit As Boolean) As Attribute()

매개 변수

element
ParameterInfo

클래스의 멤버 매개 변수를 설명하는 ParameterInfo 클래스에서 파생된 개체입니다.

inherit
Boolean

true이면 사용자 지정 특성에 대한 상위 element도 검색함을 지정합니다.

반환

element에 적용된 사용자 지정 특성이 포함된 Attribute 배열이며, 그러한 사용자 지정 특성이 없는 경우에는 빈 배열입니다.

예외

elementMember 속성이 null입니다.

element이(가) null인 경우

사용자 지정 특성 형식을 로드할 수 없는 경우

예제

다음 코드 예제를 사용 GetCustomAttributes하는 방법을 보여 줍니다.는 매개 변수로 사용 ParameterInfo 합니다.

using namespace System;
using namespace System::Reflection;
using namespace System::ComponentModel;

namespace CustAttrs5CS
{
   public ref class AClass
   {
   public:
      void ParamArrayAndDesc(
         // Add ParamArray and Description attributes.
         [Description("This argument is a ParamArray")]
         array<Int32>^args )
      {}
   };

   ref class DemoClass
   {
   public:
      static void Main()
      {
         // Get the Class type to access its metadata.
         Type^ clsType = AClass::typeid;

         // Get the type information for the method.
         MethodInfo^ mInfo = clsType->GetMethod( "ParamArrayAndDesc" );
         if ( mInfo != nullptr )
         {
            // Get the parameter information.
            array<ParameterInfo^>^pInfo = mInfo->GetParameters();
            if ( pInfo != nullptr )
            {
               // Iterate through all the attributes for the parameter.
               System::Collections::IEnumerator^ myEnum4 = Attribute::GetCustomAttributes( pInfo[ 0 ] )->GetEnumerator();
               while ( myEnum4->MoveNext() )
               {
                  Attribute^ attr = safe_cast<Attribute^>(myEnum4->Current);

                  // Check for the ParamArray attribute.
                  if ( attr->GetType() == ParamArrayAttribute::typeid )
                                    Console::WriteLine( "Parameter {0} for method {1} "
                  "has the ParamArray attribute.", pInfo[ 0 ]->Name, mInfo->Name );
                  // Check for the Description attribute.
                  else

                  // Check for the Description attribute.
                  if ( attr->GetType() == DescriptionAttribute::typeid )
                  {
                     Console::WriteLine( "Parameter {0} for method {1} "
                     "has a description attribute.", pInfo[ 0 ]->Name, mInfo->Name );
                     Console::WriteLine( "The description is: \"{0}\"", (dynamic_cast<DescriptionAttribute^>(attr))->Description );
                  }
               }
            }
         }
      }
   };
}

/*
 * Output:
 * Parameter args for method ParamArrayAndDesc has the ParamArray attribute.
 * Parameter args for method ParamArrayAndDesc has a description attribute.
 * The description is: "This argument is a ParamArray"
 */
using System;
using System.Reflection;
using System.ComponentModel;

namespace CustAttrs5CS {
    public class AClass {
        public void ParamArrayAndDesc(
            // Add ParamArray (with the keyword) and Description attributes.
            [Description("This argument is a ParamArray")]
            params int[] args)
        {}
    }

    class DemoClass {
        static void Main(string[] args) {
            // Get the Class type to access its metadata.
            Type clsType = typeof(AClass);
            // Get the type information for the method.
            MethodInfo mInfo = clsType.GetMethod("ParamArrayAndDesc");
            if (mInfo != null) {
                // Get the parameter information.
                ParameterInfo[] pInfo = mInfo.GetParameters();
                if (pInfo != null) {
                    // Iterate through all the attributes for the parameter.
                    foreach(Attribute attr in
                        Attribute.GetCustomAttributes(pInfo[0])) {
                        // Check for the ParamArray attribute.
                        if (attr.GetType() == typeof(ParamArrayAttribute))
                            Console.WriteLine("Parameter {0} for method {1} " +
                                "has the ParamArray attribute.",
                                pInfo[0].Name, mInfo.Name);
                        // Check for the Description attribute.
                        else if (attr.GetType() ==
                            typeof(DescriptionAttribute)) {
                            Console.WriteLine("Parameter {0} for method {1} " +
                                "has a description attribute.",
                                pInfo[0].Name, mInfo.Name);
                            Console.WriteLine("The description is: \"{0}\"",
                                ((DescriptionAttribute)attr).Description);
                        }
                    }
                }
            }
        }
    }
}

/*
 * Output:
 * Parameter args for method ParamArrayAndDesc has the ParamArray attribute.
 * Parameter args for method ParamArrayAndDesc has a description attribute.
 * The description is: "This argument is a ParamArray"
 */
open System
open System.Reflection
open System.ComponentModel

type AClass() =
    member _.ParamArrayAndDesc(
        // Add ParamArray and Description attributes.
        [<Description "This argument is a ParamArray">]
        [<ParamArray>]
        args: int[]) = ()

// Get the Class type to access its metadata.
let clsType = typeof<AClass>

// Get the type information for the method.
let mInfo = clsType.GetMethod "ParamArrayAndDesc"
if mInfo <> null then
    // Get the parameter information.
    let pInfo = mInfo.GetParameters()
    if pInfo <> null then
        // Iterate through all the attributes for the parameter.
        for attr in Attribute.GetCustomAttributes pInfo[0] do
            match attr with 
            // Check for the ParamArray attribute.
            | :? ParamArrayAttribute ->
                printfn $"Parameter {pInfo[0].Name} for method {mInfo.Name} has the ParamArray attribute."
                                
            // Check for the Description attribute.
            | :? DescriptionAttribute as attr ->
                printfn $"Parameter {pInfo[0].Name} for method {mInfo.Name} has a description attribute."
                printfn $"The description is: \"{attr.Description}\""
            | _ -> ()

// Output:
// Parameter args for method ParamArrayAndDesc has a description attribute.
// The description is: "This argument is a ParamArray"
// Parameter args for method ParamArrayAndDesc has the ParamArray attribute.
Imports System.Reflection
Imports System.ComponentModel

Module DemoModule
    Public Class AClass
        ' Add Description and ParamArray (with the keyword) attributes.
        Public Sub ParamArrayAndDesc( _
            <Description("This argument is a ParamArray")> _
            ByVal ParamArray args() As Integer)
        End Sub
    End Class

    Sub Main()
        ' Get the Class type to access its metadata.
        Dim clsType As Type = GetType(AClass)
        ' Get the type information for the method.
        Dim mInfo As MethodInfo = clsType.GetMethod("ParamArrayAndDesc")
        ' Get the Parameter information for the method.
        Dim pInfo() As ParameterInfo = mInfo.GetParameters()
        Dim attr As Attribute
        ' Iterate through each attribute of the parameter.
        For Each attr In Attribute.GetCustomAttributes(pInfo(0))
            ' Check for the ParamArray attribute.
            If TypeOf attr Is ParamArrayAttribute Then
                ' Convert the attribute to access its data.
                Dim paAttr As ParamArrayAttribute = _
                    CType(attr, ParamArrayAttribute)
                Console.WriteLine("Parameter {0} for method {1} has the " + _
                    "ParamArray attribute.", pInfo(0).Name, mInfo.Name)
            ' Check for the Description attribute.
            ElseIf TypeOf attr Is DescriptionAttribute Then
                ' Convert the attribute to access its data.
                Dim descAttr As DescriptionAttribute = _
                    CType(attr, DescriptionAttribute)
                Console.WriteLine("Parameter {0} for method {1} has a description " + _
                    "attribute. The description is:", pInfo(0).Name, mInfo.Name)
                Console.WriteLine(descAttr.Description)
            End If
        Next
    End Sub
End Module

' Output:
' Parameter args for method ParamArrayAndDesc has the ParamArray attribute.
' Parameter args for method ParamArrayAndDesc has a description attribute. The description is:
' This argument is a ParamArray

설명

파생 형식의 메서드에서 매개 변수를 나타내는 경우 element 반환 값에는 재정의된 기본 메서드의 동일한 매개 변수에 적용된 상속 가능한 사용자 지정 특성이 포함됩니다.

적용 대상

GetCustomAttributes(MemberInfo, Type, Boolean)

형식 멤버에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 멤버, 검색할 사용자 지정 특성의 형식 및 상위 멤버의 검색 여부를 지정합니다.

public:
 static cli::array <Attribute ^> ^ GetCustomAttributes(System::Reflection::MemberInfo ^ element, Type ^ type, bool inherit);
public:
 static cli::array <Attribute ^> ^ GetCustomAttributes(System::Reflection::MemberInfo ^ element, Type ^ attributeType, bool inherit);
public static Attribute[] GetCustomAttributes (System.Reflection.MemberInfo element, Type type, bool inherit);
public static Attribute[] GetCustomAttributes (System.Reflection.MemberInfo element, Type attributeType, bool inherit);
static member GetCustomAttributes : System.Reflection.MemberInfo * Type * bool -> Attribute[]
static member GetCustomAttributes : System.Reflection.MemberInfo * Type * bool -> Attribute[]
Public Shared Function GetCustomAttributes (element As MemberInfo, type As Type, inherit As Boolean) As Attribute()
Public Shared Function GetCustomAttributes (element As MemberInfo, attributeType As Type, inherit As Boolean) As Attribute()

매개 변수

element
MemberInfo

클래스의 생성자, 이벤트, 필드, 메서드 또는 속성 멤버를 설명하는 MemberInfo 클래스에서 파생된 개체입니다.

typeattributeType
Type

검색할 사용자 지정 특성의 형식, 즉 기본 형식입니다.

inherit
Boolean

true이면 사용자 지정 특성에 대한 상위 element도 검색함을 지정합니다.

반환

type에 적용된 element 형식의 사용자 지정 특성을 포함하는 Attribute 배열이거나, 그러한 사용자 지정 특성이 없는 경우에는 빈 배열입니다.

예외

element 또는 typenull인 경우

typeAttribute에서 파생되지 않은 경우

element가 생성자, 메서드, 속성, 이벤트, 형식 또는 필드가 아닌 경우

사용자 지정 특성 형식을 로드할 수 없는 경우

예제

다음 코드 예제를 사용 GetCustomAttributes하는 방법을 보여 줍니다.는 매개 변수로 사용 MemberInfo 합니다.

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

namespace CustAttrs4CS
{
   // Create a class for Win32 imported unmanaged functions.
   public ref class Win32
   {
   public:

      [DllImport("user32.dll", CharSet = CharSet::Unicode)]
      static int MessageBox( int hWnd, String^ text, String^ caption, UInt32 type );
   };

   public ref class AClass
   {
   public:

      // Add some attributes to the Win32CallMethod.

      [Obsolete("This method is obsolete. Use managed MsgBox instead.")]
      void Win32CallMethod()
      {
         Win32::MessageBox( 0, "This is an unmanaged call.", "Be Careful!", 0 );
      }

   };

   ref class DemoClass
   {
   public:
      static void Main()
      {
         // Get the Class type to access its metadata.
         Type^ clsType = AClass::typeid;

         // Get the type information for the Win32CallMethod.
         MethodInfo^ mInfo = clsType->GetMethod( "Win32CallMethod" );
         if ( mInfo != nullptr )
         {
            // Iterate through all the attributes for the method.
            System::Collections::IEnumerator^ myEnum3 = Attribute::GetCustomAttributes( mInfo )->GetEnumerator();
            while ( myEnum3->MoveNext() )
            {
               Attribute^ attr = safe_cast<Attribute^>(myEnum3->Current);

               // Check for the Obsolete attribute.
               if ( attr->GetType() == ObsoleteAttribute::typeid )
               {
                  Console::WriteLine( "Method {0} is obsolete. "
                  "The message is:", mInfo->Name );
                  Console::WriteLine( (dynamic_cast<ObsoleteAttribute^>(attr))->Message );
               }
               // Check for the SuppressUnmanagedCodeSecurity attribute.
               else

               // Check for the SuppressUnmanagedCodeSecurity attribute.
               if ( attr->GetType() == SuppressUnmanagedCodeSecurityAttribute::typeid )
               {
                  Console::WriteLine( "This method calls unmanaged code "
                  "with no security check." );
                  Console::WriteLine( "Please do not use unless absolutely necessary." );
                  AClass^ myCls = gcnew AClass;
                  myCls->Win32CallMethod();
               }
            }
         }
      }
   };
}


/*
 * Output:
 * Method Win32CallMethod is obsolete. The message is:
 * This method is obsolete. Use managed MsgBox instead.
 * This method calls unmanaged code with no security check.
 * Please do not use unless absolutely necessary.
 */
using System;
using System.Reflection;
using System.Security;
using System.Runtime.InteropServices;

namespace CustAttrs4CS
{

    // Define an enumeration of Win32 unmanaged types
    public enum UnmanagedType
    {
        User,
        GDI,
        Kernel,
        Shell,
        Networking,
        Multimedia
    }

    // Define the Unmanaged attribute.
    public class UnmanagedAttribute : Attribute
    {
        // Storage for the UnmanagedType value.
        protected UnmanagedType thisType;

        // Set the unmanaged type in the constructor.
        public UnmanagedAttribute(UnmanagedType type)
        {
            thisType = type;
        }

        // Define a property to get and set the UnmanagedType value.
        public UnmanagedType Win32Type
        {
            get { return thisType; }
            set { thisType = Win32Type; }
        }
    }

    // Create a class for an imported Win32 unmanaged function.
    public class Win32 {
        [DllImport("user32.dll", CharSet = CharSet.Unicode)]
        public static extern int MessageBox(int hWnd, String text,
            String caption, uint type);
    }

    public class AClass {
        // Add some attributes to Win32CallMethod.
        [Obsolete("This method is obsolete. Use managed MsgBox instead.")]
        [Unmanaged(UnmanagedType.User)]
        public void Win32CallMethod()
        {
            Win32.MessageBox(0, "This is an unmanaged call.", "Caution!", 0);
        }
    }

    class DemoClass {
        static void Main(string[] args)
            {
            // Get the AClass type to access its metadata.
            Type clsType = typeof(AClass);
            // Get the type information for Win32CallMethod.
            MethodInfo mInfo = clsType.GetMethod("Win32CallMethod");
            if (mInfo != null)
            {
                // Iterate through all the attributes of the method.
                foreach(Attribute attr in
                    Attribute.GetCustomAttributes(mInfo)) {
                    // Check for the Obsolete attribute.
                    if (attr.GetType() == typeof(ObsoleteAttribute))
                    {
                        Console.WriteLine("Method {0} is obsolete. " +
                            "The message is:",
                            mInfo.Name);
                        Console.WriteLine("  \"{0}\"",
                            ((ObsoleteAttribute)attr).Message);
                    }

                    // Check for the Unmanaged attribute.
                    else if (attr.GetType() == typeof(UnmanagedAttribute))
                    {
                        Console.WriteLine(
                            "This method calls unmanaged code.");
                        Console.WriteLine(
                            String.Format("The Unmanaged attribute type is {0}.",
                                          ((UnmanagedAttribute)attr).Win32Type));
                        AClass myCls = new AClass();
                        myCls.Win32CallMethod();
                    }
                }
            }
        }
    }
}

/*

This code example produces the following results.

First, the compilation yields the warning, "... This method is
obsolete. Use managed MsgBox instead."
Second, execution yields a message box with a title of "Caution!"
and message text of "This is an unmanaged call."
Third, the following text is displayed in the console window:

Method Win32CallMethod is obsolete. The message is:
  "This method is obsolete. Use managed MsgBox instead."
This method calls unmanaged code.
The Unmanaged attribute type is User.

*/
open System
open System.Runtime.InteropServices

// Define an enumeration of Win32 unmanaged types
type UnmanagedType =
    | User = 0
    | GDI = 1
    | Kernel = 2
    | Shell = 3
    | Networking = 4
    | Multimedia = 5

// Define the Unmanaged attribute.
type UnmanagedAttribute(unmanagedType) =
    inherit Attribute()
    
    // Define a property to get and set the UnmanagedType value.
    member val Win32Type = unmanagedType with get, set

// Create a module for an imported Win32 unmanaged function.
module Win32 =
    [<DllImport("user32.dll", CharSet = CharSet.Unicode)>]
    extern int MessageBox(IntPtr hWnd, String text, String caption, uint ``type``)

type AClass() =
    // Add some attributes to Win32CallMethod.
    [<Obsolete "This method is obsolete. Use managed MsgBox instead.">]
    [<Unmanaged(UnmanagedType.User)>]
    member _.Win32CallMethod () =
        Win32.MessageBox(0, "This is an unmanaged call.", "Caution!", 0u)

// Get the AClass type to access its metadata.
let clsType = typeof<AClass>
// Get the type information for Win32CallMethod.
let mInfo = clsType.GetMethod "Win32CallMethod"
if mInfo <> null then
    // Iterate through all the attributes of the method.
    for attr in Attribute.GetCustomAttributes mInfo do
        match attr with 
        // Check for the Obsolete attribute.
        | :? ObsoleteAttribute as attr ->
            printfn $"Method {mInfo.Name} is obsolete. The message is:"
            printfn $"  \"{attr.Message}\""

        // Check for the Unmanaged attribute.
        | :? UnmanagedAttribute as attr ->
            printfn "This method calls unmanaged code."
            printfn $"The Unmanaged attribute type is {attr.Win32Type}."
            let myCls = AClass()
            myCls.Win32CallMethod() |> ignore
        | _ -> ()

// This code example produces the following results.
//
// First, the compilation yields the warning, "... This method is
// obsolete. Use managed MsgBox instead."
// Second, execution yields a message box with a title of "Caution!"
// and message text of "This is an unmanaged call."
// Third, the following text is displayed in the console window:

// Method Win32CallMethod is obsolete. The message is:
//   "This method is obsolete. Use managed MsgBox instead."
// This method calls unmanaged code.
// The Unmanaged attribute type is User.
Imports System.Reflection
Imports System.Security
Imports System.Runtime.InteropServices

' Define an enumeration of Win32 unmanaged types
Public Enum UnmanagedType
    User
    GDI
    Kernel
    Shell
    Networking
    Multimedia
End Enum 'UnmanagedType

' Define the Unmanaged attribute.
Public Class UnmanagedAttribute 
             Inherits Attribute

    ' Storage for the UnmanagedType value.
    Protected thisType As UnmanagedType
    
    ' Set the unmanaged type in the constructor.
    Public Sub New(ByVal type As UnmanagedType) 
        thisType = type
    End Sub
    
    ' Define a property to get and set the UnmanagedType value.
    Public Property Win32Type() As UnmanagedType 
        Get
            Return thisType
        End Get
        Set
            thisType = Win32Type
        End Set
    End Property
End Class

' Create a class for an imported Win32 unmanaged function.
Public Class Win32
    <DllImport("user32.dll", CharSet:=CharSet.Unicode)> _
    Public Shared Function MessageBox(ByVal hWnd As Integer, _
                                      ByVal Text As String, _
                                      ByVal caption As String, _
                                      ByVal type As Integer) As Integer
    End Function 'MessageBox
End Class

Public Class AClass
    ' Add some attributes to Win32CallMethod.
    <Obsolete("This method is obsolete. Use managed MsgBox instead."), _
     Unmanaged(UnmanagedType.User)>  _
    Public Sub Win32CallMethod() 
        Win32.MessageBox(0, "This is an unmanaged call.", "Caution!", 0)    
    End Sub
End Class

Class DemoClass
    Shared Sub Main(ByVal args() As String) 
        ' Get the AClass type to access its metadata.
        Dim clsType As Type = GetType(AClass)
        ' Get the type information for Win32CallMethod.
        Dim mInfo As MethodInfo = clsType.GetMethod("Win32CallMethod")
        If Not (mInfo Is Nothing) Then
            ' Iterate through all the attributes of the method.
            Dim attr As Attribute
            For Each attr In  Attribute.GetCustomAttributes(mInfo)
                ' Check for the Obsolete attribute.
                If attr.GetType().Equals(GetType(ObsoleteAttribute)) Then
                    Console.WriteLine("Method {0} is obsolete. The message is:", mInfo.Name)
                    Console.WriteLine("  ""{0}""", CType(attr, ObsoleteAttribute).Message)
                ' Check for the Unmanaged attribute.
                ElseIf attr.GetType().Equals(GetType(UnmanagedAttribute)) Then
                    Console.WriteLine("This method calls unmanaged code.")
                    Console.WriteLine( _
                            String.Format("The Unmanaged attribute type is {0}.", _
                            CType(attr, UnmanagedAttribute).Win32Type))
                    Dim myCls As New AClass()
                    myCls.Win32CallMethod()
                End If
            Next attr
        End If
    End Sub
End Class

'
'This code example produces the following results. 
'
'First, the compilation yields the warning, "... This method is 
'obsolete. Use managed MsgBox instead."
'Second, execution yields a message box with a title of "Caution!" 
'and message text of "This is an unmanaged call." 
'Third, the following text is displayed in the console window:
'
'Method Win32CallMethod is obsolete. The message is:
'  "This method is obsolete. Use managed MsgBox instead."
'This method calls unmanaged code.
'The Unmanaged attribute type is User.
'

설명

반환 값에는 이 인 경우 inheritelement 상위 항목에 대한 사용자 지정 특성이 포함됩니다true.

참고

.NET Framework 버전 2.0부터 이 메서드는 특성이 새 메타데이터 형식으로 저장되는 경우 메서드, 생성자 및 형식에 대한 보안 특성을 반환합니다. 버전 2.0 이상으로 컴파일된 어셈블리는 새 형식을 사용합니다. 이전 버전의 .NET Framework 컴파일된 동적 어셈블리 및 어셈블리는 이전 XML 형식을 사용합니다. 선언적 보안 특성 내보내기 를 참조하세요.

적용 대상

GetCustomAttributes(ParameterInfo, Type, Boolean)

메서드 매개 변수에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 메서드 매개 변수, 검색할 사용자 지정 특성 형식 및 상위 메서드 매개 변수의 검색 여부를 지정합니다.

public:
 static cli::array <Attribute ^> ^ GetCustomAttributes(System::Reflection::ParameterInfo ^ element, Type ^ attributeType, bool inherit);
public static Attribute[] GetCustomAttributes (System.Reflection.ParameterInfo element, Type attributeType, bool inherit);
static member GetCustomAttributes : System.Reflection.ParameterInfo * Type * bool -> Attribute[]
Public Shared Function GetCustomAttributes (element As ParameterInfo, attributeType As Type, inherit As Boolean) As Attribute()

매개 변수

element
ParameterInfo

클래스의 멤버 매개 변수를 설명하는 ParameterInfo 클래스에서 파생된 개체입니다.

attributeType
Type

검색할 사용자 지정 특성의 형식, 즉 기본 형식입니다.

inherit
Boolean

true이면 사용자 지정 특성에 대한 상위 element도 검색함을 지정합니다.

반환

attributeType에 적용된 element 형식의 사용자 지정 특성을 포함하는 Attribute 배열이거나, 그러한 사용자 지정 특성이 없는 경우에는 빈 배열입니다.

예외

element 또는 attributeTypenull인 경우

attributeTypeAttribute에서 파생되지 않은 경우

사용자 지정 특성 형식을 로드할 수 없는 경우

예제

다음 코드 예제를 사용 GetCustomAttributes하는 방법을 보여 줍니다.는 매개 변수로 사용 ParameterInfo 합니다.

using namespace System;
using namespace System::Reflection;
using namespace System::ComponentModel;

namespace CustAttrs5CS
{
   public ref class AClass
   {
   public:
      void ParamArrayAndDesc(
         // Add ParamArray and Description attributes.
         [Description("This argument is a ParamArray")]
         array<Int32>^args )
      {}
   };

   ref class DemoClass
   {
   public:
      static void Main()
      {
         // Get the Class type to access its metadata.
         Type^ clsType = AClass::typeid;

         // Get the type information for the method.
         MethodInfo^ mInfo = clsType->GetMethod( "ParamArrayAndDesc" );
         if ( mInfo != nullptr )
         {
            // Get the parameter information.
            array<ParameterInfo^>^pInfo = mInfo->GetParameters();
            if ( pInfo != nullptr )
            {
               // Iterate through all the attributes for the parameter.
               System::Collections::IEnumerator^ myEnum4 = Attribute::GetCustomAttributes( pInfo[ 0 ] )->GetEnumerator();
               while ( myEnum4->MoveNext() )
               {
                  Attribute^ attr = safe_cast<Attribute^>(myEnum4->Current);

                  // Check for the ParamArray attribute.
                  if ( attr->GetType() == ParamArrayAttribute::typeid )
                                    Console::WriteLine( "Parameter {0} for method {1} "
                  "has the ParamArray attribute.", pInfo[ 0 ]->Name, mInfo->Name );
                  // Check for the Description attribute.
                  else

                  // Check for the Description attribute.
                  if ( attr->GetType() == DescriptionAttribute::typeid )
                  {
                     Console::WriteLine( "Parameter {0} for method {1} "
                     "has a description attribute.", pInfo[ 0 ]->Name, mInfo->Name );
                     Console::WriteLine( "The description is: \"{0}\"", (dynamic_cast<DescriptionAttribute^>(attr))->Description );
                  }
               }
            }
         }
      }
   };
}

/*
 * Output:
 * Parameter args for method ParamArrayAndDesc has the ParamArray attribute.
 * Parameter args for method ParamArrayAndDesc has a description attribute.
 * The description is: "This argument is a ParamArray"
 */
using System;
using System.Reflection;
using System.ComponentModel;

namespace CustAttrs5CS {
    public class AClass {
        public void ParamArrayAndDesc(
            // Add ParamArray (with the keyword) and Description attributes.
            [Description("This argument is a ParamArray")]
            params int[] args)
        {}
    }

    class DemoClass {
        static void Main(string[] args) {
            // Get the Class type to access its metadata.
            Type clsType = typeof(AClass);
            // Get the type information for the method.
            MethodInfo mInfo = clsType.GetMethod("ParamArrayAndDesc");
            if (mInfo != null) {
                // Get the parameter information.
                ParameterInfo[] pInfo = mInfo.GetParameters();
                if (pInfo != null) {
                    // Iterate through all the attributes for the parameter.
                    foreach(Attribute attr in
                        Attribute.GetCustomAttributes(pInfo[0])) {
                        // Check for the ParamArray attribute.
                        if (attr.GetType() == typeof(ParamArrayAttribute))
                            Console.WriteLine("Parameter {0} for method {1} " +
                                "has the ParamArray attribute.",
                                pInfo[0].Name, mInfo.Name);
                        // Check for the Description attribute.
                        else if (attr.GetType() ==
                            typeof(DescriptionAttribute)) {
                            Console.WriteLine("Parameter {0} for method {1} " +
                                "has a description attribute.",
                                pInfo[0].Name, mInfo.Name);
                            Console.WriteLine("The description is: \"{0}\"",
                                ((DescriptionAttribute)attr).Description);
                        }
                    }
                }
            }
        }
    }
}

/*
 * Output:
 * Parameter args for method ParamArrayAndDesc has the ParamArray attribute.
 * Parameter args for method ParamArrayAndDesc has a description attribute.
 * The description is: "This argument is a ParamArray"
 */
open System
open System.Reflection
open System.ComponentModel

type AClass() =
    member _.ParamArrayAndDesc(
        // Add ParamArray and Description attributes.
        [<Description "This argument is a ParamArray">]
        [<ParamArray>]
        args: int[]) = ()

// Get the Class type to access its metadata.
let clsType = typeof<AClass>

// Get the type information for the method.
let mInfo = clsType.GetMethod "ParamArrayAndDesc"
if mInfo <> null then
    // Get the parameter information.
    let pInfo = mInfo.GetParameters()
    if pInfo <> null then
        // Iterate through all the attributes for the parameter.
        for attr in Attribute.GetCustomAttributes pInfo[0] do
            match attr with 
            // Check for the ParamArray attribute.
            | :? ParamArrayAttribute ->
                printfn $"Parameter {pInfo[0].Name} for method {mInfo.Name} has the ParamArray attribute."
                                
            // Check for the Description attribute.
            | :? DescriptionAttribute as attr ->
                printfn $"Parameter {pInfo[0].Name} for method {mInfo.Name} has a description attribute."
                printfn $"The description is: \"{attr.Description}\""
            | _ -> ()

// Output:
// Parameter args for method ParamArrayAndDesc has a description attribute.
// The description is: "This argument is a ParamArray"
// Parameter args for method ParamArrayAndDesc has the ParamArray attribute.
Imports System.Reflection
Imports System.ComponentModel

Module DemoModule
    Public Class AClass
        ' Add Description and ParamArray (with the keyword) attributes.
        Public Sub ParamArrayAndDesc( _
            <Description("This argument is a ParamArray")> _
            ByVal ParamArray args() As Integer)
        End Sub
    End Class

    Sub Main()
        ' Get the Class type to access its metadata.
        Dim clsType As Type = GetType(AClass)
        ' Get the type information for the method.
        Dim mInfo As MethodInfo = clsType.GetMethod("ParamArrayAndDesc")
        ' Get the Parameter information for the method.
        Dim pInfo() As ParameterInfo = mInfo.GetParameters()
        Dim attr As Attribute
        ' Iterate through each attribute of the parameter.
        For Each attr In Attribute.GetCustomAttributes(pInfo(0))
            ' Check for the ParamArray attribute.
            If TypeOf attr Is ParamArrayAttribute Then
                ' Convert the attribute to access its data.
                Dim paAttr As ParamArrayAttribute = _
                    CType(attr, ParamArrayAttribute)
                Console.WriteLine("Parameter {0} for method {1} has the " + _
                    "ParamArray attribute.", pInfo(0).Name, mInfo.Name)
            ' Check for the Description attribute.
            ElseIf TypeOf attr Is DescriptionAttribute Then
                ' Convert the attribute to access its data.
                Dim descAttr As DescriptionAttribute = _
                    CType(attr, DescriptionAttribute)
                Console.WriteLine("Parameter {0} for method {1} has a description " + _
                    "attribute. The description is:", pInfo(0).Name, mInfo.Name)
                Console.WriteLine(descAttr.Description)
            End If
        Next
    End Sub
End Module

' Output:
' Parameter args for method ParamArrayAndDesc has the ParamArray attribute.
' Parameter args for method ParamArrayAndDesc has a description attribute. The description is:
' This argument is a ParamArray

설명

파생 형식의 메서드에서 매개 변수를 나타내는 경우 element 반환 값에는 재정의된 기본 메서드의 동일한 매개 변수에 적용된 상속 가능한 사용자 지정 특성이 포함됩니다.

적용 대상

GetCustomAttributes(Module, Type, Boolean)

모듈에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 모듈, 검색할 사용자 지정 특성의 형식 및 무시된 검색 옵션을 지정합니다.

public:
 static cli::array <Attribute ^> ^ GetCustomAttributes(System::Reflection::Module ^ element, Type ^ attributeType, bool inherit);
public static Attribute[] GetCustomAttributes (System.Reflection.Module element, Type attributeType, bool inherit);
static member GetCustomAttributes : System.Reflection.Module * Type * bool -> Attribute[]
Public Shared Function GetCustomAttributes (element As Module, attributeType As Type, inherit As Boolean) As Attribute()

매개 변수

element
Module

이식 가능한 실행 파일을 설명하는 Module 클래스에서 파생된 개체입니다.

attributeType
Type

검색할 사용자 지정 특성의 형식, 즉 기본 형식입니다.

inherit
Boolean

이 매개 변수는 무시되며 이 메서드의 작업에 영향을 끼치지 않습니다.

반환

attributeType에 적용된 element 형식의 사용자 지정 특성을 포함하는 Attribute 배열이거나, 그러한 사용자 지정 특성이 없는 경우에는 빈 배열입니다.

예외

element 또는 attributeTypenull인 경우

attributeTypeAttribute에서 파생되지 않은 경우

예제

다음 코드 예제에서는 를 매개 변수로 사용하여 ModuleGetCustomAttributes사용하는 방법을 보여 줍니다.

using namespace System;
using namespace System::Reflection;
using namespace System::ComponentModel;

// Assign some attributes to the module.
// Set the module's CLSCompliant attribute to false
// The CLSCompliant attribute is applicable for /target:module.
[module:Description("A sample description")];
[module:CLSCompliant(false)];
namespace CustAttrs2CS
{
   ref class DemoClass
   {
   public:
      static void Main()
      {
         Type^ clsType = DemoClass::typeid;

         // Get the Module type to access its metadata.
         Module^ module = clsType->Module;

         // Iterate through all the attributes for the module.
         System::Collections::IEnumerator^ myEnum1 = Attribute::GetCustomAttributes( module )->GetEnumerator();
         while ( myEnum1->MoveNext() )
         {
            Attribute^ attr = safe_cast<Attribute^>(myEnum1->Current);

            // Check for the Description attribute.
            if ( attr->GetType() == DescriptionAttribute::typeid )
                        Console::WriteLine( "Module {0} has the description \"{1}\".", module->Name, (dynamic_cast<DescriptionAttribute^>(attr))->Description );
            // Check for the CLSCompliant attribute.
            else

            // Check for the CLSCompliant attribute.
            if ( attr->GetType() == CLSCompliantAttribute::typeid )
                        Console::WriteLine( "Module {0} {1} CLSCompliant.", module->Name, (dynamic_cast<CLSCompliantAttribute^>(attr))->IsCompliant ? (String^)"is" : "is not" );
         }
      }
   };
}


/*
 * Output:
 * Module CustAttrs2CS.exe is not CLSCompliant.
 * Module CustAttrs2CS.exe has the description "A sample description".
 */
using System;
using System.Reflection;
using System.ComponentModel;

// Assign some attributes to the module.
[module:Description("A sample description")]

// Set the module's CLSCompliant attribute to false
// The CLSCompliant attribute is applicable for /target:module.
[module:CLSCompliant(false)]

namespace CustAttrs2CS {
    class DemoClass {
        static void Main(string[] args) {
            Type clsType = typeof(DemoClass);
            // Get the Module type to access its metadata.
            Module module = clsType.Module;

            // Iterate through all the attributes for the module.
            foreach(Attribute attr in Attribute.GetCustomAttributes(module)) {
                // Check for the Description attribute.
                if (attr.GetType() == typeof(DescriptionAttribute))
                    Console.WriteLine("Module {0} has the description " +
                        "\"{1}\".", module.Name,
                        ((DescriptionAttribute)attr).Description);
                // Check for the CLSCompliant attribute.
                else if (attr.GetType() == typeof(CLSCompliantAttribute))
                    Console.WriteLine("Module {0} {1} CLSCompliant.",
                        module.Name,
                        ((CLSCompliantAttribute)attr).IsCompliant ?
                            "is" : "is not");
            }
        }
    }
}

/*
 * Output:
 * Module CustAttrs2CS.exe is not CLSCompliant.
 * Module CustAttrs2CS.exe has the description "A sample description".
 */
open System
open System.ComponentModel

// Assign some attributes to the module.
[<``module``: Description "A sample description">]

// Set the module's CLSCompliant attribute to false
// The CLSCompliant attribute is applicable for /target:module.
[<``module``: CLSCompliant false>]
do ()

type DemoClass = class end

// Get the Module type to access its metadata.
let ilmodule = typeof<DemoClass>.Module

// Iterate through all the attributes for the module.
for attr in Attribute.GetCustomAttributes ilmodule do
    match attr with
    // Check for the Description attribute.
    | :? DescriptionAttribute as attr ->
        printfn $"Module {ilmodule.Name} has the description \"{attr.Description}\"."
                
    // Check for the CLSCompliant attribute.
    | :? CLSCompliantAttribute as attr ->
        printfn $"""Module {ilmodule.Name} {if attr.IsCompliant then "is" else "is not"} CLSCompliant."""
    | _ -> ()
    
// Output:
// Module CustAttrs2CS.exe is not CLSCompliant.
// Module CustAttrs2CS.exe has the description "A sample description".
Imports System.Reflection
Imports System.ComponentModel

' Give the Module some attributes.
<Module: Description("A sample description")> 

' Make the CLSCompliant attribute False.
' The CLSCompliant attribute is applicable for /target:module.
<Module: CLSCompliant(False)> 

Module DemoModule

    Sub Main()
        ' Get the Module type to access its metadata.
        Dim modType As Reflection.Module = GetType(DemoModule).Module
        Dim attr As Attribute
        ' Iterate through all the attributes for the module.
        For Each attr In Attribute.GetCustomAttributes(modType)
            ' Check for the Description attribute.
            If TypeOf attr Is DescriptionAttribute Then
                ' Convert the attribute to access its data.
                Dim descAttr As DescriptionAttribute = _
                    CType(attr, DescriptionAttribute)
                Console.WriteLine("Module {0} has the description ""{1}"".", _
                    modType.Name, descAttr.Description)

            ' Check for the CLSCompliant attribute.
            ElseIf TypeOf attr Is CLSCompliantAttribute Then
                ' Convert the attribute to access its data.
                Dim CLSCompAttr As CLSCompliantAttribute = _
                    CType(attr, CLSCompliantAttribute)
                Dim strCompliant As String
                If CLSCompAttr.IsCompliant Then
                    strCompliant = "is"
                Else
                    strCompliant = "is not"
                End If
                Console.WriteLine("Module {0} {1} CLSCompliant.", _
                    modType.Name, strCompliant)
            End If
        Next
    End Sub
End Module

' Output:
' Module CustAttrs2VB.exe has the description "A sample description".
' Module CustAttrs2VB.exe is not CLSCompliant.

설명

반환 값에는 이 인 경우 inheritelement 상위 항목에 대한 사용자 지정 특성이 포함됩니다true.

적용 대상

GetCustomAttributes(MemberInfo, Type)

형식 멤버에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 멤버와 검색할 사용자 지정 특성의 형식을 지정합니다.

public:
 static cli::array <Attribute ^> ^ GetCustomAttributes(System::Reflection::MemberInfo ^ element, Type ^ type);
public:
 static cli::array <Attribute ^> ^ GetCustomAttributes(System::Reflection::MemberInfo ^ element, Type ^ attributeType);
public static Attribute[] GetCustomAttributes (System.Reflection.MemberInfo element, Type type);
public static Attribute[] GetCustomAttributes (System.Reflection.MemberInfo element, Type attributeType);
static member GetCustomAttributes : System.Reflection.MemberInfo * Type -> Attribute[]
static member GetCustomAttributes : System.Reflection.MemberInfo * Type -> Attribute[]
Public Shared Function GetCustomAttributes (element As MemberInfo, type As Type) As Attribute()
Public Shared Function GetCustomAttributes (element As MemberInfo, attributeType As Type) As Attribute()

매개 변수

element
MemberInfo

클래스의 생성자, 이벤트, 필드, 메서드 또는 속성 멤버를 설명하는 MemberInfo 클래스에서 파생된 개체입니다.

typeattributeType
Type

검색할 사용자 지정 특성의 형식, 즉 기본 형식입니다.

반환

type에 적용된 element 형식의 사용자 지정 특성을 포함하는 Attribute 배열이거나, 그러한 사용자 지정 특성이 없는 경우에는 빈 배열입니다.

예외

element 또는 typenull인 경우

typeAttribute에서 파생되지 않은 경우

element가 생성자, 메서드, 속성, 이벤트, 형식 또는 필드가 아닌 경우

사용자 지정 특성 형식을 로드할 수 없는 경우

예제

다음 코드 예제에서는 를 매개 변수로 사용하여 MemberInfoGetCustomAttribute사용하는 방법을 보여 줍니다.

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

namespace CustAttrs4CS
{
   // Create a class for Win32 imported unmanaged functions.
   public ref class Win32
   {
   public:

      [DllImport("user32.dll", CharSet = CharSet::Unicode)]
      static int MessageBox( int hWnd, String^ text, String^ caption, UInt32 type );
   };

   public ref class AClass
   {
   public:

      // Add some attributes to the Win32CallMethod.

      [Obsolete("This method is obsolete. Use managed MsgBox instead.")]
      void Win32CallMethod()
      {
         Win32::MessageBox( 0, "This is an unmanaged call.", "Be Careful!", 0 );
      }

   };

   ref class DemoClass
   {
   public:
      static void Main()
      {
         // Get the Class type to access its metadata.
         Type^ clsType = AClass::typeid;

         // Get the type information for the Win32CallMethod.
         MethodInfo^ mInfo = clsType->GetMethod( "Win32CallMethod" );
         if ( mInfo != nullptr )
         {
            // Iterate through all the attributes for the method.
            System::Collections::IEnumerator^ myEnum3 = Attribute::GetCustomAttributes( mInfo )->GetEnumerator();
            while ( myEnum3->MoveNext() )
            {
               Attribute^ attr = safe_cast<Attribute^>(myEnum3->Current);

               // Check for the Obsolete attribute.
               if ( attr->GetType() == ObsoleteAttribute::typeid )
               {
                  Console::WriteLine( "Method {0} is obsolete. "
                  "The message is:", mInfo->Name );
                  Console::WriteLine( (dynamic_cast<ObsoleteAttribute^>(attr))->Message );
               }
               // Check for the SuppressUnmanagedCodeSecurity attribute.
               else

               // Check for the SuppressUnmanagedCodeSecurity attribute.
               if ( attr->GetType() == SuppressUnmanagedCodeSecurityAttribute::typeid )
               {
                  Console::WriteLine( "This method calls unmanaged code "
                  "with no security check." );
                  Console::WriteLine( "Please do not use unless absolutely necessary." );
                  AClass^ myCls = gcnew AClass;
                  myCls->Win32CallMethod();
               }
            }
         }
      }
   };
}


/*
 * Output:
 * Method Win32CallMethod is obsolete. The message is:
 * This method is obsolete. Use managed MsgBox instead.
 * This method calls unmanaged code with no security check.
 * Please do not use unless absolutely necessary.
 */
using System;
using System.Reflection;
using System.Security;
using System.Runtime.InteropServices;

namespace CustAttrs4CS
{

    // Define an enumeration of Win32 unmanaged types
    public enum UnmanagedType
    {
        User,
        GDI,
        Kernel,
        Shell,
        Networking,
        Multimedia
    }

    // Define the Unmanaged attribute.
    public class UnmanagedAttribute : Attribute
    {
        // Storage for the UnmanagedType value.
        protected UnmanagedType thisType;

        // Set the unmanaged type in the constructor.
        public UnmanagedAttribute(UnmanagedType type)
        {
            thisType = type;
        }

        // Define a property to get and set the UnmanagedType value.
        public UnmanagedType Win32Type
        {
            get { return thisType; }
            set { thisType = Win32Type; }
        }
    }

    // Create a class for an imported Win32 unmanaged function.
    public class Win32 {
        [DllImport("user32.dll", CharSet = CharSet.Unicode)]
        public static extern int MessageBox(int hWnd, String text,
            String caption, uint type);
    }

    public class AClass {
        // Add some attributes to Win32CallMethod.
        [Obsolete("This method is obsolete. Use managed MsgBox instead.")]
        [Unmanaged(UnmanagedType.User)]
        public void Win32CallMethod()
        {
            Win32.MessageBox(0, "This is an unmanaged call.", "Caution!", 0);
        }
    }

    class DemoClass {
        static void Main(string[] args)
            {
            // Get the AClass type to access its metadata.
            Type clsType = typeof(AClass);
            // Get the type information for Win32CallMethod.
            MethodInfo mInfo = clsType.GetMethod("Win32CallMethod");
            if (mInfo != null)
            {
                // Iterate through all the attributes of the method.
                foreach(Attribute attr in
                    Attribute.GetCustomAttributes(mInfo)) {
                    // Check for the Obsolete attribute.
                    if (attr.GetType() == typeof(ObsoleteAttribute))
                    {
                        Console.WriteLine("Method {0} is obsolete. " +
                            "The message is:",
                            mInfo.Name);
                        Console.WriteLine("  \"{0}\"",
                            ((ObsoleteAttribute)attr).Message);
                    }

                    // Check for the Unmanaged attribute.
                    else if (attr.GetType() == typeof(UnmanagedAttribute))
                    {
                        Console.WriteLine(
                            "This method calls unmanaged code.");
                        Console.WriteLine(
                            String.Format("The Unmanaged attribute type is {0}.",
                                          ((UnmanagedAttribute)attr).Win32Type));
                        AClass myCls = new AClass();
                        myCls.Win32CallMethod();
                    }
                }
            }
        }
    }
}

/*

This code example produces the following results.

First, the compilation yields the warning, "... This method is
obsolete. Use managed MsgBox instead."
Second, execution yields a message box with a title of "Caution!"
and message text of "This is an unmanaged call."
Third, the following text is displayed in the console window:

Method Win32CallMethod is obsolete. The message is:
  "This method is obsolete. Use managed MsgBox instead."
This method calls unmanaged code.
The Unmanaged attribute type is User.

*/
open System
open System.Runtime.InteropServices

// Define an enumeration of Win32 unmanaged types
type UnmanagedType =
    | User = 0
    | GDI = 1
    | Kernel = 2
    | Shell = 3
    | Networking = 4
    | Multimedia = 5

// Define the Unmanaged attribute.
type UnmanagedAttribute(unmanagedType) =
    inherit Attribute()
    
    // Define a property to get and set the UnmanagedType value.
    member val Win32Type = unmanagedType with get, set

// Create a module for an imported Win32 unmanaged function.
module Win32 =
    [<DllImport("user32.dll", CharSet = CharSet.Unicode)>]
    extern int MessageBox(IntPtr hWnd, String text, String caption, uint ``type``)

type AClass() =
    // Add some attributes to Win32CallMethod.
    [<Obsolete "This method is obsolete. Use managed MsgBox instead.">]
    [<Unmanaged(UnmanagedType.User)>]
    member _.Win32CallMethod () =
        Win32.MessageBox(0, "This is an unmanaged call.", "Caution!", 0u)

// Get the AClass type to access its metadata.
let clsType = typeof<AClass>
// Get the type information for Win32CallMethod.
let mInfo = clsType.GetMethod "Win32CallMethod"
if mInfo <> null then
    // Iterate through all the attributes of the method.
    for attr in Attribute.GetCustomAttributes mInfo do
        match attr with 
        // Check for the Obsolete attribute.
        | :? ObsoleteAttribute as attr ->
            printfn $"Method {mInfo.Name} is obsolete. The message is:"
            printfn $"  \"{attr.Message}\""

        // Check for the Unmanaged attribute.
        | :? UnmanagedAttribute as attr ->
            printfn "This method calls unmanaged code."
            printfn $"The Unmanaged attribute type is {attr.Win32Type}."
            let myCls = AClass()
            myCls.Win32CallMethod() |> ignore
        | _ -> ()

// This code example produces the following results.
//
// First, the compilation yields the warning, "... This method is
// obsolete. Use managed MsgBox instead."
// Second, execution yields a message box with a title of "Caution!"
// and message text of "This is an unmanaged call."
// Third, the following text is displayed in the console window:

// Method Win32CallMethod is obsolete. The message is:
//   "This method is obsolete. Use managed MsgBox instead."
// This method calls unmanaged code.
// The Unmanaged attribute type is User.
Imports System.Reflection
Imports System.Security
Imports System.Runtime.InteropServices

' Define an enumeration of Win32 unmanaged types
Public Enum UnmanagedType
    User
    GDI
    Kernel
    Shell
    Networking
    Multimedia
End Enum 'UnmanagedType

' Define the Unmanaged attribute.
Public Class UnmanagedAttribute 
             Inherits Attribute

    ' Storage for the UnmanagedType value.
    Protected thisType As UnmanagedType
    
    ' Set the unmanaged type in the constructor.
    Public Sub New(ByVal type As UnmanagedType) 
        thisType = type
    End Sub
    
    ' Define a property to get and set the UnmanagedType value.
    Public Property Win32Type() As UnmanagedType 
        Get
            Return thisType
        End Get
        Set
            thisType = Win32Type
        End Set
    End Property
End Class

' Create a class for an imported Win32 unmanaged function.
Public Class Win32
    <DllImport("user32.dll", CharSet:=CharSet.Unicode)> _
    Public Shared Function MessageBox(ByVal hWnd As Integer, _
                                      ByVal Text As String, _
                                      ByVal caption As String, _
                                      ByVal type As Integer) As Integer
    End Function 'MessageBox
End Class

Public Class AClass
    ' Add some attributes to Win32CallMethod.
    <Obsolete("This method is obsolete. Use managed MsgBox instead."), _
     Unmanaged(UnmanagedType.User)>  _
    Public Sub Win32CallMethod() 
        Win32.MessageBox(0, "This is an unmanaged call.", "Caution!", 0)    
    End Sub
End Class

Class DemoClass
    Shared Sub Main(ByVal args() As String) 
        ' Get the AClass type to access its metadata.
        Dim clsType As Type = GetType(AClass)
        ' Get the type information for Win32CallMethod.
        Dim mInfo As MethodInfo = clsType.GetMethod("Win32CallMethod")
        If Not (mInfo Is Nothing) Then
            ' Iterate through all the attributes of the method.
            Dim attr As Attribute
            For Each attr In  Attribute.GetCustomAttributes(mInfo)
                ' Check for the Obsolete attribute.
                If attr.GetType().Equals(GetType(ObsoleteAttribute)) Then
                    Console.WriteLine("Method {0} is obsolete. The message is:", mInfo.Name)
                    Console.WriteLine("  ""{0}""", CType(attr, ObsoleteAttribute).Message)
                ' Check for the Unmanaged attribute.
                ElseIf attr.GetType().Equals(GetType(UnmanagedAttribute)) Then
                    Console.WriteLine("This method calls unmanaged code.")
                    Console.WriteLine( _
                            String.Format("The Unmanaged attribute type is {0}.", _
                            CType(attr, UnmanagedAttribute).Win32Type))
                    Dim myCls As New AClass()
                    myCls.Win32CallMethod()
                End If
            Next attr
        End If
    End Sub
End Class

'
'This code example produces the following results. 
'
'First, the compilation yields the warning, "... This method is 
'obsolete. Use managed MsgBox instead."
'Second, execution yields a message box with a title of "Caution!" 
'and message text of "This is an unmanaged call." 
'Third, the following text is displayed in the console window:
'
'Method Win32CallMethod is obsolete. The message is:
'  "This method is obsolete. Use managed MsgBox instead."
'This method calls unmanaged code.
'The Unmanaged attribute type is User.
'

설명

반환 값에는 의 element상위 항목에 대한 사용자 지정 특성이 포함됩니다.

참고

.NET Framework 버전 2.0부터 이 메서드는 특성이 새 메타데이터 형식으로 저장되는 경우 메서드, 생성자 및 형식에 대한 보안 특성을 반환합니다. 버전 2.0 이상으로 컴파일된 어셈블리는 새 형식을 사용합니다. 이전 버전의 .NET Framework 컴파일된 동적 어셈블리 및 어셈블리는 이전 XML 형식을 사용합니다. 선언적 보안 특성 내보내기를 참조하세요.

적용 대상

GetCustomAttributes(Assembly, Type, Boolean)

어셈블리에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 어셈블리, 검색할 사용자 지정 특성의 형식 및 무시된 검색 옵션을 지정합니다.

public:
 static cli::array <Attribute ^> ^ GetCustomAttributes(System::Reflection::Assembly ^ element, Type ^ attributeType, bool inherit);
public static Attribute[] GetCustomAttributes (System.Reflection.Assembly element, Type attributeType, bool inherit);
static member GetCustomAttributes : System.Reflection.Assembly * Type * bool -> Attribute[]
Public Shared Function GetCustomAttributes (element As Assembly, attributeType As Type, inherit As Boolean) As Attribute()

매개 변수

element
Assembly

Assembly 클래스에서 파생된 개체로, 모듈의 재사용 가능한 컬렉션을 설명합니다.

attributeType
Type

검색할 사용자 지정 특성의 형식, 즉 기본 형식입니다.

inherit
Boolean

이 매개 변수는 무시되며 이 메서드의 작업에 영향을 끼치지 않습니다.

반환

attributeType에 적용된 element 형식의 사용자 지정 특성을 포함하는 Attribute 배열이거나, 그러한 사용자 지정 특성이 없는 경우에는 빈 배열입니다.

예외

element 또는 attributeTypenull인 경우

attributeTypeAttribute에서 파생되지 않은 경우

예제

다음 코드 예제에서는 를 매개 변수로 사용하여 AssemblyGetCustomAttributes사용하는 방법을 보여 줍니다.

using namespace System;
using namespace System::Reflection;

[assembly:AssemblyTitle("CustAttrs1CPP")];
[assembly:AssemblyDescription("GetCustomAttributes() Demo")];
[assembly:AssemblyCompany("Microsoft")];

ref class Example
{};

static void main()
{
    Type^ clsType = Example::typeid;

    // Get the Assembly type to access its metadata.
    Assembly^ assy = clsType->Assembly;

    // Iterate through the attributes for the assembly.
    System::Collections::IEnumerator^ myEnum = Attribute::GetCustomAttributes( assy )->GetEnumerator();
    while ( myEnum->MoveNext() )
    {
       Attribute^ attr = safe_cast<Attribute^>(myEnum->Current);

       // Check for the AssemblyTitle attribute.
       if ( attr->GetType() == AssemblyTitleAttribute::typeid )
          Console::WriteLine( "Assembly title is \"{0}\".", (dynamic_cast<AssemblyTitleAttribute^>(attr))->Title );
          // Check for the AssemblyDescription attribute.
       else
          // Check for the AssemblyDescription attribute.
          if ( attr->GetType() == AssemblyDescriptionAttribute::typeid )
             Console::WriteLine( "Assembly description is \"{0}\".", (dynamic_cast<AssemblyDescriptionAttribute^>(attr))->Description );
          // Check for the AssemblyCompany attribute.
          else if ( attr->GetType() == AssemblyCompanyAttribute::typeid )
             Console::WriteLine( "Assembly company is {0}.", (dynamic_cast<AssemblyCompanyAttribute^>(attr))->Company );
    }
}
// The example displays the following output:
//     Assembly description is "GetCustomAttributes() Demo".
//     Assembly company is Microsoft.
//     Assembly title is "CustAttrs1CPP".
using System;
using System.Reflection;

[assembly: AssemblyTitle("CustAttrs1CS")]
[assembly: AssemblyDescription("GetCustomAttributes() Demo")]
[assembly: AssemblyCompany("Microsoft")]

class Example {
    static void Main() {
        // Get the Assembly object to access its metadata.
        Assembly assy = typeof(Example).Assembly;

        // Iterate through the attributes for the assembly.
        foreach(Attribute attr in Attribute.GetCustomAttributes(assy)) {
            // Check for the AssemblyTitle attribute.
            if (attr.GetType() == typeof(AssemblyTitleAttribute))
                Console.WriteLine("Assembly title is \"{0}\".",
                    ((AssemblyTitleAttribute)attr).Title);

            // Check for the AssemblyDescription attribute.
            else if (attr.GetType() ==
                typeof(AssemblyDescriptionAttribute))
                Console.WriteLine("Assembly description is \"{0}\".",
                    ((AssemblyDescriptionAttribute)attr).Description);

            // Check for the AssemblyCompany attribute.
            else if (attr.GetType() == typeof(AssemblyCompanyAttribute))
                Console.WriteLine("Assembly company is {0}.",
                    ((AssemblyCompanyAttribute)attr).Company);
        }
   }
}
// The example displays the following output:
//     Assembly title is "CustAttrs1CS".
//     Assembly description is "GetCustomAttributes() Demo".
//     Assembly company is Microsoft.
open System
open System.Reflection

[<assembly: AssemblyTitle "CustAttrs1CS">]
[<assembly: AssemblyDescription "GetCustomAttributes() Demo">]
[<assembly: AssemblyCompany"Microsoft">]
do ()

type Example = class end

// Get the Assembly object to access its metadata.
let assembly = typeof<Example>.Assembly

// Iterate through the attributes for the assembly.
for attr in Attribute.GetCustomAttributes assembly do
    match attr with
    // Check for the AssemblyTitle attribute.
    | :? AssemblyTitleAttribute as attr ->    
        printfn $"Assembly title is \"{attr.Title}\"."
    // Check for the AssemblyDescription attribute.
    | :? AssemblyDescriptionAttribute as attr ->
        printfn $"Assembly description is \"{attr.Description}\"."
    // Check for the AssemblyCompany attribute.
    | :? AssemblyCompanyAttribute as attr ->
        printfn $"Assembly company is {attr.Company}."
    | _ -> ()
    
// The example displays the following output:
//     Assembly title is "CustAttrs1CS".
//     Assembly description is "GetCustomAttributes() Demo".
//     Assembly company is Microsoft.
Imports System.Reflection

<Assembly: AssemblyTitle("CustAttrs1VB")> 
<Assembly: AssemblyDescription("GetCustomAttributes() Demo")> 
<Assembly: AssemblyCompany("Microsoft")> 

Module Example
    Sub Main()
        ' Get the Assembly type to access its metadata.
        Dim assy As Reflection.Assembly = GetType(Example).Assembly

        ' Iterate through all the attributes for the assembly.
        For Each attr As Attribute In Attribute.GetCustomAttributes(assy)
            ' Check for the AssemblyTitle attribute.
            If TypeOf attr Is AssemblyTitleAttribute Then
                ' Convert the attribute to access its data.
                Dim attrTitle As AssemblyTitleAttribute = _
                    CType(attr, AssemblyTitleAttribute)
                Console.WriteLine("Assembly title is ""{0}"".", _
                    attrTitle.Title)

            ' Check for the AssemblyDescription attribute.
            ElseIf TypeOf attr Is AssemblyDescriptionAttribute Then
                ' Convert the attribute to access its data.
                Dim attrDesc As AssemblyDescriptionAttribute = _
                    CType(attr, AssemblyDescriptionAttribute)
                Console.WriteLine("Assembly description is ""{0}"".", _
                    attrDesc.Description)

            ' Check for the AssemblyCompany attribute.
            ElseIf TypeOf attr Is AssemblyCompanyAttribute Then
                ' Convert the attribute to access its data.
                Dim attrComp As AssemblyCompanyAttribute = _
                    CType(attr, AssemblyCompanyAttribute)
                Console.WriteLine("Assembly company is {0}.", _
                    attrComp.Company)
            End If
        Next
    End Sub
End Module
' The example displays the following output:
'     Assembly company is Microsoft.
'     Assembly description is "GetCustomAttributes() Demo".
'     Assembly title is "CustAttrs1VB".

설명

참고

.NET Framework 버전 2.0부터 이 메서드는 특성이 새 메타데이터 형식으로 저장된 경우 보안 특성을 반환합니다. 버전 2.0 이상으로 컴파일된 어셈블리는 새 형식을 사용합니다. 이전 버전의 .NET Framework 컴파일된 동적 어셈블리 및 어셈블리는 이전 XML 형식을 사용합니다. 선언적 보안 특성 내보내기를 참조하세요.

적용 대상

GetCustomAttributes(Module, Type)

모듈에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 모듈과 검색할 사용자 지정 특성의 형식을 지정합니다.

public:
 static cli::array <Attribute ^> ^ GetCustomAttributes(System::Reflection::Module ^ element, Type ^ attributeType);
public static Attribute[] GetCustomAttributes (System.Reflection.Module element, Type attributeType);
static member GetCustomAttributes : System.Reflection.Module * Type -> Attribute[]
Public Shared Function GetCustomAttributes (element As Module, attributeType As Type) As Attribute()

매개 변수

element
Module

이식 가능한 실행 파일을 설명하는 Module 클래스에서 파생된 개체입니다.

attributeType
Type

검색할 사용자 지정 특성의 형식, 즉 기본 형식입니다.

반환

attributeType에 적용된 element 형식의 사용자 지정 특성을 포함하는 Attribute 배열이거나, 그러한 사용자 지정 특성이 없는 경우에는 빈 배열입니다.

예외

element 또는 attributeTypenull인 경우

attributeTypeAttribute에서 파생되지 않은 경우

예제

다음 코드 예제에서는 를 매개 변수로 사용하여 ModuleGetCustomAttributes사용하는 방법을 보여 줍니다.

using namespace System;
using namespace System::Reflection;
using namespace System::ComponentModel;

// Assign some attributes to the module.
// Set the module's CLSCompliant attribute to false
// The CLSCompliant attribute is applicable for /target:module.
[module:Description("A sample description")];
[module:CLSCompliant(false)];
namespace CustAttrs2CS
{
   ref class DemoClass
   {
   public:
      static void Main()
      {
         Type^ clsType = DemoClass::typeid;

         // Get the Module type to access its metadata.
         Module^ module = clsType->Module;

         // Iterate through all the attributes for the module.
         System::Collections::IEnumerator^ myEnum1 = Attribute::GetCustomAttributes( module )->GetEnumerator();
         while ( myEnum1->MoveNext() )
         {
            Attribute^ attr = safe_cast<Attribute^>(myEnum1->Current);

            // Check for the Description attribute.
            if ( attr->GetType() == DescriptionAttribute::typeid )
                        Console::WriteLine( "Module {0} has the description \"{1}\".", module->Name, (dynamic_cast<DescriptionAttribute^>(attr))->Description );
            // Check for the CLSCompliant attribute.
            else

            // Check for the CLSCompliant attribute.
            if ( attr->GetType() == CLSCompliantAttribute::typeid )
                        Console::WriteLine( "Module {0} {1} CLSCompliant.", module->Name, (dynamic_cast<CLSCompliantAttribute^>(attr))->IsCompliant ? (String^)"is" : "is not" );
         }
      }
   };
}


/*
 * Output:
 * Module CustAttrs2CS.exe is not CLSCompliant.
 * Module CustAttrs2CS.exe has the description "A sample description".
 */
using System;
using System.Reflection;
using System.ComponentModel;

// Assign some attributes to the module.
[module:Description("A sample description")]

// Set the module's CLSCompliant attribute to false
// The CLSCompliant attribute is applicable for /target:module.
[module:CLSCompliant(false)]

namespace CustAttrs2CS {
    class DemoClass {
        static void Main(string[] args) {
            Type clsType = typeof(DemoClass);
            // Get the Module type to access its metadata.
            Module module = clsType.Module;

            // Iterate through all the attributes for the module.
            foreach(Attribute attr in Attribute.GetCustomAttributes(module)) {
                // Check for the Description attribute.
                if (attr.GetType() == typeof(DescriptionAttribute))
                    Console.WriteLine("Module {0} has the description " +
                        "\"{1}\".", module.Name,
                        ((DescriptionAttribute)attr).Description);
                // Check for the CLSCompliant attribute.
                else if (attr.GetType() == typeof(CLSCompliantAttribute))
                    Console.WriteLine("Module {0} {1} CLSCompliant.",
                        module.Name,
                        ((CLSCompliantAttribute)attr).IsCompliant ?
                            "is" : "is not");
            }
        }
    }
}

/*
 * Output:
 * Module CustAttrs2CS.exe is not CLSCompliant.
 * Module CustAttrs2CS.exe has the description "A sample description".
 */
open System
open System.ComponentModel

// Assign some attributes to the module.
[<``module``: Description "A sample description">]

// Set the module's CLSCompliant attribute to false
// The CLSCompliant attribute is applicable for /target:module.
[<``module``: CLSCompliant false>]
do ()

type DemoClass = class end

// Get the Module type to access its metadata.
let ilmodule = typeof<DemoClass>.Module

// Iterate through all the attributes for the module.
for attr in Attribute.GetCustomAttributes ilmodule do
    match attr with
    // Check for the Description attribute.
    | :? DescriptionAttribute as attr ->
        printfn $"Module {ilmodule.Name} has the description \"{attr.Description}\"."
                
    // Check for the CLSCompliant attribute.
    | :? CLSCompliantAttribute as attr ->
        printfn $"""Module {ilmodule.Name} {if attr.IsCompliant then "is" else "is not"} CLSCompliant."""
    | _ -> ()
    
// Output:
// Module CustAttrs2CS.exe is not CLSCompliant.
// Module CustAttrs2CS.exe has the description "A sample description".
Imports System.Reflection
Imports System.ComponentModel

' Give the Module some attributes.
<Module: Description("A sample description")> 

' Make the CLSCompliant attribute False.
' The CLSCompliant attribute is applicable for /target:module.
<Module: CLSCompliant(False)> 

Module DemoModule

    Sub Main()
        ' Get the Module type to access its metadata.
        Dim modType As Reflection.Module = GetType(DemoModule).Module
        Dim attr As Attribute
        ' Iterate through all the attributes for the module.
        For Each attr In Attribute.GetCustomAttributes(modType)
            ' Check for the Description attribute.
            If TypeOf attr Is DescriptionAttribute Then
                ' Convert the attribute to access its data.
                Dim descAttr As DescriptionAttribute = _
                    CType(attr, DescriptionAttribute)
                Console.WriteLine("Module {0} has the description ""{1}"".", _
                    modType.Name, descAttr.Description)

            ' Check for the CLSCompliant attribute.
            ElseIf TypeOf attr Is CLSCompliantAttribute Then
                ' Convert the attribute to access its data.
                Dim CLSCompAttr As CLSCompliantAttribute = _
                    CType(attr, CLSCompliantAttribute)
                Dim strCompliant As String
                If CLSCompAttr.IsCompliant Then
                    strCompliant = "is"
                Else
                    strCompliant = "is not"
                End If
                Console.WriteLine("Module {0} {1} CLSCompliant.", _
                    modType.Name, strCompliant)
            End If
        Next
    End Sub
End Module

' Output:
' Module CustAttrs2VB.exe has the description "A sample description".
' Module CustAttrs2VB.exe is not CLSCompliant.

적용 대상

GetCustomAttributes(ParameterInfo, Type)

메서드 매개 변수에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 메서드 매개 변수와 검색할 사용자 지정 특성의 형식을 지정합니다.

public:
 static cli::array <Attribute ^> ^ GetCustomAttributes(System::Reflection::ParameterInfo ^ element, Type ^ attributeType);
public static Attribute[] GetCustomAttributes (System.Reflection.ParameterInfo element, Type attributeType);
static member GetCustomAttributes : System.Reflection.ParameterInfo * Type -> Attribute[]
Public Shared Function GetCustomAttributes (element As ParameterInfo, attributeType As Type) As Attribute()

매개 변수

element
ParameterInfo

클래스의 멤버 매개 변수를 설명하는 ParameterInfo 클래스에서 파생된 개체입니다.

attributeType
Type

검색할 사용자 지정 특성의 형식, 즉 기본 형식입니다.

반환

attributeType에 적용된 element 형식의 사용자 지정 특성을 포함하는 Attribute 배열이거나, 그러한 사용자 지정 특성이 없는 경우에는 빈 배열입니다.

예외

element 또는 attributeTypenull인 경우

attributeTypeAttribute에서 파생되지 않은 경우

사용자 지정 특성 형식을 로드할 수 없는 경우

예제

다음 코드 예제에서는 를 매개 변수로 사용하여 ParameterInfoGetCustomAttributes사용하는 방법을 보여 줍니다.

using namespace System;
using namespace System::Reflection;
using namespace System::ComponentModel;

namespace CustAttrs5CS
{
   public ref class AClass
   {
   public:
      void ParamArrayAndDesc(
         // Add ParamArray and Description attributes.
         [Description("This argument is a ParamArray")]
         array<Int32>^args )
      {}
   };

   ref class DemoClass
   {
   public:
      static void Main()
      {
         // Get the Class type to access its metadata.
         Type^ clsType = AClass::typeid;

         // Get the type information for the method.
         MethodInfo^ mInfo = clsType->GetMethod( "ParamArrayAndDesc" );
         if ( mInfo != nullptr )
         {
            // Get the parameter information.
            array<ParameterInfo^>^pInfo = mInfo->GetParameters();
            if ( pInfo != nullptr )
            {
               // Iterate through all the attributes for the parameter.
               System::Collections::IEnumerator^ myEnum4 = Attribute::GetCustomAttributes( pInfo[ 0 ] )->GetEnumerator();
               while ( myEnum4->MoveNext() )
               {
                  Attribute^ attr = safe_cast<Attribute^>(myEnum4->Current);

                  // Check for the ParamArray attribute.
                  if ( attr->GetType() == ParamArrayAttribute::typeid )
                                    Console::WriteLine( "Parameter {0} for method {1} "
                  "has the ParamArray attribute.", pInfo[ 0 ]->Name, mInfo->Name );
                  // Check for the Description attribute.
                  else

                  // Check for the Description attribute.
                  if ( attr->GetType() == DescriptionAttribute::typeid )
                  {
                     Console::WriteLine( "Parameter {0} for method {1} "
                     "has a description attribute.", pInfo[ 0 ]->Name, mInfo->Name );
                     Console::WriteLine( "The description is: \"{0}\"", (dynamic_cast<DescriptionAttribute^>(attr))->Description );
                  }
               }
            }
         }
      }
   };
}

/*
 * Output:
 * Parameter args for method ParamArrayAndDesc has the ParamArray attribute.
 * Parameter args for method ParamArrayAndDesc has a description attribute.
 * The description is: "This argument is a ParamArray"
 */
using System;
using System.Reflection;
using System.ComponentModel;

namespace CustAttrs5CS {
    public class AClass {
        public void ParamArrayAndDesc(
            // Add ParamArray (with the keyword) and Description attributes.
            [Description("This argument is a ParamArray")]
            params int[] args)
        {}
    }

    class DemoClass {
        static void Main(string[] args) {
            // Get the Class type to access its metadata.
            Type clsType = typeof(AClass);
            // Get the type information for the method.
            MethodInfo mInfo = clsType.GetMethod("ParamArrayAndDesc");
            if (mInfo != null) {
                // Get the parameter information.
                ParameterInfo[] pInfo = mInfo.GetParameters();
                if (pInfo != null) {
                    // Iterate through all the attributes for the parameter.
                    foreach(Attribute attr in
                        Attribute.GetCustomAttributes(pInfo[0])) {
                        // Check for the ParamArray attribute.
                        if (attr.GetType() == typeof(ParamArrayAttribute))
                            Console.WriteLine("Parameter {0} for method {1} " +
                                "has the ParamArray attribute.",
                                pInfo[0].Name, mInfo.Name);
                        // Check for the Description attribute.
                        else if (attr.GetType() ==
                            typeof(DescriptionAttribute)) {
                            Console.WriteLine("Parameter {0} for method {1} " +
                                "has a description attribute.",
                                pInfo[0].Name, mInfo.Name);
                            Console.WriteLine("The description is: \"{0}\"",
                                ((DescriptionAttribute)attr).Description);
                        }
                    }
                }
            }
        }
    }
}

/*
 * Output:
 * Parameter args for method ParamArrayAndDesc has the ParamArray attribute.
 * Parameter args for method ParamArrayAndDesc has a description attribute.
 * The description is: "This argument is a ParamArray"
 */
open System
open System.Reflection
open System.ComponentModel

type AClass() =
    member _.ParamArrayAndDesc(
        // Add ParamArray and Description attributes.
        [<Description "This argument is a ParamArray">]
        [<ParamArray>]
        args: int[]) = ()

// Get the Class type to access its metadata.
let clsType = typeof<AClass>

// Get the type information for the method.
let mInfo = clsType.GetMethod "ParamArrayAndDesc"
if mInfo <> null then
    // Get the parameter information.
    let pInfo = mInfo.GetParameters()
    if pInfo <> null then
        // Iterate through all the attributes for the parameter.
        for attr in Attribute.GetCustomAttributes pInfo[0] do
            match attr with 
            // Check for the ParamArray attribute.
            | :? ParamArrayAttribute ->
                printfn $"Parameter {pInfo[0].Name} for method {mInfo.Name} has the ParamArray attribute."
                                
            // Check for the Description attribute.
            | :? DescriptionAttribute as attr ->
                printfn $"Parameter {pInfo[0].Name} for method {mInfo.Name} has a description attribute."
                printfn $"The description is: \"{attr.Description}\""
            | _ -> ()

// Output:
// Parameter args for method ParamArrayAndDesc has a description attribute.
// The description is: "This argument is a ParamArray"
// Parameter args for method ParamArrayAndDesc has the ParamArray attribute.
Imports System.Reflection
Imports System.ComponentModel

Module DemoModule
    Public Class AClass
        ' Add Description and ParamArray (with the keyword) attributes.
        Public Sub ParamArrayAndDesc( _
            <Description("This argument is a ParamArray")> _
            ByVal ParamArray args() As Integer)
        End Sub
    End Class

    Sub Main()
        ' Get the Class type to access its metadata.
        Dim clsType As Type = GetType(AClass)
        ' Get the type information for the method.
        Dim mInfo As MethodInfo = clsType.GetMethod("ParamArrayAndDesc")
        ' Get the Parameter information for the method.
        Dim pInfo() As ParameterInfo = mInfo.GetParameters()
        Dim attr As Attribute
        ' Iterate through each attribute of the parameter.
        For Each attr In Attribute.GetCustomAttributes(pInfo(0))
            ' Check for the ParamArray attribute.
            If TypeOf attr Is ParamArrayAttribute Then
                ' Convert the attribute to access its data.
                Dim paAttr As ParamArrayAttribute = _
                    CType(attr, ParamArrayAttribute)
                Console.WriteLine("Parameter {0} for method {1} has the " + _
                    "ParamArray attribute.", pInfo(0).Name, mInfo.Name)
            ' Check for the Description attribute.
            ElseIf TypeOf attr Is DescriptionAttribute Then
                ' Convert the attribute to access its data.
                Dim descAttr As DescriptionAttribute = _
                    CType(attr, DescriptionAttribute)
                Console.WriteLine("Parameter {0} for method {1} has a description " + _
                    "attribute. The description is:", pInfo(0).Name, mInfo.Name)
                Console.WriteLine(descAttr.Description)
            End If
        Next
    End Sub
End Module

' Output:
' Parameter args for method ParamArrayAndDesc has the ParamArray attribute.
' Parameter args for method ParamArrayAndDesc has a description attribute. The description is:
' This argument is a ParamArray

설명

파생 형식의 메서드에서 매개 변수를 나타내는 경우 element 반환 값에는 재정의된 기본 메서드의 동일한 매개 변수에 적용된 상속 가능한 사용자 지정 특성이 포함됩니다.

적용 대상

GetCustomAttributes(MemberInfo, Boolean)

형식 멤버에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 멤버, 검색할 사용자 지정 특성의 형식 및 상위 멤버의 검색 여부를 지정합니다.

public:
 static cli::array <Attribute ^> ^ GetCustomAttributes(System::Reflection::MemberInfo ^ element, bool inherit);
public static Attribute[] GetCustomAttributes (System.Reflection.MemberInfo element, bool inherit);
static member GetCustomAttributes : System.Reflection.MemberInfo * bool -> Attribute[]
Public Shared Function GetCustomAttributes (element As MemberInfo, inherit As Boolean) As Attribute()

매개 변수

element
MemberInfo

클래스의 생성자, 이벤트, 필드, 메서드 또는 속성 멤버를 설명하는 MemberInfo 클래스에서 파생된 개체입니다.

inherit
Boolean

true이면 사용자 지정 특성에 대한 상위 element도 검색함을 지정합니다.

반환

element에 적용된 사용자 지정 특성이 포함된 Attribute 배열이며, 그러한 사용자 지정 특성이 없는 경우에는 빈 배열입니다.

예외

element이(가) null인 경우

element가 생성자, 메서드, 속성, 이벤트, 형식 또는 필드가 아닌 경우

사용자 지정 특성 형식을 로드할 수 없는 경우

예제

다음 코드 예제에서는 를 매개 변수로 사용하여 MemberInfoGetCustomAttributes사용하는 방법을 보여 줍니다.

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

namespace CustAttrs4CS
{
   // Create a class for Win32 imported unmanaged functions.
   public ref class Win32
   {
   public:

      [DllImport("user32.dll", CharSet = CharSet::Unicode)]
      static int MessageBox( int hWnd, String^ text, String^ caption, UInt32 type );
   };

   public ref class AClass
   {
   public:

      // Add some attributes to the Win32CallMethod.

      [Obsolete("This method is obsolete. Use managed MsgBox instead.")]
      void Win32CallMethod()
      {
         Win32::MessageBox( 0, "This is an unmanaged call.", "Be Careful!", 0 );
      }

   };

   ref class DemoClass
   {
   public:
      static void Main()
      {
         // Get the Class type to access its metadata.
         Type^ clsType = AClass::typeid;

         // Get the type information for the Win32CallMethod.
         MethodInfo^ mInfo = clsType->GetMethod( "Win32CallMethod" );
         if ( mInfo != nullptr )
         {
            // Iterate through all the attributes for the method.
            System::Collections::IEnumerator^ myEnum3 = Attribute::GetCustomAttributes( mInfo )->GetEnumerator();
            while ( myEnum3->MoveNext() )
            {
               Attribute^ attr = safe_cast<Attribute^>(myEnum3->Current);

               // Check for the Obsolete attribute.
               if ( attr->GetType() == ObsoleteAttribute::typeid )
               {
                  Console::WriteLine( "Method {0} is obsolete. "
                  "The message is:", mInfo->Name );
                  Console::WriteLine( (dynamic_cast<ObsoleteAttribute^>(attr))->Message );
               }
               // Check for the SuppressUnmanagedCodeSecurity attribute.
               else

               // Check for the SuppressUnmanagedCodeSecurity attribute.
               if ( attr->GetType() == SuppressUnmanagedCodeSecurityAttribute::typeid )
               {
                  Console::WriteLine( "This method calls unmanaged code "
                  "with no security check." );
                  Console::WriteLine( "Please do not use unless absolutely necessary." );
                  AClass^ myCls = gcnew AClass;
                  myCls->Win32CallMethod();
               }
            }
         }
      }
   };
}


/*
 * Output:
 * Method Win32CallMethod is obsolete. The message is:
 * This method is obsolete. Use managed MsgBox instead.
 * This method calls unmanaged code with no security check.
 * Please do not use unless absolutely necessary.
 */
using System;
using System.Reflection;
using System.Security;
using System.Runtime.InteropServices;

namespace CustAttrs4CS
{

    // Define an enumeration of Win32 unmanaged types
    public enum UnmanagedType
    {
        User,
        GDI,
        Kernel,
        Shell,
        Networking,
        Multimedia
    }

    // Define the Unmanaged attribute.
    public class UnmanagedAttribute : Attribute
    {
        // Storage for the UnmanagedType value.
        protected UnmanagedType thisType;

        // Set the unmanaged type in the constructor.
        public UnmanagedAttribute(UnmanagedType type)
        {
            thisType = type;
        }

        // Define a property to get and set the UnmanagedType value.
        public UnmanagedType Win32Type
        {
            get { return thisType; }
            set { thisType = Win32Type; }
        }
    }

    // Create a class for an imported Win32 unmanaged function.
    public class Win32 {
        [DllImport("user32.dll", CharSet = CharSet.Unicode)]
        public static extern int MessageBox(int hWnd, String text,
            String caption, uint type);
    }

    public class AClass {
        // Add some attributes to Win32CallMethod.
        [Obsolete("This method is obsolete. Use managed MsgBox instead.")]
        [Unmanaged(UnmanagedType.User)]
        public void Win32CallMethod()
        {
            Win32.MessageBox(0, "This is an unmanaged call.", "Caution!", 0);
        }
    }

    class DemoClass {
        static void Main(string[] args)
            {
            // Get the AClass type to access its metadata.
            Type clsType = typeof(AClass);
            // Get the type information for Win32CallMethod.
            MethodInfo mInfo = clsType.GetMethod("Win32CallMethod");
            if (mInfo != null)
            {
                // Iterate through all the attributes of the method.
                foreach(Attribute attr in
                    Attribute.GetCustomAttributes(mInfo)) {
                    // Check for the Obsolete attribute.
                    if (attr.GetType() == typeof(ObsoleteAttribute))
                    {
                        Console.WriteLine("Method {0} is obsolete. " +
                            "The message is:",
                            mInfo.Name);
                        Console.WriteLine("  \"{0}\"",
                            ((ObsoleteAttribute)attr).Message);
                    }

                    // Check for the Unmanaged attribute.
                    else if (attr.GetType() == typeof(UnmanagedAttribute))
                    {
                        Console.WriteLine(
                            "This method calls unmanaged code.");
                        Console.WriteLine(
                            String.Format("The Unmanaged attribute type is {0}.",
                                          ((UnmanagedAttribute)attr).Win32Type));
                        AClass myCls = new AClass();
                        myCls.Win32CallMethod();
                    }
                }
            }
        }
    }
}

/*

This code example produces the following results.

First, the compilation yields the warning, "... This method is
obsolete. Use managed MsgBox instead."
Second, execution yields a message box with a title of "Caution!"
and message text of "This is an unmanaged call."
Third, the following text is displayed in the console window:

Method Win32CallMethod is obsolete. The message is:
  "This method is obsolete. Use managed MsgBox instead."
This method calls unmanaged code.
The Unmanaged attribute type is User.

*/
open System
open System.Runtime.InteropServices

// Define an enumeration of Win32 unmanaged types
type UnmanagedType =
    | User = 0
    | GDI = 1
    | Kernel = 2
    | Shell = 3
    | Networking = 4
    | Multimedia = 5

// Define the Unmanaged attribute.
type UnmanagedAttribute(unmanagedType) =
    inherit Attribute()
    
    // Define a property to get and set the UnmanagedType value.
    member val Win32Type = unmanagedType with get, set

// Create a module for an imported Win32 unmanaged function.
module Win32 =
    [<DllImport("user32.dll", CharSet = CharSet.Unicode)>]
    extern int MessageBox(IntPtr hWnd, String text, String caption, uint ``type``)

type AClass() =
    // Add some attributes to Win32CallMethod.
    [<Obsolete "This method is obsolete. Use managed MsgBox instead.">]
    [<Unmanaged(UnmanagedType.User)>]
    member _.Win32CallMethod () =
        Win32.MessageBox(0, "This is an unmanaged call.", "Caution!", 0u)

// Get the AClass type to access its metadata.
let clsType = typeof<AClass>
// Get the type information for Win32CallMethod.
let mInfo = clsType.GetMethod "Win32CallMethod"
if mInfo <> null then
    // Iterate through all the attributes of the method.
    for attr in Attribute.GetCustomAttributes mInfo do
        match attr with 
        // Check for the Obsolete attribute.
        | :? ObsoleteAttribute as attr ->
            printfn $"Method {mInfo.Name} is obsolete. The message is:"
            printfn $"  \"{attr.Message}\""

        // Check for the Unmanaged attribute.
        | :? UnmanagedAttribute as attr ->
            printfn "This method calls unmanaged code."
            printfn $"The Unmanaged attribute type is {attr.Win32Type}."
            let myCls = AClass()
            myCls.Win32CallMethod() |> ignore
        | _ -> ()

// This code example produces the following results.
//
// First, the compilation yields the warning, "... This method is
// obsolete. Use managed MsgBox instead."
// Second, execution yields a message box with a title of "Caution!"
// and message text of "This is an unmanaged call."
// Third, the following text is displayed in the console window:

// Method Win32CallMethod is obsolete. The message is:
//   "This method is obsolete. Use managed MsgBox instead."
// This method calls unmanaged code.
// The Unmanaged attribute type is User.
Imports System.Reflection
Imports System.Security
Imports System.Runtime.InteropServices

' Define an enumeration of Win32 unmanaged types
Public Enum UnmanagedType
    User
    GDI
    Kernel
    Shell
    Networking
    Multimedia
End Enum 'UnmanagedType

' Define the Unmanaged attribute.
Public Class UnmanagedAttribute 
             Inherits Attribute

    ' Storage for the UnmanagedType value.
    Protected thisType As UnmanagedType
    
    ' Set the unmanaged type in the constructor.
    Public Sub New(ByVal type As UnmanagedType) 
        thisType = type
    End Sub
    
    ' Define a property to get and set the UnmanagedType value.
    Public Property Win32Type() As UnmanagedType 
        Get
            Return thisType
        End Get
        Set
            thisType = Win32Type
        End Set
    End Property
End Class

' Create a class for an imported Win32 unmanaged function.
Public Class Win32
    <DllImport("user32.dll", CharSet:=CharSet.Unicode)> _
    Public Shared Function MessageBox(ByVal hWnd As Integer, _
                                      ByVal Text As String, _
                                      ByVal caption As String, _
                                      ByVal type As Integer) As Integer
    End Function 'MessageBox
End Class

Public Class AClass
    ' Add some attributes to Win32CallMethod.
    <Obsolete("This method is obsolete. Use managed MsgBox instead."), _
     Unmanaged(UnmanagedType.User)>  _
    Public Sub Win32CallMethod() 
        Win32.MessageBox(0, "This is an unmanaged call.", "Caution!", 0)    
    End Sub
End Class

Class DemoClass
    Shared Sub Main(ByVal args() As String) 
        ' Get the AClass type to access its metadata.
        Dim clsType As Type = GetType(AClass)
        ' Get the type information for Win32CallMethod.
        Dim mInfo As MethodInfo = clsType.GetMethod("Win32CallMethod")
        If Not (mInfo Is Nothing) Then
            ' Iterate through all the attributes of the method.
            Dim attr As Attribute
            For Each attr In  Attribute.GetCustomAttributes(mInfo)
                ' Check for the Obsolete attribute.
                If attr.GetType().Equals(GetType(ObsoleteAttribute)) Then
                    Console.WriteLine("Method {0} is obsolete. The message is:", mInfo.Name)
                    Console.WriteLine("  ""{0}""", CType(attr, ObsoleteAttribute).Message)
                ' Check for the Unmanaged attribute.
                ElseIf attr.GetType().Equals(GetType(UnmanagedAttribute)) Then
                    Console.WriteLine("This method calls unmanaged code.")
                    Console.WriteLine( _
                            String.Format("The Unmanaged attribute type is {0}.", _
                            CType(attr, UnmanagedAttribute).Win32Type))
                    Dim myCls As New AClass()
                    myCls.Win32CallMethod()
                End If
            Next attr
        End If
    End Sub
End Class

'
'This code example produces the following results. 
'
'First, the compilation yields the warning, "... This method is 
'obsolete. Use managed MsgBox instead."
'Second, execution yields a message box with a title of "Caution!" 
'and message text of "This is an unmanaged call." 
'Third, the following text is displayed in the console window:
'
'Method Win32CallMethod is obsolete. The message is:
'  "This method is obsolete. Use managed MsgBox instead."
'This method calls unmanaged code.
'The Unmanaged attribute type is User.
'

설명

반환 값에는 이 인 경우 inheritelement 상위 항목에 대한 사용자 지정 특성이 포함됩니다true.

참고

.NET Framework 버전 2.0부터 이 메서드는 특성이 새 메타데이터 형식으로 저장되는 경우 메서드, 생성자 및 형식에 대한 보안 특성을 반환합니다. 버전 2.0 이상으로 컴파일된 어셈블리는 새 형식을 사용합니다. 이전 버전의 .NET Framework 컴파일된 동적 어셈블리 및 어셈블리는 이전 XML 형식을 사용합니다. 선언적 보안 특성 내보내기를 참조하세요.

적용 대상

GetCustomAttributes(Assembly, Type)

어셈블리에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 어셈블리와 검색할 사용자 지정 특성의 형식을 지정합니다.

public:
 static cli::array <Attribute ^> ^ GetCustomAttributes(System::Reflection::Assembly ^ element, Type ^ attributeType);
public static Attribute[] GetCustomAttributes (System.Reflection.Assembly element, Type attributeType);
static member GetCustomAttributes : System.Reflection.Assembly * Type -> Attribute[]
Public Shared Function GetCustomAttributes (element As Assembly, attributeType As Type) As Attribute()

매개 변수

element
Assembly

Assembly 클래스에서 파생된 개체로, 모듈의 재사용 가능한 컬렉션을 설명합니다.

attributeType
Type

검색할 사용자 지정 특성의 형식, 즉 기본 형식입니다.

반환

attributeType에 적용된 element 형식의 사용자 지정 특성을 포함하는 Attribute 배열이거나, 그러한 사용자 지정 특성이 없는 경우에는 빈 배열입니다.

예외

element 또는 attributeTypenull인 경우

attributeTypeAttribute에서 파생되지 않은 경우

예제

다음 코드 예제에서는 를 매개 변수로 사용하여 AssemblyGetCustomAttributes사용하는 방법을 보여 줍니다.

using namespace System;
using namespace System::Reflection;

[assembly:AssemblyTitle("CustAttrs1CPP")];
[assembly:AssemblyDescription("GetCustomAttributes() Demo")];
[assembly:AssemblyCompany("Microsoft")];

ref class Example
{};

static void main()
{
    Type^ clsType = Example::typeid;

    // Get the Assembly type to access its metadata.
    Assembly^ assy = clsType->Assembly;

    // Iterate through the attributes for the assembly.
    System::Collections::IEnumerator^ myEnum = Attribute::GetCustomAttributes( assy )->GetEnumerator();
    while ( myEnum->MoveNext() )
    {
       Attribute^ attr = safe_cast<Attribute^>(myEnum->Current);

       // Check for the AssemblyTitle attribute.
       if ( attr->GetType() == AssemblyTitleAttribute::typeid )
          Console::WriteLine( "Assembly title is \"{0}\".", (dynamic_cast<AssemblyTitleAttribute^>(attr))->Title );
          // Check for the AssemblyDescription attribute.
       else
          // Check for the AssemblyDescription attribute.
          if ( attr->GetType() == AssemblyDescriptionAttribute::typeid )
             Console::WriteLine( "Assembly description is \"{0}\".", (dynamic_cast<AssemblyDescriptionAttribute^>(attr))->Description );
          // Check for the AssemblyCompany attribute.
          else if ( attr->GetType() == AssemblyCompanyAttribute::typeid )
             Console::WriteLine( "Assembly company is {0}.", (dynamic_cast<AssemblyCompanyAttribute^>(attr))->Company );
    }
}
// The example displays the following output:
//     Assembly description is "GetCustomAttributes() Demo".
//     Assembly company is Microsoft.
//     Assembly title is "CustAttrs1CPP".
using System;
using System.Reflection;

[assembly: AssemblyTitle("CustAttrs1CS")]
[assembly: AssemblyDescription("GetCustomAttributes() Demo")]
[assembly: AssemblyCompany("Microsoft")]

class Example {
    static void Main() {
        // Get the Assembly object to access its metadata.
        Assembly assy = typeof(Example).Assembly;

        // Iterate through the attributes for the assembly.
        foreach(Attribute attr in Attribute.GetCustomAttributes(assy)) {
            // Check for the AssemblyTitle attribute.
            if (attr.GetType() == typeof(AssemblyTitleAttribute))
                Console.WriteLine("Assembly title is \"{0}\".",
                    ((AssemblyTitleAttribute)attr).Title);

            // Check for the AssemblyDescription attribute.
            else if (attr.GetType() ==
                typeof(AssemblyDescriptionAttribute))
                Console.WriteLine("Assembly description is \"{0}\".",
                    ((AssemblyDescriptionAttribute)attr).Description);

            // Check for the AssemblyCompany attribute.
            else if (attr.GetType() == typeof(AssemblyCompanyAttribute))
                Console.WriteLine("Assembly company is {0}.",
                    ((AssemblyCompanyAttribute)attr).Company);
        }
   }
}
// The example displays the following output:
//     Assembly title is "CustAttrs1CS".
//     Assembly description is "GetCustomAttributes() Demo".
//     Assembly company is Microsoft.
open System
open System.Reflection

[<assembly: AssemblyTitle "CustAttrs1CS">]
[<assembly: AssemblyDescription "GetCustomAttributes() Demo">]
[<assembly: AssemblyCompany"Microsoft">]
do ()

type Example = class end

// Get the Assembly object to access its metadata.
let assembly = typeof<Example>.Assembly

// Iterate through the attributes for the assembly.
for attr in Attribute.GetCustomAttributes assembly do
    match attr with
    // Check for the AssemblyTitle attribute.
    | :? AssemblyTitleAttribute as attr ->    
        printfn $"Assembly title is \"{attr.Title}\"."
    // Check for the AssemblyDescription attribute.
    | :? AssemblyDescriptionAttribute as attr ->
        printfn $"Assembly description is \"{attr.Description}\"."
    // Check for the AssemblyCompany attribute.
    | :? AssemblyCompanyAttribute as attr ->
        printfn $"Assembly company is {attr.Company}."
    | _ -> ()
    
// The example displays the following output:
//     Assembly title is "CustAttrs1CS".
//     Assembly description is "GetCustomAttributes() Demo".
//     Assembly company is Microsoft.
Imports System.Reflection

<Assembly: AssemblyTitle("CustAttrs1VB")> 
<Assembly: AssemblyDescription("GetCustomAttributes() Demo")> 
<Assembly: AssemblyCompany("Microsoft")> 

Module Example
    Sub Main()
        ' Get the Assembly type to access its metadata.
        Dim assy As Reflection.Assembly = GetType(Example).Assembly

        ' Iterate through all the attributes for the assembly.
        For Each attr As Attribute In Attribute.GetCustomAttributes(assy)
            ' Check for the AssemblyTitle attribute.
            If TypeOf attr Is AssemblyTitleAttribute Then
                ' Convert the attribute to access its data.
                Dim attrTitle As AssemblyTitleAttribute = _
                    CType(attr, AssemblyTitleAttribute)
                Console.WriteLine("Assembly title is ""{0}"".", _
                    attrTitle.Title)

            ' Check for the AssemblyDescription attribute.
            ElseIf TypeOf attr Is AssemblyDescriptionAttribute Then
                ' Convert the attribute to access its data.
                Dim attrDesc As AssemblyDescriptionAttribute = _
                    CType(attr, AssemblyDescriptionAttribute)
                Console.WriteLine("Assembly description is ""{0}"".", _
                    attrDesc.Description)

            ' Check for the AssemblyCompany attribute.
            ElseIf TypeOf attr Is AssemblyCompanyAttribute Then
                ' Convert the attribute to access its data.
                Dim attrComp As AssemblyCompanyAttribute = _
                    CType(attr, AssemblyCompanyAttribute)
                Console.WriteLine("Assembly company is {0}.", _
                    attrComp.Company)
            End If
        Next
    End Sub
End Module
' The example displays the following output:
'     Assembly company is Microsoft.
'     Assembly description is "GetCustomAttributes() Demo".
'     Assembly title is "CustAttrs1VB".

설명

참고

.NET Framework 버전 2.0부터 이 메서드는 특성이 새 메타데이터 형식으로 저장된 경우 보안 특성을 반환합니다. 버전 2.0 이상으로 컴파일된 어셈블리는 새 형식을 사용합니다. 이전 버전의 .NET Framework 컴파일된 동적 어셈블리 및 어셈블리는 이전 XML 형식을 사용합니다. 선언적 보안 특성 내보내기를 참조하세요.

적용 대상

GetCustomAttributes(Assembly, Boolean)

어셈블리에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 어셈블리와 무시된 검색 옵션을 지정합니다.

public:
 static cli::array <Attribute ^> ^ GetCustomAttributes(System::Reflection::Assembly ^ element, bool inherit);
public static Attribute[] GetCustomAttributes (System.Reflection.Assembly element, bool inherit);
static member GetCustomAttributes : System.Reflection.Assembly * bool -> Attribute[]
Public Shared Function GetCustomAttributes (element As Assembly, inherit As Boolean) As Attribute()

매개 변수

element
Assembly

Assembly 클래스에서 파생된 개체로, 모듈의 재사용 가능한 컬렉션을 설명합니다.

inherit
Boolean

이 매개 변수는 무시되며 이 메서드의 작업에 영향을 끼치지 않습니다.

반환

element에 적용된 사용자 지정 특성이 포함된 Attribute 배열이며, 그러한 사용자 지정 특성이 없는 경우에는 빈 배열입니다.

예외

element 또는 attributeTypenull인 경우

예제

다음 코드 예제에서는 를 매개 변수로 사용하여 AssemblyGetCustomAttributes사용하는 방법을 보여 줍니다.

using namespace System;
using namespace System::Reflection;

[assembly:AssemblyTitle("CustAttrs1CPP")];
[assembly:AssemblyDescription("GetCustomAttributes() Demo")];
[assembly:AssemblyCompany("Microsoft")];

ref class Example
{};

static void main()
{
    Type^ clsType = Example::typeid;

    // Get the Assembly type to access its metadata.
    Assembly^ assy = clsType->Assembly;

    // Iterate through the attributes for the assembly.
    System::Collections::IEnumerator^ myEnum = Attribute::GetCustomAttributes( assy )->GetEnumerator();
    while ( myEnum->MoveNext() )
    {
       Attribute^ attr = safe_cast<Attribute^>(myEnum->Current);

       // Check for the AssemblyTitle attribute.
       if ( attr->GetType() == AssemblyTitleAttribute::typeid )
          Console::WriteLine( "Assembly title is \"{0}\".", (dynamic_cast<AssemblyTitleAttribute^>(attr))->Title );
          // Check for the AssemblyDescription attribute.
       else
          // Check for the AssemblyDescription attribute.
          if ( attr->GetType() == AssemblyDescriptionAttribute::typeid )
             Console::WriteLine( "Assembly description is \"{0}\".", (dynamic_cast<AssemblyDescriptionAttribute^>(attr))->Description );
          // Check for the AssemblyCompany attribute.
          else if ( attr->GetType() == AssemblyCompanyAttribute::typeid )
             Console::WriteLine( "Assembly company is {0}.", (dynamic_cast<AssemblyCompanyAttribute^>(attr))->Company );
    }
}
// The example displays the following output:
//     Assembly description is "GetCustomAttributes() Demo".
//     Assembly company is Microsoft.
//     Assembly title is "CustAttrs1CPP".
using System;
using System.Reflection;

[assembly: AssemblyTitle("CustAttrs1CS")]
[assembly: AssemblyDescription("GetCustomAttributes() Demo")]
[assembly: AssemblyCompany("Microsoft")]

class Example {
    static void Main() {
        // Get the Assembly object to access its metadata.
        Assembly assy = typeof(Example).Assembly;

        // Iterate through the attributes for the assembly.
        foreach(Attribute attr in Attribute.GetCustomAttributes(assy)) {
            // Check for the AssemblyTitle attribute.
            if (attr.GetType() == typeof(AssemblyTitleAttribute))
                Console.WriteLine("Assembly title is \"{0}\".",
                    ((AssemblyTitleAttribute)attr).Title);

            // Check for the AssemblyDescription attribute.
            else if (attr.GetType() ==
                typeof(AssemblyDescriptionAttribute))
                Console.WriteLine("Assembly description is \"{0}\".",
                    ((AssemblyDescriptionAttribute)attr).Description);

            // Check for the AssemblyCompany attribute.
            else if (attr.GetType() == typeof(AssemblyCompanyAttribute))
                Console.WriteLine("Assembly company is {0}.",
                    ((AssemblyCompanyAttribute)attr).Company);
        }
   }
}
// The example displays the following output:
//     Assembly title is "CustAttrs1CS".
//     Assembly description is "GetCustomAttributes() Demo".
//     Assembly company is Microsoft.
open System
open System.Reflection

[<assembly: AssemblyTitle "CustAttrs1CS">]
[<assembly: AssemblyDescription "GetCustomAttributes() Demo">]
[<assembly: AssemblyCompany"Microsoft">]
do ()

type Example = class end

// Get the Assembly object to access its metadata.
let assembly = typeof<Example>.Assembly

// Iterate through the attributes for the assembly.
for attr in Attribute.GetCustomAttributes assembly do
    match attr with
    // Check for the AssemblyTitle attribute.
    | :? AssemblyTitleAttribute as attr ->    
        printfn $"Assembly title is \"{attr.Title}\"."
    // Check for the AssemblyDescription attribute.
    | :? AssemblyDescriptionAttribute as attr ->
        printfn $"Assembly description is \"{attr.Description}\"."
    // Check for the AssemblyCompany attribute.
    | :? AssemblyCompanyAttribute as attr ->
        printfn $"Assembly company is {attr.Company}."
    | _ -> ()
    
// The example displays the following output:
//     Assembly title is "CustAttrs1CS".
//     Assembly description is "GetCustomAttributes() Demo".
//     Assembly company is Microsoft.
Imports System.Reflection

<Assembly: AssemblyTitle("CustAttrs1VB")> 
<Assembly: AssemblyDescription("GetCustomAttributes() Demo")> 
<Assembly: AssemblyCompany("Microsoft")> 

Module Example
    Sub Main()
        ' Get the Assembly type to access its metadata.
        Dim assy As Reflection.Assembly = GetType(Example).Assembly

        ' Iterate through all the attributes for the assembly.
        For Each attr As Attribute In Attribute.GetCustomAttributes(assy)
            ' Check for the AssemblyTitle attribute.
            If TypeOf attr Is AssemblyTitleAttribute Then
                ' Convert the attribute to access its data.
                Dim attrTitle As AssemblyTitleAttribute = _
                    CType(attr, AssemblyTitleAttribute)
                Console.WriteLine("Assembly title is ""{0}"".", _
                    attrTitle.Title)

            ' Check for the AssemblyDescription attribute.
            ElseIf TypeOf attr Is AssemblyDescriptionAttribute Then
                ' Convert the attribute to access its data.
                Dim attrDesc As AssemblyDescriptionAttribute = _
                    CType(attr, AssemblyDescriptionAttribute)
                Console.WriteLine("Assembly description is ""{0}"".", _
                    attrDesc.Description)

            ' Check for the AssemblyCompany attribute.
            ElseIf TypeOf attr Is AssemblyCompanyAttribute Then
                ' Convert the attribute to access its data.
                Dim attrComp As AssemblyCompanyAttribute = _
                    CType(attr, AssemblyCompanyAttribute)
                Console.WriteLine("Assembly company is {0}.", _
                    attrComp.Company)
            End If
        Next
    End Sub
End Module
' The example displays the following output:
'     Assembly company is Microsoft.
'     Assembly description is "GetCustomAttributes() Demo".
'     Assembly title is "CustAttrs1VB".

설명

참고

.NET Framework 버전 2.0부터 이 메서드는 특성이 새 메타데이터 형식으로 저장된 경우 보안 특성을 반환합니다. 버전 2.0 이상으로 컴파일된 어셈블리는 새 형식을 사용합니다. 이전 버전의 .NET Framework 컴파일된 동적 어셈블리 및 어셈블리는 이전 XML 형식을 사용합니다. 선언적 보안 특성 내보내기를 참조하세요.

적용 대상

GetCustomAttributes(ParameterInfo)

메서드 매개 변수에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 메서드 매개 변수를 지정합니다.

public:
 static cli::array <Attribute ^> ^ GetCustomAttributes(System::Reflection::ParameterInfo ^ element);
public static Attribute[] GetCustomAttributes (System.Reflection.ParameterInfo element);
static member GetCustomAttributes : System.Reflection.ParameterInfo -> Attribute[]
Public Shared Function GetCustomAttributes (element As ParameterInfo) As Attribute()

매개 변수

element
ParameterInfo

클래스의 멤버 매개 변수를 설명하는 ParameterInfo 클래스에서 파생된 개체입니다.

반환

element에 적용된 사용자 지정 특성이 포함된 Attribute 배열이며, 그러한 사용자 지정 특성이 없는 경우에는 빈 배열입니다.

예외

element이(가) null인 경우

사용자 지정 특성 형식을 로드할 수 없는 경우

예제

다음 코드 예제에서는 를 매개 변수로 사용하여 ParameterInfoGetCustomAttributes사용하는 방법을 보여 줍니다.

using namespace System;
using namespace System::Reflection;
using namespace System::ComponentModel;

namespace CustAttrs5CS
{
   public ref class AClass
   {
   public:
      void ParamArrayAndDesc(
         // Add ParamArray and Description attributes.
         [Description("This argument is a ParamArray")]
         array<Int32>^args )
      {}
   };

   ref class DemoClass
   {
   public:
      static void Main()
      {
         // Get the Class type to access its metadata.
         Type^ clsType = AClass::typeid;

         // Get the type information for the method.
         MethodInfo^ mInfo = clsType->GetMethod( "ParamArrayAndDesc" );
         if ( mInfo != nullptr )
         {
            // Get the parameter information.
            array<ParameterInfo^>^pInfo = mInfo->GetParameters();
            if ( pInfo != nullptr )
            {
               // Iterate through all the attributes for the parameter.
               System::Collections::IEnumerator^ myEnum4 = Attribute::GetCustomAttributes( pInfo[ 0 ] )->GetEnumerator();
               while ( myEnum4->MoveNext() )
               {
                  Attribute^ attr = safe_cast<Attribute^>(myEnum4->Current);

                  // Check for the ParamArray attribute.
                  if ( attr->GetType() == ParamArrayAttribute::typeid )
                                    Console::WriteLine( "Parameter {0} for method {1} "
                  "has the ParamArray attribute.", pInfo[ 0 ]->Name, mInfo->Name );
                  // Check for the Description attribute.
                  else

                  // Check for the Description attribute.
                  if ( attr->GetType() == DescriptionAttribute::typeid )
                  {
                     Console::WriteLine( "Parameter {0} for method {1} "
                     "has a description attribute.", pInfo[ 0 ]->Name, mInfo->Name );
                     Console::WriteLine( "The description is: \"{0}\"", (dynamic_cast<DescriptionAttribute^>(attr))->Description );
                  }
               }
            }
         }
      }
   };
}

/*
 * Output:
 * Parameter args for method ParamArrayAndDesc has the ParamArray attribute.
 * Parameter args for method ParamArrayAndDesc has a description attribute.
 * The description is: "This argument is a ParamArray"
 */
using System;
using System.Reflection;
using System.ComponentModel;

namespace CustAttrs5CS {
    public class AClass {
        public void ParamArrayAndDesc(
            // Add ParamArray (with the keyword) and Description attributes.
            [Description("This argument is a ParamArray")]
            params int[] args)
        {}
    }

    class DemoClass {
        static void Main(string[] args) {
            // Get the Class type to access its metadata.
            Type clsType = typeof(AClass);
            // Get the type information for the method.
            MethodInfo mInfo = clsType.GetMethod("ParamArrayAndDesc");
            if (mInfo != null) {
                // Get the parameter information.
                ParameterInfo[] pInfo = mInfo.GetParameters();
                if (pInfo != null) {
                    // Iterate through all the attributes for the parameter.
                    foreach(Attribute attr in
                        Attribute.GetCustomAttributes(pInfo[0])) {
                        // Check for the ParamArray attribute.
                        if (attr.GetType() == typeof(ParamArrayAttribute))
                            Console.WriteLine("Parameter {0} for method {1} " +
                                "has the ParamArray attribute.",
                                pInfo[0].Name, mInfo.Name);
                        // Check for the Description attribute.
                        else if (attr.GetType() ==
                            typeof(DescriptionAttribute)) {
                            Console.WriteLine("Parameter {0} for method {1} " +
                                "has a description attribute.",
                                pInfo[0].Name, mInfo.Name);
                            Console.WriteLine("The description is: \"{0}\"",
                                ((DescriptionAttribute)attr).Description);
                        }
                    }
                }
            }
        }
    }
}

/*
 * Output:
 * Parameter args for method ParamArrayAndDesc has the ParamArray attribute.
 * Parameter args for method ParamArrayAndDesc has a description attribute.
 * The description is: "This argument is a ParamArray"
 */
open System
open System.Reflection
open System.ComponentModel

type AClass() =
    member _.ParamArrayAndDesc(
        // Add ParamArray and Description attributes.
        [<Description "This argument is a ParamArray">]
        [<ParamArray>]
        args: int[]) = ()

// Get the Class type to access its metadata.
let clsType = typeof<AClass>

// Get the type information for the method.
let mInfo = clsType.GetMethod "ParamArrayAndDesc"
if mInfo <> null then
    // Get the parameter information.
    let pInfo = mInfo.GetParameters()
    if pInfo <> null then
        // Iterate through all the attributes for the parameter.
        for attr in Attribute.GetCustomAttributes pInfo[0] do
            match attr with 
            // Check for the ParamArray attribute.
            | :? ParamArrayAttribute ->
                printfn $"Parameter {pInfo[0].Name} for method {mInfo.Name} has the ParamArray attribute."
                                
            // Check for the Description attribute.
            | :? DescriptionAttribute as attr ->
                printfn $"Parameter {pInfo[0].Name} for method {mInfo.Name} has a description attribute."
                printfn $"The description is: \"{attr.Description}\""
            | _ -> ()

// Output:
// Parameter args for method ParamArrayAndDesc has a description attribute.
// The description is: "This argument is a ParamArray"
// Parameter args for method ParamArrayAndDesc has the ParamArray attribute.
Imports System.Reflection
Imports System.ComponentModel

Module DemoModule
    Public Class AClass
        ' Add Description and ParamArray (with the keyword) attributes.
        Public Sub ParamArrayAndDesc( _
            <Description("This argument is a ParamArray")> _
            ByVal ParamArray args() As Integer)
        End Sub
    End Class

    Sub Main()
        ' Get the Class type to access its metadata.
        Dim clsType As Type = GetType(AClass)
        ' Get the type information for the method.
        Dim mInfo As MethodInfo = clsType.GetMethod("ParamArrayAndDesc")
        ' Get the Parameter information for the method.
        Dim pInfo() As ParameterInfo = mInfo.GetParameters()
        Dim attr As Attribute
        ' Iterate through each attribute of the parameter.
        For Each attr In Attribute.GetCustomAttributes(pInfo(0))
            ' Check for the ParamArray attribute.
            If TypeOf attr Is ParamArrayAttribute Then
                ' Convert the attribute to access its data.
                Dim paAttr As ParamArrayAttribute = _
                    CType(attr, ParamArrayAttribute)
                Console.WriteLine("Parameter {0} for method {1} has the " + _
                    "ParamArray attribute.", pInfo(0).Name, mInfo.Name)
            ' Check for the Description attribute.
            ElseIf TypeOf attr Is DescriptionAttribute Then
                ' Convert the attribute to access its data.
                Dim descAttr As DescriptionAttribute = _
                    CType(attr, DescriptionAttribute)
                Console.WriteLine("Parameter {0} for method {1} has a description " + _
                    "attribute. The description is:", pInfo(0).Name, mInfo.Name)
                Console.WriteLine(descAttr.Description)
            End If
        Next
    End Sub
End Module

' Output:
' Parameter args for method ParamArrayAndDesc has the ParamArray attribute.
' Parameter args for method ParamArrayAndDesc has a description attribute. The description is:
' This argument is a ParamArray

설명

파생 형식의 메서드에서 매개 변수를 나타내는 경우 element 반환 값에는 재정의된 기본 메서드의 동일한 매개 변수에 적용된 상속 가능한 사용자 지정 특성이 포함됩니다.

적용 대상

GetCustomAttributes(Module)

모듈에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 모듈을 지정합니다.

public:
 static cli::array <Attribute ^> ^ GetCustomAttributes(System::Reflection::Module ^ element);
public static Attribute[] GetCustomAttributes (System.Reflection.Module element);
static member GetCustomAttributes : System.Reflection.Module -> Attribute[]
Public Shared Function GetCustomAttributes (element As Module) As Attribute()

매개 변수

element
Module

이식 가능한 실행 파일을 설명하는 Module 클래스에서 파생된 개체입니다.

반환

element에 적용된 사용자 지정 특성이 포함된 Attribute 배열이며, 그러한 사용자 지정 특성이 없는 경우에는 빈 배열입니다.

예외

element이(가) null인 경우

예제

다음 코드 예제에서는 를 매개 변수로 사용하여 ModuleGetCustomAttributes사용하는 방법을 보여 줍니다.

using namespace System;
using namespace System::Reflection;
using namespace System::ComponentModel;

// Assign some attributes to the module.
// Set the module's CLSCompliant attribute to false
// The CLSCompliant attribute is applicable for /target:module.
[module:Description("A sample description")];
[module:CLSCompliant(false)];
namespace CustAttrs2CS
{
   ref class DemoClass
   {
   public:
      static void Main()
      {
         Type^ clsType = DemoClass::typeid;

         // Get the Module type to access its metadata.
         Module^ module = clsType->Module;

         // Iterate through all the attributes for the module.
         System::Collections::IEnumerator^ myEnum1 = Attribute::GetCustomAttributes( module )->GetEnumerator();
         while ( myEnum1->MoveNext() )
         {
            Attribute^ attr = safe_cast<Attribute^>(myEnum1->Current);

            // Check for the Description attribute.
            if ( attr->GetType() == DescriptionAttribute::typeid )
                        Console::WriteLine( "Module {0} has the description \"{1}\".", module->Name, (dynamic_cast<DescriptionAttribute^>(attr))->Description );
            // Check for the CLSCompliant attribute.
            else

            // Check for the CLSCompliant attribute.
            if ( attr->GetType() == CLSCompliantAttribute::typeid )
                        Console::WriteLine( "Module {0} {1} CLSCompliant.", module->Name, (dynamic_cast<CLSCompliantAttribute^>(attr))->IsCompliant ? (String^)"is" : "is not" );
         }
      }
   };
}


/*
 * Output:
 * Module CustAttrs2CS.exe is not CLSCompliant.
 * Module CustAttrs2CS.exe has the description "A sample description".
 */
using System;
using System.Reflection;
using System.ComponentModel;

// Assign some attributes to the module.
[module:Description("A sample description")]

// Set the module's CLSCompliant attribute to false
// The CLSCompliant attribute is applicable for /target:module.
[module:CLSCompliant(false)]

namespace CustAttrs2CS {
    class DemoClass {
        static void Main(string[] args) {
            Type clsType = typeof(DemoClass);
            // Get the Module type to access its metadata.
            Module module = clsType.Module;

            // Iterate through all the attributes for the module.
            foreach(Attribute attr in Attribute.GetCustomAttributes(module)) {
                // Check for the Description attribute.
                if (attr.GetType() == typeof(DescriptionAttribute))
                    Console.WriteLine("Module {0} has the description " +
                        "\"{1}\".", module.Name,
                        ((DescriptionAttribute)attr).Description);
                // Check for the CLSCompliant attribute.
                else if (attr.GetType() == typeof(CLSCompliantAttribute))
                    Console.WriteLine("Module {0} {1} CLSCompliant.",
                        module.Name,
                        ((CLSCompliantAttribute)attr).IsCompliant ?
                            "is" : "is not");
            }
        }
    }
}

/*
 * Output:
 * Module CustAttrs2CS.exe is not CLSCompliant.
 * Module CustAttrs2CS.exe has the description "A sample description".
 */
open System
open System.ComponentModel

// Assign some attributes to the module.
[<``module``: Description "A sample description">]

// Set the module's CLSCompliant attribute to false
// The CLSCompliant attribute is applicable for /target:module.
[<``module``: CLSCompliant false>]
do ()

type DemoClass = class end

// Get the Module type to access its metadata.
let ilmodule = typeof<DemoClass>.Module

// Iterate through all the attributes for the module.
for attr in Attribute.GetCustomAttributes ilmodule do
    match attr with
    // Check for the Description attribute.
    | :? DescriptionAttribute as attr ->
        printfn $"Module {ilmodule.Name} has the description \"{attr.Description}\"."
                
    // Check for the CLSCompliant attribute.
    | :? CLSCompliantAttribute as attr ->
        printfn $"""Module {ilmodule.Name} {if attr.IsCompliant then "is" else "is not"} CLSCompliant."""
    | _ -> ()
    
// Output:
// Module CustAttrs2CS.exe is not CLSCompliant.
// Module CustAttrs2CS.exe has the description "A sample description".
Imports System.Reflection
Imports System.ComponentModel

' Give the Module some attributes.
<Module: Description("A sample description")> 

' Make the CLSCompliant attribute False.
' The CLSCompliant attribute is applicable for /target:module.
<Module: CLSCompliant(False)> 

Module DemoModule

    Sub Main()
        ' Get the Module type to access its metadata.
        Dim modType As Reflection.Module = GetType(DemoModule).Module
        Dim attr As Attribute
        ' Iterate through all the attributes for the module.
        For Each attr In Attribute.GetCustomAttributes(modType)
            ' Check for the Description attribute.
            If TypeOf attr Is DescriptionAttribute Then
                ' Convert the attribute to access its data.
                Dim descAttr As DescriptionAttribute = _
                    CType(attr, DescriptionAttribute)
                Console.WriteLine("Module {0} has the description ""{1}"".", _
                    modType.Name, descAttr.Description)

            ' Check for the CLSCompliant attribute.
            ElseIf TypeOf attr Is CLSCompliantAttribute Then
                ' Convert the attribute to access its data.
                Dim CLSCompAttr As CLSCompliantAttribute = _
                    CType(attr, CLSCompliantAttribute)
                Dim strCompliant As String
                If CLSCompAttr.IsCompliant Then
                    strCompliant = "is"
                Else
                    strCompliant = "is not"
                End If
                Console.WriteLine("Module {0} {1} CLSCompliant.", _
                    modType.Name, strCompliant)
            End If
        Next
    End Sub
End Module

' Output:
' Module CustAttrs2VB.exe has the description "A sample description".
' Module CustAttrs2VB.exe is not CLSCompliant.

적용 대상

GetCustomAttributes(MemberInfo)

형식 멤버에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수는 멤버를 지정합니다.

public:
 static cli::array <Attribute ^> ^ GetCustomAttributes(System::Reflection::MemberInfo ^ element);
public static Attribute[] GetCustomAttributes (System.Reflection.MemberInfo element);
static member GetCustomAttributes : System.Reflection.MemberInfo -> Attribute[]
Public Shared Function GetCustomAttributes (element As MemberInfo) As Attribute()

매개 변수

element
MemberInfo

클래스의 생성자, 이벤트, 필드, 메서드 또는 속성 멤버를 설명하는 MemberInfo 클래스에서 파생된 개체입니다.

반환

element에 적용된 사용자 지정 특성이 포함된 Attribute 배열이며, 그러한 사용자 지정 특성이 없는 경우에는 빈 배열입니다.

예외

element이(가) null인 경우

element가 생성자, 메서드, 속성, 이벤트, 형식 또는 필드가 아닌 경우

사용자 지정 특성 형식을 로드할 수 없는 경우

예제

다음 코드 예제에서는 를 매개 변수로 사용하여 MemberInfoGetCustomAttribute사용하는 방법을 보여 줍니다.

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

namespace CustAttrs4CS
{
   // Create a class for Win32 imported unmanaged functions.
   public ref class Win32
   {
   public:

      [DllImport("user32.dll", CharSet = CharSet::Unicode)]
      static int MessageBox( int hWnd, String^ text, String^ caption, UInt32 type );
   };

   public ref class AClass
   {
   public:

      // Add some attributes to the Win32CallMethod.

      [Obsolete("This method is obsolete. Use managed MsgBox instead.")]
      void Win32CallMethod()
      {
         Win32::MessageBox( 0, "This is an unmanaged call.", "Be Careful!", 0 );
      }

   };

   ref class DemoClass
   {
   public:
      static void Main()
      {
         // Get the Class type to access its metadata.
         Type^ clsType = AClass::typeid;

         // Get the type information for the Win32CallMethod.
         MethodInfo^ mInfo = clsType->GetMethod( "Win32CallMethod" );
         if ( mInfo != nullptr )
         {
            // Iterate through all the attributes for the method.
            System::Collections::IEnumerator^ myEnum3 = Attribute::GetCustomAttributes( mInfo )->GetEnumerator();
            while ( myEnum3->MoveNext() )
            {
               Attribute^ attr = safe_cast<Attribute^>(myEnum3->Current);

               // Check for the Obsolete attribute.
               if ( attr->GetType() == ObsoleteAttribute::typeid )
               {
                  Console::WriteLine( "Method {0} is obsolete. "
                  "The message is:", mInfo->Name );
                  Console::WriteLine( (dynamic_cast<ObsoleteAttribute^>(attr))->Message );
               }
               // Check for the SuppressUnmanagedCodeSecurity attribute.
               else

               // Check for the SuppressUnmanagedCodeSecurity attribute.
               if ( attr->GetType() == SuppressUnmanagedCodeSecurityAttribute::typeid )
               {
                  Console::WriteLine( "This method calls unmanaged code "
                  "with no security check." );
                  Console::WriteLine( "Please do not use unless absolutely necessary." );
                  AClass^ myCls = gcnew AClass;
                  myCls->Win32CallMethod();
               }
            }
         }
      }
   };
}


/*
 * Output:
 * Method Win32CallMethod is obsolete. The message is:
 * This method is obsolete. Use managed MsgBox instead.
 * This method calls unmanaged code with no security check.
 * Please do not use unless absolutely necessary.
 */
using System;
using System.Reflection;
using System.Security;
using System.Runtime.InteropServices;

namespace CustAttrs4CS
{

    // Define an enumeration of Win32 unmanaged types
    public enum UnmanagedType
    {
        User,
        GDI,
        Kernel,
        Shell,
        Networking,
        Multimedia
    }

    // Define the Unmanaged attribute.
    public class UnmanagedAttribute : Attribute
    {
        // Storage for the UnmanagedType value.
        protected UnmanagedType thisType;

        // Set the unmanaged type in the constructor.
        public UnmanagedAttribute(UnmanagedType type)
        {
            thisType = type;
        }

        // Define a property to get and set the UnmanagedType value.
        public UnmanagedType Win32Type
        {
            get { return thisType; }
            set { thisType = Win32Type; }
        }
    }

    // Create a class for an imported Win32 unmanaged function.
    public class Win32 {
        [DllImport("user32.dll", CharSet = CharSet.Unicode)]
        public static extern int MessageBox(int hWnd, String text,
            String caption, uint type);
    }

    public class AClass {
        // Add some attributes to Win32CallMethod.
        [Obsolete("This method is obsolete. Use managed MsgBox instead.")]
        [Unmanaged(UnmanagedType.User)]
        public void Win32CallMethod()
        {
            Win32.MessageBox(0, "This is an unmanaged call.", "Caution!", 0);
        }
    }

    class DemoClass {
        static void Main(string[] args)
            {
            // Get the AClass type to access its metadata.
            Type clsType = typeof(AClass);
            // Get the type information for Win32CallMethod.
            MethodInfo mInfo = clsType.GetMethod("Win32CallMethod");
            if (mInfo != null)
            {
                // Iterate through all the attributes of the method.
                foreach(Attribute attr in
                    Attribute.GetCustomAttributes(mInfo)) {
                    // Check for the Obsolete attribute.
                    if (attr.GetType() == typeof(ObsoleteAttribute))
                    {
                        Console.WriteLine("Method {0} is obsolete. " +
                            "The message is:",
                            mInfo.Name);
                        Console.WriteLine("  \"{0}\"",
                            ((ObsoleteAttribute)attr).Message);
                    }

                    // Check for the Unmanaged attribute.
                    else if (attr.GetType() == typeof(UnmanagedAttribute))
                    {
                        Console.WriteLine(
                            "This method calls unmanaged code.");
                        Console.WriteLine(
                            String.Format("The Unmanaged attribute type is {0}.",
                                          ((UnmanagedAttribute)attr).Win32Type));
                        AClass myCls = new AClass();
                        myCls.Win32CallMethod();
                    }
                }
            }
        }
    }
}

/*

This code example produces the following results.

First, the compilation yields the warning, "... This method is
obsolete. Use managed MsgBox instead."
Second, execution yields a message box with a title of "Caution!"
and message text of "This is an unmanaged call."
Third, the following text is displayed in the console window:

Method Win32CallMethod is obsolete. The message is:
  "This method is obsolete. Use managed MsgBox instead."
This method calls unmanaged code.
The Unmanaged attribute type is User.

*/
open System
open System.Runtime.InteropServices

// Define an enumeration of Win32 unmanaged types
type UnmanagedType =
    | User = 0
    | GDI = 1
    | Kernel = 2
    | Shell = 3
    | Networking = 4
    | Multimedia = 5

// Define the Unmanaged attribute.
type UnmanagedAttribute(unmanagedType) =
    inherit Attribute()
    
    // Define a property to get and set the UnmanagedType value.
    member val Win32Type = unmanagedType with get, set

// Create a module for an imported Win32 unmanaged function.
module Win32 =
    [<DllImport("user32.dll", CharSet = CharSet.Unicode)>]
    extern int MessageBox(IntPtr hWnd, String text, String caption, uint ``type``)

type AClass() =
    // Add some attributes to Win32CallMethod.
    [<Obsolete "This method is obsolete. Use managed MsgBox instead.">]
    [<Unmanaged(UnmanagedType.User)>]
    member _.Win32CallMethod () =
        Win32.MessageBox(0, "This is an unmanaged call.", "Caution!", 0u)

// Get the AClass type to access its metadata.
let clsType = typeof<AClass>
// Get the type information for Win32CallMethod.
let mInfo = clsType.GetMethod "Win32CallMethod"
if mInfo <> null then
    // Iterate through all the attributes of the method.
    for attr in Attribute.GetCustomAttributes mInfo do
        match attr with 
        // Check for the Obsolete attribute.
        | :? ObsoleteAttribute as attr ->
            printfn $"Method {mInfo.Name} is obsolete. The message is:"
            printfn $"  \"{attr.Message}\""

        // Check for the Unmanaged attribute.
        | :? UnmanagedAttribute as attr ->
            printfn "This method calls unmanaged code."
            printfn $"The Unmanaged attribute type is {attr.Win32Type}."
            let myCls = AClass()
            myCls.Win32CallMethod() |> ignore
        | _ -> ()

// This code example produces the following results.
//
// First, the compilation yields the warning, "... This method is
// obsolete. Use managed MsgBox instead."
// Second, execution yields a message box with a title of "Caution!"
// and message text of "This is an unmanaged call."
// Third, the following text is displayed in the console window:

// Method Win32CallMethod is obsolete. The message is:
//   "This method is obsolete. Use managed MsgBox instead."
// This method calls unmanaged code.
// The Unmanaged attribute type is User.
Imports System.Reflection
Imports System.Security
Imports System.Runtime.InteropServices

' Define an enumeration of Win32 unmanaged types
Public Enum UnmanagedType
    User
    GDI
    Kernel
    Shell
    Networking
    Multimedia
End Enum 'UnmanagedType

' Define the Unmanaged attribute.
Public Class UnmanagedAttribute 
             Inherits Attribute

    ' Storage for the UnmanagedType value.
    Protected thisType As UnmanagedType
    
    ' Set the unmanaged type in the constructor.
    Public Sub New(ByVal type As UnmanagedType) 
        thisType = type
    End Sub
    
    ' Define a property to get and set the UnmanagedType value.
    Public Property Win32Type() As UnmanagedType 
        Get
            Return thisType
        End Get
        Set
            thisType = Win32Type
        End Set
    End Property
End Class

' Create a class for an imported Win32 unmanaged function.
Public Class Win32
    <DllImport("user32.dll", CharSet:=CharSet.Unicode)> _
    Public Shared Function MessageBox(ByVal hWnd As Integer, _
                                      ByVal Text As String, _
                                      ByVal caption As String, _
                                      ByVal type As Integer) As Integer
    End Function 'MessageBox
End Class

Public Class AClass
    ' Add some attributes to Win32CallMethod.
    <Obsolete("This method is obsolete. Use managed MsgBox instead."), _
     Unmanaged(UnmanagedType.User)>  _
    Public Sub Win32CallMethod() 
        Win32.MessageBox(0, "This is an unmanaged call.", "Caution!", 0)    
    End Sub
End Class

Class DemoClass
    Shared Sub Main(ByVal args() As String) 
        ' Get the AClass type to access its metadata.
        Dim clsType As Type = GetType(AClass)
        ' Get the type information for Win32CallMethod.
        Dim mInfo As MethodInfo = clsType.GetMethod("Win32CallMethod")
        If Not (mInfo Is Nothing) Then
            ' Iterate through all the attributes of the method.
            Dim attr As Attribute
            For Each attr In  Attribute.GetCustomAttributes(mInfo)
                ' Check for the Obsolete attribute.
                If attr.GetType().Equals(GetType(ObsoleteAttribute)) Then
                    Console.WriteLine("Method {0} is obsolete. The message is:", mInfo.Name)
                    Console.WriteLine("  ""{0}""", CType(attr, ObsoleteAttribute).Message)
                ' Check for the Unmanaged attribute.
                ElseIf attr.GetType().Equals(GetType(UnmanagedAttribute)) Then
                    Console.WriteLine("This method calls unmanaged code.")
                    Console.WriteLine( _
                            String.Format("The Unmanaged attribute type is {0}.", _
                            CType(attr, UnmanagedAttribute).Win32Type))
                    Dim myCls As New AClass()
                    myCls.Win32CallMethod()
                End If
            Next attr
        End If
    End Sub
End Class

'
'This code example produces the following results. 
'
'First, the compilation yields the warning, "... This method is 
'obsolete. Use managed MsgBox instead."
'Second, execution yields a message box with a title of "Caution!" 
'and message text of "This is an unmanaged call." 
'Third, the following text is displayed in the console window:
'
'Method Win32CallMethod is obsolete. The message is:
'  "This method is obsolete. Use managed MsgBox instead."
'This method calls unmanaged code.
'The Unmanaged attribute type is User.
'

설명

반환 값에는 의 element상위 항목에 대한 사용자 지정 특성이 포함됩니다.

참고

.NET Framework 버전 2.0부터 이 메서드는 특성이 새 메타데이터 형식으로 저장되는 경우 메서드, 생성자 및 형식에 대한 보안 특성을 반환합니다. 버전 2.0 이상으로 컴파일된 어셈블리는 새 형식을 사용합니다. 이전 버전의 .NET Framework 컴파일된 동적 어셈블리 및 어셈블리는 이전 XML 형식을 사용합니다. 선언적 보안 특성 내보내기를 참조하세요.

적용 대상

GetCustomAttributes(Assembly)

어셈블리에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수로 어셈블리를 지정합니다.

public:
 static cli::array <Attribute ^> ^ GetCustomAttributes(System::Reflection::Assembly ^ element);
public static Attribute[] GetCustomAttributes (System.Reflection.Assembly element);
static member GetCustomAttributes : System.Reflection.Assembly -> Attribute[]
Public Shared Function GetCustomAttributes (element As Assembly) As Attribute()

매개 변수

element
Assembly

Assembly 클래스에서 파생된 개체로, 모듈의 재사용 가능한 컬렉션을 설명합니다.

반환

element에 적용된 사용자 지정 특성이 포함된 Attribute 배열이며, 그러한 사용자 지정 특성이 없는 경우에는 빈 배열입니다.

예외

element이(가) null인 경우

예제

다음 예제에서는 현재 어셈블리에 있는 사용자 지정 특성을 검색합니다.

using namespace System;
using namespace System::Reflection;

[assembly:AssemblyTitle("CustAttrs1CPP")];
[assembly:AssemblyDescription("GetCustomAttributes() Demo")];
[assembly:AssemblyCompany("Microsoft")];

ref class Example
{};

static void main()
{
    Type^ clsType = Example::typeid;

    // Get the Assembly type to access its metadata.
    Assembly^ assy = clsType->Assembly;

    // Iterate through the attributes for the assembly.
    System::Collections::IEnumerator^ myEnum = Attribute::GetCustomAttributes( assy )->GetEnumerator();
    while ( myEnum->MoveNext() )
    {
       Attribute^ attr = safe_cast<Attribute^>(myEnum->Current);

       // Check for the AssemblyTitle attribute.
       if ( attr->GetType() == AssemblyTitleAttribute::typeid )
          Console::WriteLine( "Assembly title is \"{0}\".", (dynamic_cast<AssemblyTitleAttribute^>(attr))->Title );
          // Check for the AssemblyDescription attribute.
       else
          // Check for the AssemblyDescription attribute.
          if ( attr->GetType() == AssemblyDescriptionAttribute::typeid )
             Console::WriteLine( "Assembly description is \"{0}\".", (dynamic_cast<AssemblyDescriptionAttribute^>(attr))->Description );
          // Check for the AssemblyCompany attribute.
          else if ( attr->GetType() == AssemblyCompanyAttribute::typeid )
             Console::WriteLine( "Assembly company is {0}.", (dynamic_cast<AssemblyCompanyAttribute^>(attr))->Company );
    }
}
// The example displays the following output:
//     Assembly description is "GetCustomAttributes() Demo".
//     Assembly company is Microsoft.
//     Assembly title is "CustAttrs1CPP".
using System;
using System.Reflection;

[assembly: AssemblyTitle("CustAttrs1CS")]
[assembly: AssemblyDescription("GetCustomAttributes() Demo")]
[assembly: AssemblyCompany("Microsoft")]

class Example {
    static void Main() {
        // Get the Assembly object to access its metadata.
        Assembly assy = typeof(Example).Assembly;

        // Iterate through the attributes for the assembly.
        foreach(Attribute attr in Attribute.GetCustomAttributes(assy)) {
            // Check for the AssemblyTitle attribute.
            if (attr.GetType() == typeof(AssemblyTitleAttribute))
                Console.WriteLine("Assembly title is \"{0}\".",
                    ((AssemblyTitleAttribute)attr).Title);

            // Check for the AssemblyDescription attribute.
            else if (attr.GetType() ==
                typeof(AssemblyDescriptionAttribute))
                Console.WriteLine("Assembly description is \"{0}\".",
                    ((AssemblyDescriptionAttribute)attr).Description);

            // Check for the AssemblyCompany attribute.
            else if (attr.GetType() == typeof(AssemblyCompanyAttribute))
                Console.WriteLine("Assembly company is {0}.",
                    ((AssemblyCompanyAttribute)attr).Company);
        }
   }
}
// The example displays the following output:
//     Assembly title is "CustAttrs1CS".
//     Assembly description is "GetCustomAttributes() Demo".
//     Assembly company is Microsoft.
open System
open System.Reflection

[<assembly: AssemblyTitle "CustAttrs1CS">]
[<assembly: AssemblyDescription "GetCustomAttributes() Demo">]
[<assembly: AssemblyCompany"Microsoft">]
do ()

type Example = class end

// Get the Assembly object to access its metadata.
let assembly = typeof<Example>.Assembly

// Iterate through the attributes for the assembly.
for attr in Attribute.GetCustomAttributes assembly do
    match attr with
    // Check for the AssemblyTitle attribute.
    | :? AssemblyTitleAttribute as attr ->    
        printfn $"Assembly title is \"{attr.Title}\"."
    // Check for the AssemblyDescription attribute.
    | :? AssemblyDescriptionAttribute as attr ->
        printfn $"Assembly description is \"{attr.Description}\"."
    // Check for the AssemblyCompany attribute.
    | :? AssemblyCompanyAttribute as attr ->
        printfn $"Assembly company is {attr.Company}."
    | _ -> ()
    
// The example displays the following output:
//     Assembly title is "CustAttrs1CS".
//     Assembly description is "GetCustomAttributes() Demo".
//     Assembly company is Microsoft.
Imports System.Reflection

<Assembly: AssemblyTitle("CustAttrs1VB")> 
<Assembly: AssemblyDescription("GetCustomAttributes() Demo")> 
<Assembly: AssemblyCompany("Microsoft")> 

Module Example
    Sub Main()
        ' Get the Assembly type to access its metadata.
        Dim assy As Reflection.Assembly = GetType(Example).Assembly

        ' Iterate through all the attributes for the assembly.
        For Each attr As Attribute In Attribute.GetCustomAttributes(assy)
            ' Check for the AssemblyTitle attribute.
            If TypeOf attr Is AssemblyTitleAttribute Then
                ' Convert the attribute to access its data.
                Dim attrTitle As AssemblyTitleAttribute = _
                    CType(attr, AssemblyTitleAttribute)
                Console.WriteLine("Assembly title is ""{0}"".", _
                    attrTitle.Title)

            ' Check for the AssemblyDescription attribute.
            ElseIf TypeOf attr Is AssemblyDescriptionAttribute Then
                ' Convert the attribute to access its data.
                Dim attrDesc As AssemblyDescriptionAttribute = _
                    CType(attr, AssemblyDescriptionAttribute)
                Console.WriteLine("Assembly description is ""{0}"".", _
                    attrDesc.Description)

            ' Check for the AssemblyCompany attribute.
            ElseIf TypeOf attr Is AssemblyCompanyAttribute Then
                ' Convert the attribute to access its data.
                Dim attrComp As AssemblyCompanyAttribute = _
                    CType(attr, AssemblyCompanyAttribute)
                Console.WriteLine("Assembly company is {0}.", _
                    attrComp.Company)
            End If
        Next
    End Sub
End Module
' The example displays the following output:
'     Assembly company is Microsoft.
'     Assembly description is "GetCustomAttributes() Demo".
'     Assembly title is "CustAttrs1VB".

설명

참고

.NET Framework 버전 2.0부터 이 메서드는 특성이 새 메타데이터 형식으로 저장된 경우 보안 특성을 반환합니다. 버전 2.0 이상으로 컴파일된 어셈블리는 새 형식을 사용합니다. 이전 버전의 .NET Framework 컴파일된 동적 어셈블리 및 어셈블리는 이전 XML 형식을 사용합니다. 선언적 보안 특성 내보내기를 참조하세요.

적용 대상

GetCustomAttributes(Module, Boolean)

모듈에 적용된 사용자 지정 특성의 배열을 검색합니다. 매개 변수에는 모듈과 무시된 검색 옵션을 지정합니다.

public:
 static cli::array <Attribute ^> ^ GetCustomAttributes(System::Reflection::Module ^ element, bool inherit);
public static Attribute[] GetCustomAttributes (System.Reflection.Module element, bool inherit);
static member GetCustomAttributes : System.Reflection.Module * bool -> Attribute[]
Public Shared Function GetCustomAttributes (element As Module, inherit As Boolean) As Attribute()

매개 변수

element
Module

이식 가능한 실행 파일을 설명하는 Module 클래스에서 파생된 개체입니다.

inherit
Boolean

이 매개 변수는 무시되며 이 메서드의 작업에 영향을 끼치지 않습니다.

반환

element에 적용된 사용자 지정 특성이 포함된 Attribute 배열이며, 그러한 사용자 지정 특성이 없는 경우에는 빈 배열입니다.

예외

element 또는 attributeTypenull인 경우

예제

다음 코드 예제에서는 를 매개 변수로 사용하여 ModuleGetCustomAttributes사용하는 방법을 보여 줍니다.

using namespace System;
using namespace System::Reflection;
using namespace System::ComponentModel;

// Assign some attributes to the module.
// Set the module's CLSCompliant attribute to false
// The CLSCompliant attribute is applicable for /target:module.
[module:Description("A sample description")];
[module:CLSCompliant(false)];
namespace CustAttrs2CS
{
   ref class DemoClass
   {
   public:
      static void Main()
      {
         Type^ clsType = DemoClass::typeid;

         // Get the Module type to access its metadata.
         Module^ module = clsType->Module;

         // Iterate through all the attributes for the module.
         System::Collections::IEnumerator^ myEnum1 = Attribute::GetCustomAttributes( module )->GetEnumerator();
         while ( myEnum1->MoveNext() )
         {
            Attribute^ attr = safe_cast<Attribute^>(myEnum1->Current);

            // Check for the Description attribute.
            if ( attr->GetType() == DescriptionAttribute::typeid )
                        Console::WriteLine( "Module {0} has the description \"{1}\".", module->Name, (dynamic_cast<DescriptionAttribute^>(attr))->Description );
            // Check for the CLSCompliant attribute.
            else

            // Check for the CLSCompliant attribute.
            if ( attr->GetType() == CLSCompliantAttribute::typeid )
                        Console::WriteLine( "Module {0} {1} CLSCompliant.", module->Name, (dynamic_cast<CLSCompliantAttribute^>(attr))->IsCompliant ? (String^)"is" : "is not" );
         }
      }
   };
}


/*
 * Output:
 * Module CustAttrs2CS.exe is not CLSCompliant.
 * Module CustAttrs2CS.exe has the description "A sample description".
 */
using System;
using System.Reflection;
using System.ComponentModel;

// Assign some attributes to the module.
[module:Description("A sample description")]

// Set the module's CLSCompliant attribute to false
// The CLSCompliant attribute is applicable for /target:module.
[module:CLSCompliant(false)]

namespace CustAttrs2CS {
    class DemoClass {
        static void Main(string[] args) {
            Type clsType = typeof(DemoClass);
            // Get the Module type to access its metadata.
            Module module = clsType.Module;

            // Iterate through all the attributes for the module.
            foreach(Attribute attr in Attribute.GetCustomAttributes(module)) {
                // Check for the Description attribute.
                if (attr.GetType() == typeof(DescriptionAttribute))
                    Console.WriteLine("Module {0} has the description " +
                        "\"{1}\".", module.Name,
                        ((DescriptionAttribute)attr).Description);
                // Check for the CLSCompliant attribute.
                else if (attr.GetType() == typeof(CLSCompliantAttribute))
                    Console.WriteLine("Module {0} {1} CLSCompliant.",
                        module.Name,
                        ((CLSCompliantAttribute)attr).IsCompliant ?
                            "is" : "is not");
            }
        }
    }
}

/*
 * Output:
 * Module CustAttrs2CS.exe is not CLSCompliant.
 * Module CustAttrs2CS.exe has the description "A sample description".
 */
open System
open System.ComponentModel

// Assign some attributes to the module.
[<``module``: Description "A sample description">]

// Set the module's CLSCompliant attribute to false
// The CLSCompliant attribute is applicable for /target:module.
[<``module``: CLSCompliant false>]
do ()

type DemoClass = class end

// Get the Module type to access its metadata.
let ilmodule = typeof<DemoClass>.Module

// Iterate through all the attributes for the module.
for attr in Attribute.GetCustomAttributes ilmodule do
    match attr with
    // Check for the Description attribute.
    | :? DescriptionAttribute as attr ->
        printfn $"Module {ilmodule.Name} has the description \"{attr.Description}\"."
                
    // Check for the CLSCompliant attribute.
    | :? CLSCompliantAttribute as attr ->
        printfn $"""Module {ilmodule.Name} {if attr.IsCompliant then "is" else "is not"} CLSCompliant."""
    | _ -> ()
    
// Output:
// Module CustAttrs2CS.exe is not CLSCompliant.
// Module CustAttrs2CS.exe has the description "A sample description".
Imports System.Reflection
Imports System.ComponentModel

' Give the Module some attributes.
<Module: Description("A sample description")> 

' Make the CLSCompliant attribute False.
' The CLSCompliant attribute is applicable for /target:module.
<Module: CLSCompliant(False)> 

Module DemoModule

    Sub Main()
        ' Get the Module type to access its metadata.
        Dim modType As Reflection.Module = GetType(DemoModule).Module
        Dim attr As Attribute
        ' Iterate through all the attributes for the module.
        For Each attr In Attribute.GetCustomAttributes(modType)
            ' Check for the Description attribute.
            If TypeOf attr Is DescriptionAttribute Then
                ' Convert the attribute to access its data.
                Dim descAttr As DescriptionAttribute = _
                    CType(attr, DescriptionAttribute)
                Console.WriteLine("Module {0} has the description ""{1}"".", _
                    modType.Name, descAttr.Description)

            ' Check for the CLSCompliant attribute.
            ElseIf TypeOf attr Is CLSCompliantAttribute Then
                ' Convert the attribute to access its data.
                Dim CLSCompAttr As CLSCompliantAttribute = _
                    CType(attr, CLSCompliantAttribute)
                Dim strCompliant As String
                If CLSCompAttr.IsCompliant Then
                    strCompliant = "is"
                Else
                    strCompliant = "is not"
                End If
                Console.WriteLine("Module {0} {1} CLSCompliant.", _
                    modType.Name, strCompliant)
            End If
        Next
    End Sub
End Module

' Output:
' Module CustAttrs2VB.exe has the description "A sample description".
' Module CustAttrs2VB.exe is not CLSCompliant.

설명

반환 값에는 이 인 경우 inheritelement 상위 항목에 대한 사용자 지정 특성이 포함됩니다true.

적용 대상