CustomAttributeData CustomAttributeData CustomAttributeData CustomAttributeData Class

정의

리플렉션 전용 컨텍스트에 로드되는 어셈블리, 모듈, 형식, 멤버 및 매개 변수에 대한 사용자 지정 특성 데이터에 액세스할 수 있도록 해줍니다. Provides access to custom attribute data for assemblies, modules, types, members and parameters that are loaded into the reflection-only context.

public ref class CustomAttributeData
[System.Runtime.InteropServices.ComVisible(true)]
[Serializable]
public class CustomAttributeData
type CustomAttributeData = class
Public Class CustomAttributeData
상속
CustomAttributeDataCustomAttributeDataCustomAttributeDataCustomAttributeData
특성
ComVisibleAttribute SerializableAttribute

예제

다음 예제에서는 네 가지 생성자와 속성을 사용 하 여 사용자 지정 특성을 정의합니다.The following example defines a custom attribute with four constructors and four properties. 두 속성은 읽기 전용 및 생성자의 위치 매개 변수를 사용 하 여 설정 됩니다.Two of the properties are read-only, and are set by using the positional parameters of the constructors. 다른 두 속성은 읽기/쓰기가 가능 하 고 명명 된 인수를 사용 해야만 설정할 수 있습니다.The other two properties are read/write, and can be set only by using named arguments. 하나의 위치 속성은 문자열의 배열 및 하나의 명명 된 속성은 정수의 배열입니다.One positional property is an array of strings, and one named property is an array of integers.

어셈블리, 어셈블리에 선언된 형식, 형식의 메서드, 메서드의 매개 변수에 특성이 적용됩니다.The attribute is applied to the assembly, to a type declared in the assembly, to a method of the type, and to a parameter of the method. 다른 생성자는 이러한 경우에 사용 됩니다.Different constructors are used for these cases. 를 실행 하면 어셈블리를 리플렉션 전용 컨텍스트에 자동으로 로드 하 고 형식 및 포함 된 멤버에 적용 된 사용자 지정 특성에 대 한 정보를 표시 합니다.When executed, the assembly loads itself into the reflection-only context and displays information about the custom attributes that were applied to it and to the type and members it contains.

형식에 적용 되는 특성 위치 인수와 명명 된 인수를 사용 하 여 배열 속성을 보여 줍니다.The attribute that is applied to the type demonstrates array properties, with both positional and named arguments.

using namespace System;
using namespace System::Reflection;
using namespace System::Collections::Generic;
using namespace System::Collections::ObjectModel;

// An enumeration used by the ExampleAttribute class.
public enum class ExampleKind
{
   FirstKind, SecondKind, ThirdKind, FourthKind
};

// An example attribute. The attribute can be applied to all
// targets, from assemblies to parameters.
//
[AttributeUsage(AttributeTargets::All)]
public ref class ExampleAttribute: public Attribute
{
private:
   // Data for properties.
   ExampleKind kindValue;
   String^ noteValue;
   array<String^>^ arrayStrings;
   array<int>^ arrayNumbers;

   // Constructors. 
   void ExampleAttributeInitialize( ExampleKind initKind, array<String^>^ initStrings )
   {
      kindValue = initKind;
      arrayStrings = initStrings;
   }
public:
   ExampleAttribute()
   {
      ExampleAttributeInitialize( ExampleKind::FirstKind, nullptr );
   }
   ExampleAttribute( ExampleKind initKind )
   {
      ExampleAttributeInitialize( initKind, nullptr );
   }
   ExampleAttribute( ExampleKind initKind, array<String^>^ initStrings )
   {
      ExampleAttributeInitialize( initKind, initStrings );
   }

   // Properties. The Note and Numbers properties must be read/write, so they
   // can be used as named parameters.
   //
   property ExampleKind Kind 
   {
      ExampleKind get()
      {
         return kindValue;
      }
   }
   property array<String^>^ Strings
   {
      array<String^>^ get()
      {
         return arrayStrings;
      }
   }
   property String^ Note 
   {
      String^ get()
      {
         return noteValue;
      }

      void set( String^ value )
      {
         noteValue = value;
      }
   }
   property array<int>^ Numbers
   {
      array<int>^ get()
      {
         return arrayNumbers;
      }

      void set( array<int>^ value )
      {
         arrayNumbers = value;
      }
   }
};

// The example attribute is applied to the assembly.
[assembly:Example(ExampleKind::ThirdKind,Note="This is a note on the assembly.")];

// The example attribute is applied to the test class.
//
[Example(ExampleKind::SecondKind, 
         gcnew array<String^> { "String array argument, line 1", 
                        "String array argument, line 2", 
                        "String array argument, line 3" }, 
         Note="This is a note on the class.",
         Numbers = gcnew array<int> { 53, 57, 59 })] 
public ref class Test
{
public:
   // The example attribute is applied to a method, using the
   // parameterless constructor and supplying a named argument.
   // The attribute is also applied to the method parameter.
   //
   [Example(Note="This is a note on a method.")]
   void TestMethod( [Example] Object^ arg ){}

   // Main() gets objects representing the assembly, the test
   // type, the test method, and the method parameter. Custom
   // attribute data is displayed for each of these.
   //
   static void Main()
   {
      Assembly^ assembly = Assembly::ReflectionOnlyLoad( "Source" );
      Type^ t = assembly->GetType( "Test" );
      MethodInfo^ m = t->GetMethod( "TestMethod" );
      array<ParameterInfo^>^p = m->GetParameters();

      Console::WriteLine( "\r\nAttributes for assembly: '{0}'", assembly );
      ShowAttributeData( CustomAttributeData::GetCustomAttributes( assembly ) );
      Console::WriteLine( "\r\nAttributes for type: '{0}'", t );
      ShowAttributeData( CustomAttributeData::GetCustomAttributes( t ) );
      Console::WriteLine( "\r\nAttributes for member: '{0}'", m );
      ShowAttributeData( CustomAttributeData::GetCustomAttributes( m ) );
      Console::WriteLine( "\r\nAttributes for parameter: '{0}'", p );
      ShowAttributeData( CustomAttributeData::GetCustomAttributes( p[ 0 ] ) );
   }

private:
    static void ShowValueOrArray(CustomAttributeTypedArgument^ cata)
    {
        if (cata->Value->GetType() == ReadOnlyCollection<CustomAttributeTypedArgument>::typeid)
        {
            Console::WriteLine("         Array of '{0}':", cata->ArgumentType);

            for each (CustomAttributeTypedArgument^ cataElement in 
                (ReadOnlyCollection<CustomAttributeTypedArgument>^) cata->Value)
            {
                Console::WriteLine("             Type: '{0}'  Value: '{1}'",
                    cataElement->ArgumentType, cataElement->Value);
            }
        }
        else
        {
            Console::WriteLine( "         Type: '{0}'  Value: '{1}'",
               cata->ArgumentType, cata->Value );
        }
    }

   static void ShowAttributeData( IList< CustomAttributeData^ >^ attributes )
   {
      for each ( CustomAttributeData^ cad in attributes )
      {
         Console::WriteLine( "   {0}", cad );
         Console::WriteLine( "      Constructor: '{0}'", cad->Constructor );

         Console::WriteLine( "      Constructor arguments:" );
         for each ( CustomAttributeTypedArgument^ cata in cad->ConstructorArguments )
         {
            ShowValueOrArray(cata);
         }

         Console::WriteLine( "      Named arguments:" );
         for each ( CustomAttributeNamedArgument cana in cad->NamedArguments )
         {
            Console::WriteLine( "         MemberInfo: '{0}'", cana.MemberInfo );
            ShowValueOrArray(cana.TypedValue);
         }
      }
   }
};

int main()
{
   Test::Main();
}

/* This code example produces output similar to the following:

Attributes for assembly: 'source, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
   [System.Runtime.CompilerServices.CompilationRelaxationsAttribute((Int32)8)]
      Constructor: 'Void .ctor(Int32)'
      Constructor arguments:
         Type: 'System.Int32'  Value: '8'
      Named arguments:
   [System.Runtime.CompilerServices.RuntimeCompatibilityAttribute(WrapNonExceptionThrows = True)]
      Constructor: 'Void .ctor()'
      Constructor arguments:
      Named arguments:
         MemberInfo: 'Boolean WrapNonExceptionThrows'
         Type: 'System.Boolean'  Value: 'True'
   [ExampleAttribute((ExampleKind)2, Note = "This is a note on the assembly.")]
      Constructor: 'Void .ctor(ExampleKind)'
      Constructor arguments:
         Type: 'ExampleKind'  Value: '2'
      Named arguments:
         MemberInfo: 'System.String Note'
         Type: 'System.String'  Value: 'This is a note on the assembly.'

Attributes for type: 'Test'
   [ExampleAttribute((ExampleKind)1, new String[3] { "String array argument, line 1", "String array argument, line 2", "String array argument, line 3" }, Note = "This is a note on the class.", Numbers = new Int32[3] { 53, 57, 59 })]
      Constructor: 'Void .ctor(ExampleKind, System.String[])'
      Constructor arguments:
         Type: 'ExampleKind'  Value: '1'
         Array of 'System.String[]':
             Type: 'System.String'  Value: 'String array argument, line 1'
             Type: 'System.String'  Value: 'String array argument, line 2'
             Type: 'System.String'  Value: 'String array argument, line 3'
      Named arguments:
         MemberInfo: 'System.String Note'
         Type: 'System.String'  Value: 'This is a note on the class.'
         MemberInfo: 'Int32[] Numbers'
         Array of 'System.Int32[]':
             Type: 'System.Int32'  Value: '53'
             Type: 'System.Int32'  Value: '57'
             Type: 'System.Int32'  Value: '59'

Attributes for member: 'Void TestMethod(System.Object)'
   [ExampleAttribute(Note = "This is a note on a method.")]
      Constructor: 'Void .ctor()'
      Constructor arguments:
      Named arguments:
         MemberInfo: 'System.String Note'
         Type: 'System.String'  Value: 'This is a note on a method.'

Attributes for parameter: 'System.Object arg'
   [ExampleAttribute()]
      Constructor: 'Void .ctor()'
      Constructor arguments:
      Named arguments:
*/
using System;
using System.Reflection;
using System.Collections.Generic;
using System.Collections.ObjectModel;

// The example attribute is applied to the assembly.
[assembly:Example(ExampleKind.ThirdKind, Note="This is a note on the assembly.")]

// An enumeration used by the ExampleAttribute class.
public enum ExampleKind
{
    FirstKind, 
    SecondKind, 
    ThirdKind, 
    FourthKind
};

// An example attribute. The attribute can be applied to all
// targets, from assemblies to parameters.
//
[AttributeUsage(AttributeTargets.All)]
public class ExampleAttribute : Attribute
{
    // Data for properties.
    private ExampleKind kindValue;
    private string noteValue;
    private string[] arrayStrings;
    private int[] arrayNumbers;

    // Constructors. The parameterless constructor (.ctor) calls
    // the constructor that specifies ExampleKind and an array of 
    // strings, and supplies the default values.
    //
    public ExampleAttribute(ExampleKind initKind, string[] initStrings)
    {
        kindValue = initKind;
        arrayStrings = initStrings;
    }
    public ExampleAttribute(ExampleKind initKind) : this(initKind, null) {}
    public ExampleAttribute() : this(ExampleKind.FirstKind, null) {}

    // Properties. The Note and Numbers properties must be read/write, so they
    // can be used as named parameters.
    //
    public ExampleKind Kind { get { return kindValue; }}
    public string[] Strings { get { return arrayStrings; }}
    public string Note    
    {
        get { return noteValue; }
        set { noteValue = value; }
    }
    public int[] Numbers
    {
        get { return arrayNumbers; }
        set { arrayNumbers = value; }
    }
}

// The example attribute is applied to the test class.
//
[Example(ExampleKind.SecondKind, 
         new string[] { "String array argument, line 1", 
                        "String array argument, line 2", 
                        "String array argument, line 3" }, 
         Note="This is a note on the class.",
         Numbers = new int[] { 53, 57, 59 })] 
public class Test
{
    // The example attribute is applied to a method, using the
    // parameterless constructor and supplying a named argument.
    // The attribute is also applied to the method parameter.
    //
    [Example(Note="This is a note on a method.")]
    public void TestMethod([Example] object arg) { }

    // Main() gets objects representing the assembly, the test
    // type, the test method, and the method parameter. Custom
    // attribute data is displayed for each of these.
    //
    public static void Main()
    {
        Assembly asm = Assembly.ReflectionOnlyLoad("Source");
        Type t = asm.GetType("Test");
        MethodInfo m = t.GetMethod("TestMethod");
        ParameterInfo[] p = m.GetParameters();

        Console.WriteLine("\r\nAttributes for assembly: '{0}'", asm);
        ShowAttributeData(CustomAttributeData.GetCustomAttributes(asm));
        Console.WriteLine("\r\nAttributes for type: '{0}'", t);
        ShowAttributeData(CustomAttributeData.GetCustomAttributes(t));
        Console.WriteLine("\r\nAttributes for member: '{0}'", m);
        ShowAttributeData(CustomAttributeData.GetCustomAttributes(m));
        Console.WriteLine("\r\nAttributes for parameter: '{0}'", p);
        ShowAttributeData(CustomAttributeData.GetCustomAttributes(p[0]));
    }

    private static void ShowAttributeData(
        IList<CustomAttributeData> attributes)
    {
        foreach( CustomAttributeData cad in attributes )
        {
            Console.WriteLine("   {0}", cad);
            Console.WriteLine("      Constructor: '{0}'", cad.Constructor);

            Console.WriteLine("      Constructor arguments:");
            foreach( CustomAttributeTypedArgument cata 
                in cad.ConstructorArguments )
            {
                ShowValueOrArray(cata);
            }

            Console.WriteLine("      Named arguments:");
            foreach( CustomAttributeNamedArgument cana 
                in cad.NamedArguments )
            {
                Console.WriteLine("         MemberInfo: '{0}'", 
                    cana.MemberInfo);
                ShowValueOrArray(cana.TypedValue);
            }
        }
    }

    private static void ShowValueOrArray(CustomAttributeTypedArgument cata)
    {
        if (cata.Value.GetType() == typeof(ReadOnlyCollection<CustomAttributeTypedArgument>))
        {
            Console.WriteLine("         Array of '{0}':", cata.ArgumentType);

            foreach (CustomAttributeTypedArgument cataElement in 
                (ReadOnlyCollection<CustomAttributeTypedArgument>) cata.Value)
            {
                Console.WriteLine("             Type: '{0}'  Value: '{1}'",
                    cataElement.ArgumentType, cataElement.Value);
            }
        }
        else
        {
            Console.WriteLine("         Type: '{0}'  Value: '{1}'", 
                cata.ArgumentType, cata.Value);
        }
    }
}

/* This code example produces output similar to the following:

Attributes for assembly: 'source, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
   [System.Runtime.CompilerServices.CompilationRelaxationsAttribute((Int32)8)]
      Constructor: 'Void .ctor(Int32)'
      Constructor arguments:
         Type: 'System.Int32'  Value: '8'
      Named arguments:
   [System.Runtime.CompilerServices.RuntimeCompatibilityAttribute(WrapNonExceptionThrows = True)]
      Constructor: 'Void .ctor()'
      Constructor arguments:
      Named arguments:
         MemberInfo: 'Boolean WrapNonExceptionThrows'
         Type: 'System.Boolean'  Value: 'True'
   [ExampleAttribute((ExampleKind)2, Note = "This is a note on the assembly.")]
      Constructor: 'Void .ctor(ExampleKind)'
      Constructor arguments:
         Type: 'ExampleKind'  Value: '2'
      Named arguments:
         MemberInfo: 'System.String Note'
         Type: 'System.String'  Value: 'This is a note on the assembly.'

Attributes for type: 'Test'
   [ExampleAttribute((ExampleKind)1, new String[3] { "String array argument, line 1", "String array argument, line 2", "String array argument, line 3" }, Note = "This is a note on the class.", Numbers = new Int32[3] { 53, 57, 59 })]
      Constructor: 'Void .ctor(ExampleKind, System.String[])'
      Constructor arguments:
         Type: 'ExampleKind'  Value: '1'
         Array of 'System.String[]':
             Type: 'System.String'  Value: 'String array argument, line 1'
             Type: 'System.String'  Value: 'String array argument, line 2'
             Type: 'System.String'  Value: 'String array argument, line 3'
      Named arguments:
         MemberInfo: 'System.String Note'
         Type: 'System.String'  Value: 'This is a note on the class.'
         MemberInfo: 'Int32[] Numbers'
         Array of 'System.Int32[]':
             Type: 'System.Int32'  Value: '53'
             Type: 'System.Int32'  Value: '57'
             Type: 'System.Int32'  Value: '59'

Attributes for member: 'Void TestMethod(System.Object)'
   [ExampleAttribute(Note = "This is a note on a method.")]
      Constructor: 'Void .ctor()'
      Constructor arguments:
      Named arguments:
         MemberInfo: 'System.String Note'
         Type: 'System.String'  Value: 'This is a note on a method.'

Attributes for parameter: 'System.Object arg'
   [ExampleAttribute()]
      Constructor: 'Void .ctor()'
      Constructor arguments:
      Named arguments:
*/
Imports System
Imports System.Reflection
Imports System.Collections.Generic
Imports System.Collections.ObjectModel

' The example attribute is applied to the assembly.
<Assembly:Example(ExampleKind.ThirdKind, Note:="This is a note on the assembly.")>

' An enumeration used by the ExampleAttribute class.
Public Enum ExampleKind
    FirstKind
    SecondKind
    ThirdKind
    FourthKind
End Enum

' An example attribute. The attribute can be applied to all
' targets, from assemblies to parameters.
'
<AttributeUsage(AttributeTargets.All)> _
Public Class ExampleAttribute
    Inherits Attribute

    ' Data for properties.
    Private kindValue As ExampleKind
    Private noteValue As String
    Private arrayStrings() As String
    Private arrayNumbers() As Integer

    ' Constructors. The parameterless constructor (.ctor) calls
    ' the constructor that specifies ExampleKind and an array of
    ' strings, and supplies the default values.
    '
    Public Sub New(ByVal initKind As ExampleKind, ByVal initStrings() As String)
        kindValue = initKind
        arrayStrings = initStrings
    End Sub
    Public Sub New(ByVal initKind As ExampleKind)
        Me.New(initKind, Nothing)
    End Sub
    Public Sub New()
        Me.New(ExampleKind.FirstKind, Nothing)
    End Sub

    ' Properties. The Note and Numbers properties must be read/write, so they 
    ' can be used as named parameters.
    '
    Public ReadOnly Property Kind As ExampleKind
        Get
            Return kindValue 
        End Get
    End Property
    Public ReadOnly Property Strings As String()
        Get
            Return arrayStrings 
        End Get
    End Property
    Public Property Note As String
        Get
            Return noteValue 
        End Get
        Set
            noteValue = value
        End Set
    End Property
    Public Property Numbers As Integer()
        Get
            Return arrayNumbers 
        End Get
        Set
            arrayNumbers = value
        End Set
    End Property
End Class

' The example attribute is applied to the test class.
'
<Example(ExampleKind.SecondKind, _
         New String() { "String array argument, line 1", _
                        "String array argument, line 2", _
                        "String array argument, line 3" }, _
         Note := "This is a note on the class.", _
         Numbers := New Integer() { 53, 57, 59 })> _
Public Class Test
    ' The example attribute is applied to a method, using the
    ' parameterless constructor and supplying a named argument.
    ' The attribute is also applied to the method parameter.
    '
    <Example(Note:="This is a note on a method.")> _
    Public Sub TestMethod(<Example()> ByVal arg As Object)
    End Sub

    ' Sub Main gets objects representing the assembly, the test
    ' type, the test method, and the method parameter. Custom
    ' attribute data is displayed for each of these.
    '
    Public Shared Sub Main()
        Dim asm As [Assembly] = Assembly.ReflectionOnlyLoad("source")
        Dim t As Type = asm.GetType("Test")
        Dim m As MethodInfo = t.GetMethod("TestMethod")
        Dim p() As ParameterInfo = m.GetParameters()

        Console.WriteLine(vbCrLf & "Attributes for assembly: '{0}'", asm)
        ShowAttributeData(CustomAttributeData.GetCustomAttributes(asm))
        Console.WriteLine(vbCrLf & "Attributes for type: '{0}'", t)
        ShowAttributeData(CustomAttributeData.GetCustomAttributes(t))
        Console.WriteLine(vbCrLf & "Attributes for member: '{0}'", m)
        ShowAttributeData(CustomAttributeData.GetCustomAttributes(m))
        Console.WriteLine(vbCrLf & "Attributes for parameter: '{0}'", p)
        ShowAttributeData(CustomAttributeData.GetCustomAttributes(p(0)))
    End Sub

    Private Shared Sub ShowAttributeData( _
        ByVal attributes As IList(Of CustomAttributeData))

        For Each cad As CustomAttributeData _
            In CType(attributes, IEnumerable(Of CustomAttributeData))

            Console.WriteLine("   {0}", cad)
            Console.WriteLine("      Constructor: '{0}'", cad.Constructor)

            Console.WriteLine("      Constructor arguments:")
            For Each cata As CustomAttributeTypedArgument _
                In CType(cad.ConstructorArguments, IEnumerable(Of CustomAttributeTypedArgument))

                ShowValueOrArray(cata)
            Next

            Console.WriteLine("      Named arguments:")
            For Each cana As CustomAttributeNamedArgument _
                In CType(cad.NamedArguments, IEnumerable(Of CustomAttributeNamedArgument))

                Console.WriteLine("         MemberInfo: '{0}'", _
                    cana.MemberInfo)
                ShowValueOrArray(cana.TypedValue)
            Next
        Next
    End Sub

    Private Shared Sub ShowValueOrArray(ByVal cata As CustomAttributeTypedArgument)
        If cata.Value.GetType() Is GetType(ReadOnlyCollection(Of CustomAttributeTypedArgument)) Then
            Console.WriteLine("         Array of '{0}':", cata.ArgumentType)

            For Each cataElement As CustomAttributeTypedArgument In cata.Value
                Console.WriteLine("             Type: '{0}'  Value: '{1}'", _
                    cataElement.ArgumentType, cataElement.Value)
            Next
        Else
            Console.WriteLine("         Type: '{0}'  Value: '{1}'", _
                cata.ArgumentType, cata.Value)
        End If       
    End Sub
End Class

' This code example produces output similar to the following:
'
'Attributes for assembly: 'source, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
'   [System.Runtime.CompilerServices.CompilationRelaxationsAttribute((Int32)8)]
'      Constructor: 'Void .ctor(Int32)'
'      Constructor arguments:
'         Type: 'System.Int32'  Value: '8'
'      Named arguments:
'   [System.Runtime.CompilerServices.RuntimeCompatibilityAttribute(WrapNonExceptionThrows = True)]
'      Constructor: 'Void .ctor()'
'      Constructor arguments:
'      Named arguments:
'         MemberInfo: 'Boolean WrapNonExceptionThrows'
'         Type: 'System.Boolean'  Value: 'True'
'   [ExampleAttribute((ExampleKind)2, Note = "This is a note on the assembly.")]
'      Constructor: 'Void .ctor(ExampleKind)'
'      Constructor arguments:
'         Type: 'ExampleKind'  Value: '2'
'      Named arguments:
'         MemberInfo: 'System.String Note'
'         Type: 'System.String'  Value: 'This is a note on the assembly.'
'
'Attributes for type: 'Test'
'   [ExampleAttribute((ExampleKind)1, new String[3] { "String array argument, line 1", "String array argument, line 2", "String array argument, line 3" }, Note = "This is a note on the class.", Numbers = new Int32[3] { 53, 57, 59 })]
'      Constructor: 'Void .ctor(ExampleKind, System.String[])'
'      Constructor arguments:
'         Type: 'ExampleKind'  Value: '1'
'         Array of 'System.String[]':
'             Type: 'System.String'  Value: 'String array argument, line 1'
'             Type: 'System.String'  Value: 'String array argument, line 2'
'             Type: 'System.String'  Value: 'String array argument, line 3'
'      Named arguments:
'         MemberInfo: 'System.String Note'
'         Type: 'System.String'  Value: 'This is a note on the class.'
'         MemberInfo: 'Int32[] Numbers'
'         Array of 'System.Int32[]':
'             Type: 'System.Int32'  Value: '53'
'             Type: 'System.Int32'  Value: '57'
'             Type: 'System.Int32'  Value: '59'
'
'Attributes for member: 'Void TestMethod(System.Object)'
'   [ExampleAttribute(Note = "This is a note on a method.")]
'      Constructor: 'Void .ctor()'
'      Constructor arguments:
'      Named arguments:
'         MemberInfo: 'System.String Note'
'         Type: 'System.String'  Value: 'This is a note on a method.'
'
'Attributes for parameter: 'System.Object arg'
'   [ExampleAttribute()]
'      Constructor: 'Void .ctor()'
'      Constructor arguments:
'      Named arguments:

설명

항상 하 고 해당 속성을 검사 한 다음,와 같은 메서드를 사용 하 여 인스턴스를 만들어 사용자 지정 특성을 검사할 수 없는 하므로 리플렉션 전용 컨텍스트에서 검사 중인 코드를 실행할 수 없습니다 Attribute.GetCustomAttributes, MemberInfo.GetCustomAttributes등 .Code that is being examined in the reflection-only context cannot be executed, so it is not always possible to examine custom attributes by creating instances of them and then examining their properties, using methods like Attribute.GetCustomAttributes, MemberInfo.GetCustomAttributes, and so on. 특성 형식 자체에 대 한 코드는 리플렉션 전용 컨텍스트에 로드 되 면이 실행할 수 없습니다.If the code for the attribute type itself is loaded into the reflection-only context, it cannot be executed.

CustomAttributeData 클래스 특성에 대 한 추상화를 제공 하 여 리플렉션 전용 컨텍스트에서 사용자 지정 특성의 검사를 허용 합니다.The CustomAttributeData class allows examination of custom attributes in the reflection-only context by providing an abstraction for attributes. 이 클래스의 멤버 위치 인수를 가져오는 데 사용 하 고 명명 된 특성의 인수 수 있습니다.The members of this class can be used to obtain the positional arguments and named arguments of the attribute. 사용 하 여는 ConstructorArguments 속성의 목록을 가져오려면 CustomAttributeTypedArgument 사용 및 위치 인수를 나타내는 구조를 NamedArguments 속성의 목록을 가져오려면 CustomAttributeNamedArgument 명명 된 인수를 나타내는 구조체입니다.Use the ConstructorArguments property to get a list of CustomAttributeTypedArgument structures that represent the positional arguments, and use the NamedArguments property to get a list of CustomAttributeNamedArgument structures that represent the named arguments.

참고

CustomAttributeNamedArgument 구조만 가져오고 인수 값을 설정 하는 데 사용 되는 특성 속성에 대 한 정보를 제공 합니다.The CustomAttributeNamedArgument structure only provides information about the attribute property used to get and set the argument value. 형식 및 인수 값을 가져오려면 합니다 CustomAttributeNamedArgument.TypedValue 속성을는 CustomAttributeTypedArgument 구조입니다.To obtain the type and value of the argument, use the CustomAttributeNamedArgument.TypedValue property to obtain a CustomAttributeTypedArgument structure.

경우는 CustomAttributeTypedArgument 명명 된 또는 위치 인수에 대 한 구조체 사용 하 여는 CustomAttributeTypedArgument.ArgumentType 형식을 가져올 속성 및 CustomAttributeTypedArgument.Value 속성 값을 가져옵니다.When you have a CustomAttributeTypedArgument structure for an argument, whether named or positional, use the CustomAttributeTypedArgument.ArgumentType property to get the type and the CustomAttributeTypedArgument.Value property to get the value.

참고

배열 인수에 대 한 합니다 CustomAttributeTypedArgument.Value 속성을 제네릭 반환 ReadOnlyCollection<T>CustomAttributeTypedArgument 개체입니다.For an array argument, the CustomAttributeTypedArgument.Value property returns a generic ReadOnlyCollection<T> of CustomAttributeTypedArgument objects. CustomAttributeTypedArgument 컬렉션의 개체 배열의 해당 요소를 나타냅니다.Each CustomAttributeTypedArgument object in the collection represents the corresponding element of the array.

CustomAttributeData 리플렉션 전용 컨텍스트 뿐만 아니라 실행 컨텍스트의 수입니다.CustomAttributeData can be used in the execution context as well as in the reflection-only context. 예를 들어 다음 사용자 지정 특성에 대 한 코드를 포함 하는 어셈블리를 로드 하지 않도록 하는 것이 좋습니다.For example, you might want to avoid loading the assembly that contains the code for a custom attribute. 사용 하는 CustomAttributeData 클래스와 같은 메서드를 사용 하 여 다릅니다 Attribute.GetCustomAttributes:Using the CustomAttributeData class is different from using methods like Attribute.GetCustomAttributes:

  • 속성 및 메서드의 CustomAttributeData 생성자의 의미 체계가 없습니다 특성 인스턴스에 지정 된 값으로 제공 합니다.The properties and methods of CustomAttributeData only provide you with the values that were specified for the attribute instance, not the semantics of the constructor. 예를 들어 특성의 문자열 인수 수 내부적으로 몇 가지 다른 표현으로 변환 되어 반환 될 정규형; 또는 실제 특성 코드를 실행할 때 속성 부작용이 있을 수 있습니다.For example, a string argument of an attribute might be converted internally to some other representation, and returned in a canonical form; or a property might have side effects when the actual attribute code is executed.

  • 속성 및 메서드의 CustomAttributeData 기본 클래스에서 상속 되며, 사용자 지정 특성을 검색할 수 없습니다.The properties and methods of CustomAttributeData do not allow you to retrieve the custom attributes inherited from base classes.

인스턴스를 만들 합니다 CustomAttributeData 클래스를 사용 하 여는 static (Shared Visual basic에서) GetCustomAttributes 팩터리 메서드.To create instances of the CustomAttributeData class, use the static (Shared in Visual Basic) GetCustomAttributes factory methods.

생성자

CustomAttributeData() CustomAttributeData() CustomAttributeData() CustomAttributeData()

CustomAttributeData 클래스의 새 인스턴스를 초기화합니다. Initializes a new instance of the CustomAttributeData class.

속성

AttributeType AttributeType AttributeType AttributeType

특성의 형식을 가져옵니다. Gets the type of the attribute.

Constructor Constructor Constructor Constructor

사용자 지정 특성을 초기화하는 생성자를 나타내는 ConstructorInfo 개체를 가져옵니다. Gets a ConstructorInfo object that represents the constructor that would have initialized the custom attribute.

ConstructorArguments ConstructorArguments ConstructorArguments ConstructorArguments

CustomAttributeData 개체가 나타내는 특성 인스턴스에 지정된 위치 인수 목록을 가져옵니다. Gets the list of positional arguments specified for the attribute instance represented by the CustomAttributeData object.

NamedArguments NamedArguments NamedArguments NamedArguments

CustomAttributeData 개체가 나타내는 특성 인스턴스에 지정된 명명된 인수 목록을 가져옵니다. Gets the list of named arguments specified for the attribute instance represented by the CustomAttributeData object.

메서드

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

@FSHO2@이 인스턴스가 지정한 개체와 같은지를 나타내는 값을 반환합니다. Returns a value that indicates whether this instance is equal to a specified object.

GetCustomAttributes(Assembly) GetCustomAttributes(Assembly) GetCustomAttributes(Assembly) GetCustomAttributes(Assembly)

대상 어셈블리에 적용된 특성에 대한 데이터를 나타내는 CustomAttributeData 개체의 목록을 반환합니다. Returns a list of CustomAttributeData objects representing data about the attributes that have been applied to the target assembly.

GetCustomAttributes(MemberInfo) GetCustomAttributes(MemberInfo) GetCustomAttributes(MemberInfo) GetCustomAttributes(MemberInfo)

대상 멤버에 적용된 특성에 대한 데이터를 나타내는 CustomAttributeData 개체의 목록을 반환합니다. Returns a list of CustomAttributeData objects representing data about the attributes that have been applied to the target member.

GetCustomAttributes(Module) GetCustomAttributes(Module) GetCustomAttributes(Module) GetCustomAttributes(Module)

대상 모듈에 적용된 특성에 대한 데이터를 나타내는 CustomAttributeData 개체의 목록을 반환합니다. Returns a list of CustomAttributeData objects representing data about the attributes that have been applied to the target module.

GetCustomAttributes(ParameterInfo) GetCustomAttributes(ParameterInfo) GetCustomAttributes(ParameterInfo) GetCustomAttributes(ParameterInfo)

대상 매개 변수에 적용된 특성에 대한 데이터를 나타내는 CustomAttributeData 개체의 목록을 반환합니다. Returns a list of CustomAttributeData objects representing data about the attributes that have been applied to the target parameter.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

특정 형식에 대한 해시 함수 역할을 합니다. Serves as a hash function for a particular type.

GetType() GetType() GetType() GetType()

현재 인스턴스의 Type을 가져옵니다. Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다. Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

사용자 지정 특성의 문자열 표현을 반환합니다. Returns a string representation of the custom attribute.

적용 대상

추가 정보