다음을 통해 공유


PropertyInfo 클래스

속성의 특성을 검색하고 속성 메타데이터에 대한 액세스를 제공합니다.

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

구문

‘선언
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.None)> _
Public MustInherit Class PropertyInfo
    Inherits MemberInfo
    Implements _PropertyInfo
‘사용 방법
Dim instance As PropertyInfo
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.None)] 
public abstract class PropertyInfo : MemberInfo, _PropertyInfo
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType::None)] 
public ref class PropertyInfo abstract : public MemberInfo, _PropertyInfo
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.None) */ 
public abstract class PropertyInfo extends MemberInfo implements _PropertyInfo
SerializableAttribute 
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.None) 
public abstract class PropertyInfo extends MemberInfo implements _PropertyInfo

설명

속성과 필드는 논리적으로 같습니다. 속성이란 개체의 특성 상태에 이름을 붙인 것으로 그 값은 대개 getset 접근자를 통해 액세스할 수 있습니다. 속성은 읽기 전용일 수 있습니다. 이런 경우 세트 루틴(set routine)은 지원되지 않습니다.

참고

속성이 static인지 여부를 확인하려면 GetGetMethod 메서드나 GetSetMethod 메서드를 호출하여 get 또는 set 접근자에 대한 MethodInfo를 가져온 다음 해당 IsStatic 속성을 검사해야 합니다.

이 클래스의 일부 메서드는 속성의 getset 접근자 메서드에 특정 형식이 있다고 가정합니다. getset 메서드의 시그니처는 다음 규칙을 따라야 합니다.

  • get 메서드의 반환 형식과 set 메서드의 마지막 인수는 동일해야 합니다. 이것이 속성의 형식입니다.

  • getset 메서드에는 동일한 개수, 형식, 순서의 인덱스가 있어야 합니다.

이 형식을 사용할 수 없으면 GetValueSetValue 메서드의 작동은 정의되지 않습니다.

GetCustomAttributes의 inherit 매개 변수가 true일 때 PropertyInfo에서 ICustomAttributeProvider.GetCustomAttributes를 호출해도 형식 계층이 작동하지 않습니다. System.Attribute를 사용하여 사용자 지정 특성을 상속합니다.

상속자 참고 사항 PropertyInfo에서 상속하는 경우 GetValue, SetValue, GetAccessors, GetGetMethod, GetSetMethodGetIndexParameters 멤버를 재정의해야 합니다.

예제

이 예제에서는 다양한 리플렉션 클래스를 사용하여 어셈블리에 포함된 메타데이터를 분석하는 방법을 보여 줍니다.

Imports System
Imports System.Reflection

Module Module1

    Sub Main()
        ' This variable holds the amount of indenting that 
        ' should be used when displaying each line of information.
        Dim indent As Int32 = 0
        ' Display information about the EXE assembly.
        Dim a As [Assembly] = System.Reflection.Assembly.GetExecutingAssembly()
        Display(indent, "Assembly identity={0}", a.FullName)
        Display(indent + 1, "Codebase={0}", a.CodeBase)

        ' Display the set of assemblies our assemblies references.
        Dim an As AssemblyName
        Display(indent, "Referenced assemblies:")
        For Each an In a.GetReferencedAssemblies()
            Display(indent + 1, "Name={0}, Version={1}, Culture={2}, PublicKey token={3}", _
                an.Name, an.Version, an.CultureInfo.Name, BitConverter.ToString(an.GetPublicKeyToken))
        Next
        Display(indent, "")

        ' Display information about each assembly loading into this AppDomain.
        For Each a In AppDomain.CurrentDomain.GetAssemblies()
            Display(indent, "Assembly: {0}", a)

            ' Display information about each module of this assembly.
            Dim m As [Module]
            For Each m In a.GetModules(True)
                Display(indent + 1, "Module: {0}", m.Name)
            Next

            ' Display information about each type exported from this assembly.
            Dim t As Type
            indent += 1
            For Each t In a.GetExportedTypes()
                Display(0, "")
                Display(indent, "Type: {0}", t)

                ' For each type, show its members & their custom attributes.
                Dim mi As MemberInfo
                indent += 1
                For Each mi In t.GetMembers()
                    Display(indent, "Member: {0}", mi.Name)
                    DisplayAttributes(indent, mi)

                    ' If the member is a method, display information about its parameters.
                    Dim pi As ParameterInfo
                    If mi.MemberType = MemberTypes.Method Then
                        For Each pi In CType(mi, MethodInfo).GetParameters()
                            Display(indent + 1, "Parameter: Type={0}, Name={1}", pi.ParameterType, pi.Name)
                        Next
                    End If

                    ' If the member is a property, display information about the property's accessor methods.
                    If mi.MemberType = MemberTypes.Property Then
                        Dim am As MethodInfo
                        For Each am In CType(mi, PropertyInfo).GetAccessors()
                            Display(indent + 1, "Accessor method: {0}", am)
                        Next
                    End If
                Next
                indent -= 1
            Next
            indent -= 1
        Next
    End Sub

    ' Displays the custom attributes applied to the specified member.
    Sub DisplayAttributes(ByVal indent As Int32, ByVal mi As MemberInfo)
        ' Get the set of custom attributes; if none exist, just return.
        Dim attrs() As Object = mi.GetCustomAttributes(False)
        If attrs.Length = 0 Then Return

        ' Display the custom attributes applied to this member.
        Display(indent + 1, "Attributes:")
        Dim o As Object
        For Each o In attrs
            Display(indent + 2, "{0}", o.ToString())
        Next
    End Sub

    ' Display a formatted string indented by the specified amount.
    Sub Display(ByVal indent As Int32, ByVal format As String, ByVal ParamArray params() As Object)
        Console.Write(New String(" "c, indent * 2))
        Console.WriteLine(format, params)
    End Sub
End Module

'The output shown below is abbreviated.
'
'Assembly identity=Reflection, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
'  Codebase=file:///C:/Reflection.exe
'Referenced assemblies:
'  Name=mscorlib, Version=1.0.5000.0, Culture=, PublicKey token=B7-7A-5C-56-19-34-E0-89
'  Name=Microsoft.VisualBasic, Version=7.0.5000.0, Culture=, PublicKey token=B0-3F-5F-7F-11-D5-0A-3A
'
'Assembly: mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
'  Module: mscorlib.dll
'  Module: prc.nlp
'  Module: prcp.nlp
'  Module: ksc.nlp
'  Module: ctype.nlp
'  Module: xjis.nlp
'  Module: bopomofo.nlp
'  Module: culture.nlp
'  Module: region.nlp
'  Module: sortkey.nlp
'  Module: charinfo.nlp
'  Module: big5.nlp
'  Module: sorttbls.nlp
'  Module: l_intl.nlp
'  Module: l_except.nlp
'
'  Type: System.Object
'    Member: GetHashCode
'    Member: Equals
'      Parameter: Type=System.Object, Name=obj
'    Member: ToString
'    Member: Equals
'      Parameter: Type=System.Object, Name=objA
'      Parameter: Type=System.Object, Name=objB
'    Member: ReferenceEquals
'      Parameter: Type=System.Object, Name=objA
'      Parameter: Type=System.Object, Name=objB
'    Member: GetType
'    Member: .ctor
'
'  Type: System.ICloneable
'    Member: Clone
'
'  Type: System.Collections.IEnumerable
'    Member: GetEnumerator
'      Attributes:
'        System.Runtime.InteropServices.DispIdAttribute
'
'  Type: System.Collections.ICollection
'    Member: get_IsSynchronized
'    Member: get_SyncRoot
'    Member: get_Count
'    Member: CopyTo
'      Parameter: Type=System.Array, Name=array
'      Parameter: Type=System.Int32, Name=index
'    Member: Count
'      Accessor method: Int32 get_Count()
'    Member: SyncRoot
'      Accessor method: System.Object get_SyncRoot()
'    Member: IsSynchronized
'      Accessor method: Boolean get_IsSynchronized()
'

상속 계층 구조

System.Object
   System.Reflection.MemberInfo
    System.Reflection.PropertyInfo
       Microsoft.JScript.COMPropertyInfo
       System.Reflection.Emit.PropertyBuilder

스레드로부터의 안전성

이 형식은 다중 스레드 작업을 수행하는 데 안전합니다.

플랫폼

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

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

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

PropertyInfo 멤버
System.Reflection 네임스페이스