PropertyInfo 类

定义

发现属性 (Property) 的属性 (Attribute) 并提供对属性 (Property) 元数据的访问。

public ref class PropertyInfo abstract : System::Reflection::MemberInfo
public ref class PropertyInfo abstract : System::Reflection::MemberInfo, System::Runtime::InteropServices::_PropertyInfo
public abstract class PropertyInfo : System.Reflection.MemberInfo
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Serializable]
public abstract class PropertyInfo : System.Reflection.MemberInfo, System.Runtime.InteropServices._PropertyInfo
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class PropertyInfo : System.Reflection.MemberInfo, System.Runtime.InteropServices._PropertyInfo
type PropertyInfo = class
    inherit MemberInfo
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
[<System.Serializable>]
type PropertyInfo = class
    inherit MemberInfo
    interface _PropertyInfo
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type PropertyInfo = class
    inherit MemberInfo
    interface _PropertyInfo
Public MustInherit Class PropertyInfo
Inherits MemberInfo
Public MustInherit Class PropertyInfo
Inherits MemberInfo
Implements _PropertyInfo
继承
PropertyInfo
派生
属性
实现

示例

此示例演示如何使用各种反射类来分析程序集中包含的元数据。

注意

此示例生成大约 55,000 行数据,可以在命令提示符处将其重定向到文本文件,如下所示: example.exe > propertyinfo.txt

using namespace System;
using namespace System::Reflection;

static void Display(Int32 indent, String^ format, ... array<Object^>^param) 
{
    Console::Write("{0}", gcnew String (' ', indent));
    Console::WriteLine(format, param);
}
    
// Displays the custom attributes applied to the specified member.
static void DisplayAttributes(Int32 indent, MemberInfo^ mi)
{
    // Get the set of custom attributes; if none exist, just return.
    array<Object^>^attrs = mi->GetCustomAttributes(false);
        
    if (attrs->Length==0)
    {
        return;          
    }
        
    // Display the custom attributes applied to this member.
    Display(indent+1, "Attributes:");
    for each ( Object^ o in attrs )
    {
        Display(indent*2, "{0}", o);
    }				
}

void main()
{
    try
    {
        // This variable holds the amount of indenting that 
        // should be used when displaying each line of information.
        Int32 indent = 0; 
        // Display information about the EXE assembly.
        Assembly^ a = System::Reflection::Assembly::GetExecutingAssembly();
        
        Display(indent, "Assembly identity={0}", gcnew array<Object^> {a->FullName});
        Display(indent+1, "Codebase={0}", gcnew array<Object^> {a->CodeBase});

        // Display the set of assemblies our assemblies reference.
  
        Display(indent, "Referenced assemblies:"); 

        for each ( AssemblyName^ an in a->GetReferencedAssemblies() )
        {
            Display(indent + 1, "Name={0}, Version={1}, Culture={2}, PublicKey token={3}", gcnew array<Object^> {an->Name, an->Version, an->CultureInfo, (BitConverter::ToString(an->GetPublicKeyToken()))});
        }
        Display(indent, "");  
        // Display information about each assembly loading into this AppDomain. 
        for each ( Assembly^ b in AppDomain::CurrentDomain->GetAssemblies()) 
        {
            Display(indent, "Assembly: {0}", gcnew array<Object^> {b});
            // Display information about each module of this assembly.
 
            for each ( Module^ m in b->GetModules(true) ) 
            {
                Display(indent+1, "Module: {0}", gcnew array<Object^> {m->Name});
            }
            // Display information about each type exported from this assembly.
           
            indent += 1; 
            for each ( Type^ t in b->GetExportedTypes() ) 
            {
                Display(0, "");  
                Display(indent, "Type: {0}", gcnew array<Object^> {t}); 

                // For each type, show its members & their custom attributes.
           
                indent += 1; 
                for each (MemberInfo^ mi in t->GetMembers() )
                {
                    Display(indent, "Member: {0}", gcnew array<Object^> {mi->Name}); 
                    DisplayAttributes(indent, mi);

                    // If the member is a method, display information about its parameters.         
                    if (mi->MemberType==MemberTypes::Method) 
                    {
                    
                        for each ( ParameterInfo^ pi in (((MethodInfo^) mi)->GetParameters()))
                        {
                            Display(indent+1, "Parameter: Type={0}, Name={1}", gcnew array<Object^> {pi->ParameterType, pi->Name}); 
                        }
                    }

                    // If the member is a property, display information about the property's accessor methods.
                    if (mi->MemberType==MemberTypes::Property) 
                    {
                        for each ( MethodInfo^ am in (((PropertyInfo^) mi)->GetAccessors()) )
                        {
                            Display(indent+1, "Accessor method: {0}", gcnew array<Object^> {am});
                        }
                    }
                }
                // Display a formatted string indented by the specified amount.               
                indent -= 1;
            }
            indent -= 1;
        }
    }
    catch (Exception^ e)
    {
        Console::WriteLine(e->Message);
    }
}

// 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()
//
using System;
using System.Reflection;

class Module1
{
    public static void Main()
    {
        // This variable holds the amount of indenting that
        // should be used when displaying each line of information.
        Int32 indent = 0;
        // Display information about the EXE assembly.
        Assembly a = typeof(Module1).Assembly;
        Display(indent, "Assembly identity={0}", a.FullName);
        Display(indent+1, "Codebase={0}", a.CodeBase);

        // Display the set of assemblies our assemblies reference.

        Display(indent, "Referenced assemblies:");
        foreach (AssemblyName 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())));
        }
        Display(indent, "");

        // Display information about each assembly loading into this AppDomain.
        foreach (Assembly b in AppDomain.CurrentDomain.GetAssemblies())
        {
            Display(indent, "Assembly: {0}", b);

            // Display information about each module of this assembly.
            foreach ( Module m in b.GetModules(true) )
            {
                Display(indent+1, "Module: {0}", m.Name);
            }

            // Display information about each type exported from this assembly.

            indent += 1;
            foreach ( Type t in b.GetExportedTypes() )
            {
                Display(0, "");
                Display(indent, "Type: {0}", t);

                // For each type, show its members & their custom attributes.

                indent += 1;
                foreach (MemberInfo mi in t.GetMembers() )
                {
                    Display(indent, "Member: {0}", mi.Name);
                    DisplayAttributes(indent, mi);

                    // If the member is a method, display information about its parameters.

                    if (mi.MemberType==MemberTypes.Method)
                    {
                        foreach ( ParameterInfo pi in ((MethodInfo) mi).GetParameters() )
                        {
                            Display(indent+1, "Parameter: Type={0}, Name={1}", pi.ParameterType, pi.Name);
                        }
                    }

                    // If the member is a property, display information about the property's accessor methods.
                    if (mi.MemberType==MemberTypes.Property)
                    {
                        foreach ( MethodInfo am in ((PropertyInfo) mi).GetAccessors() )
                        {
                            Display(indent+1, "Accessor method: {0}", am);
                        }
                    }
                }
                indent -= 1;
            }
            indent -= 1;
        }
    }

    // Displays the custom attributes applied to the specified member.
    public static void DisplayAttributes(Int32 indent, MemberInfo mi)
    {
        // Get the set of custom attributes; if none exist, just return.
        object[] attrs = mi.GetCustomAttributes(false);
        if (attrs.Length==0) {return;}

        // Display the custom attributes applied to this member.
        Display(indent+1, "Attributes:");
        foreach ( object o in attrs )
        {
            Display(indent+2, "{0}", o.ToString());
        }
    }

    // Display a formatted string indented by the specified amount.
    public static void Display(Int32 indent, string format, params object[] param)

    {
        Console.Write(new string(' ', indent*2));
        Console.WriteLine(format, param);
    }
}

//The output shown below is abbreviated.
//
//Assembly identity=ReflectionCS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
//  Codebase=file:///C:/Documents and Settings/test/My Documents/Visual Studio 2005/Projects/Reflection/Reflection/obj/Debug/Reflection.exe
//Referenced assemblies:
//  Name=mscorlib, Version=2.0.0.0, Culture=, PublicKey token=B7-7A-5C-56-19-34-E0-89
//
//Assembly: mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
//  Module: mscorlib.dll
//  Module: mscorlib.dll
//  Module: mscorlib.dll
//  Module: mscorlib.dll
//  Module: mscorlib.dll
//  Module: mscorlib.dll
//  Module: mscorlib.dll
//  Module: mscorlib.dll
//  Module: mscorlib.dll
//  Module: mscorlib.dll
//  Module: mscorlib.dll
//  Module: mscorlib.dll
//  Module: mscorlib.dll
//  Module: mscorlib.dll
//
//  Type: System.Object
//    Member: GetType
//    Member: ToString
//    Member: Equals
//      Parameter: Type=System.Object, Name=obj
//    Member: Equals
//      Parameter: Type=System.Object, Name=objA
//      Parameter: Type=System.Object, Name=objB
//    Member: ReferenceEquals
//      Attributes:
//        System.Runtime.ConstrainedExecution.ReliabilityContractAttribute
//      Parameter: Type=System.Object, Name=objA
//      Parameter: Type=System.Object, Name=objB
//    Member: GetHashCode
//    Member: .ctor
//      Attributes:
//        System.Runtime.ConstrainedExecution.ReliabilityContractAttribute
//
//  Type: System.ICloneable
//    Member: Clone
//
//  Type: System.Collections.IEnumerable
//    Member: GetEnumerator
//      Attributes:
//        System.Runtime.InteropServices.DispIdAttribute
//
//  Type: System.Collections.ICollection
//    Member: CopyTo
//      Parameter: Type=System.Array, Name=array
//      Parameter: Type=System.Int32, Name=index
//    Member: get_Count
//    Member: get_SyncRoot
//    Member: get_IsSynchronized
//    Member: Count
//      Accessor method: Int32 get_Count()
//    Member: SyncRoot
//      Accessor method: System.Object get_SyncRoot()
//    Member: IsSynchronized
//      Accessor method: Boolean get_IsSynchronized()
//
//  Type: System.Collections.IList
//    Member: get_Item
//      Parameter: Type=System.Int32, Name=index
//    Member: set_Item
//      Parameter: Type=System.Int32, Name=index
//      Parameter: Type=System.Object, Name=value
//    Member: Add
//      Parameter: Type=System.Object, Name=value
//    Member: Contains
//      Parameter: Type=System.Object, Name=value
//    Member: Clear
//    Member: get_IsReadOnly
//    Member: get_IsFixedSize
//    Member: IndexOf
//      Parameter: Type=System.Object, Name=value
//    Member: Insert
//      Parameter: Type=System.Int32, Name=index
//      Parameter: Type=System.Object, Name=value
//    Member: Remove
//      Parameter: Type=System.Object, Name=value
//    Member: RemoveAt
//      Parameter: Type=System.Int32, Name=index
//    Member: Item
//      Accessor method: System.Object get_Item(Int32)
//      Accessor method: Void set_Item(Int32, System.Object)
//    Member: IsReadOnly
//      Accessor method: Boolean get_IsReadOnly()
//    Member: IsFixedSize
//      Accessor method: Boolean get_IsFixedSize()
//
//  Type: System.Array
//    Member: IndexOf
//      Parameter: Type=T[], Name=array
//      Parameter: Type=T, Name=value
//    Member: AsReadOnly
//      Parameter: Type=T[], Name=array
//    Member: Resize
//      Attributes:
//        System.Runtime.ConstrainedExecution.ReliabilityContractAttribute
//      Parameter: Type=T[]&, Name=array
//      Parameter: Type=System.Int32, Name=newSize
//    Member: BinarySearch
//      Attributes:
//        System.Runtime.ConstrainedExecution.ReliabilityContractAttribute
//      Parameter: Type=T[], Name=array
//      Parameter: Type=T, Name=value
//    Member: BinarySearch
//      Attributes:
//        System.Runtime.ConstrainedExecution.ReliabilityContractAttribute
//      Parameter: Type=T[], Name=array
//      Parameter: Type=T, Name=value
//      Parameter: Type=System.Collections.Generic.IComparer`1[T], Name=comparer
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 = GetType(Module1).Assembly
        Display(indent, "Assembly identity={0}", a.FullName)
        Display(indent + 1, "Codebase={0}", a.CodeBase)

        ' Display the set of assemblies our assemblies reference.
        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()
'

注解

属性在逻辑上与字段相同。 属性是对象的状态的命名方面,其值通常可通过 getset 访问器进行访问。 属性可以是只读的,在这种情况下,不支持设置例程。

注意

若要确定属性是否为 static,必须通过调用 GetGetMethodGetSetMethod 方法获取 MethodInfogetset 访问器的 ,并检查其 IsStatic 属性。

此类中的多个方法假定属性的 get 访问器和 set 访问器方法具有特定格式。 和 set 方法的get签名必须与以下约定匹配:

  • 方法的 get 返回类型与方法的最后一个 set 参数必须相同。 这是属性的类型。

  • getset 方法必须具有相同的索引数、类型和顺序。

如果不遵循此格式,则 和 SetValue 方法的行为GetValue是不确定的。

当 的 GetCustomAttributes 参数为 trueinherit,在 上PropertyInfo调用 ICustomAttributeProvider.GetCustomAttributes 不会遍进类型层次结构。 使用 System.Attribute 继承自定义属性。

实施者说明

PropertyInfo继承时,必须重写以下成员:GetValue(Object, Object[])、、SetValue(Object, Object, BindingFlags, Binder, Object[], CultureInfo)GetAccessors(Boolean)GetGetMethod(Boolean)GetSetMethod(Boolean)GetIndexParameters()

构造函数

PropertyInfo()

初始化 PropertyInfo 类的新实例。

属性

Attributes

获取此属性 (Property) 的属性 (Attribute)。

CanRead

获取一个值,该值指示此属性是否可读。

CanWrite

获取一个值,该值指示此属性是否可写。

CustomAttributes

获取包含此成员自定义属性的集合。

(继承自 MemberInfo)
DeclaringType

获取声明该成员的类。

(继承自 MemberInfo)
GetMethod

获取此属性的 get 访问器。

IsCollectible

获取一个值,该值指示此 MemberInfo 对象是否是包含在可回收的 AssemblyLoadContext 中的程序集的一部分。

(继承自 MemberInfo)
IsSpecialName

获取一个值,该值指示此属性是否是特殊名称。

MemberType

获取一个 MemberTypes 值,该值指示此成员是属性。

MemberType

在派生类中重写时,获取 MemberTypes 值,该值指示成员类型 - 方法、构造函数、事件等。

(继承自 MemberInfo)
MetadataToken

获取一个值,该值标识元数据元素。

(继承自 MemberInfo)
Module

获取一个模块,在该模块中已经定义一个类型,该类型用于声明由当前 MemberInfo 表示的成员。

(继承自 MemberInfo)
Name

获取当前成员的名称。

(继承自 MemberInfo)
PropertyType

获取此属性的类型。

ReflectedType

获取用于获取 MemberInfo 的此实例的类对象。

(继承自 MemberInfo)
SetMethod

获取此属性的 set 访问器。

方法

Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。

Equals(Object)

返回一个值,该值指示此实例是否与指定的对象相等。

(继承自 MemberInfo)
GetAccessors()

返回一个数组,其元素反射了由当前实例反射的属性的公共 getset 访问器。

GetAccessors(Boolean)

返回一个数组,其元素反射了当前实例反射的属性的公共及非公共(如果指定)getset 取值函数。

GetConstantValue()

由编译器返回与属性关联的文本值。

GetCustomAttributes(Boolean)

在派生类中重写时,返回应用于此成员的所有自定义属性的数组。

(继承自 MemberInfo)
GetCustomAttributes(Type, Boolean)

在派生类中重写时,返回应用于此成员并由 Type 标识的自定义属性的数组。

(继承自 MemberInfo)
GetCustomAttributesData()

返回 CustomAttributeData 对象列表,这些对象表示已应用到目标成员的特性相关数据。

(继承自 MemberInfo)
GetGetMethod()

返回此属性的公共 get 访问器。

GetGetMethod(Boolean)

当在派生类中重写时,返回此属性的公共或非公共 get 访问器。

GetHashCode()

返回此实例的哈希代码。

GetHashCode()

返回此实例的哈希代码。

(继承自 MemberInfo)
GetIndexParameters()

当在派生类中重写时,返回此属性的所有索引参数的数组。

GetModifiedPropertyType()

获取此属性对象的修改类型。

GetOptionalCustomModifiers()

返回一个类型数组,其中的类型表示属性的可选自定义修饰符。

GetRawConstantValue()

由编译器返回与属性关联的文本值。

GetRequiredCustomModifiers()

返回一个类型数组,其中的类型表示属性所必需的自定义修饰符。

GetSetMethod()

返回此属性的公共 set 访问器。

GetSetMethod(Boolean)

当在派生类中重写时,返回此属性的 set 访问器。

GetType()

发现属性 (Property) 的属性 (Attribute) 并提供对属性 (Property) 元数据的访问。

GetType()

发现成员的属性并提供对成员元数据的访问权限。

(继承自 MemberInfo)
GetValue(Object)

返回指定对象的属性值。

GetValue(Object, BindingFlags, Binder, Object[], CultureInfo)

当在派生类中重写时,将返回具有指定绑定、索引和区域性特定信息的指定对象的属性值。

GetValue(Object, Object[])

用索引化属性的可选索引值返回指定对象的该属性值。

HasSameMetadataDefinitionAs(MemberInfo)

发现属性 (Property) 的属性 (Attribute) 并提供对属性 (Property) 元数据的访问。

(继承自 MemberInfo)
IsDefined(Type, Boolean)

在派生类中重写时,指示是否将指定类型或其派生类型的一个或多个特性应用于此成员。

(继承自 MemberInfo)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
SetValue(Object, Object)

设置指定对象的属性值。

SetValue(Object, Object, BindingFlags, Binder, Object[], CultureInfo)

当在派生类中重写时,为具有指定绑定、索引和区域性特定信息的指定对象设置属性值。

SetValue(Object, Object, Object[])

用索引化属性的可选索引值设置指定对象的该属性值。

ToString()

返回表示当前对象的字符串。

(继承自 Object)

运算符

Equality(PropertyInfo, PropertyInfo)

指示两个 PropertyInfo 对象是否相等。

Inequality(PropertyInfo, PropertyInfo)

指示两个 PropertyInfo 对象是否不相等。

显式接口实现

_MemberInfo.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。

(继承自 MemberInfo)
_MemberInfo.GetType()

获取一个表示 MemberInfo 类的 Type 对象。

(继承自 MemberInfo)
_MemberInfo.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。

(继承自 MemberInfo)
_MemberInfo.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。

(继承自 MemberInfo)
_MemberInfo.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。

(继承自 MemberInfo)
_PropertyInfo.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。

_PropertyInfo.GetType()

获取表示 Type 类型的 PropertyInfo 对象。

_PropertyInfo.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。

_PropertyInfo.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。

_PropertyInfo.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。

ICustomAttributeProvider.GetCustomAttributes(Boolean)

返回在该成员上定义的所有自定义特性的数组(已命名的特性除外),如果没有自定义特性,则返回空数组。

(继承自 MemberInfo)
ICustomAttributeProvider.GetCustomAttributes(Type, Boolean)

返回在该成员上定义、由类型标识的自定义属性数组,如果没有该类型的自定义属性,则返回空数组。

(继承自 MemberInfo)
ICustomAttributeProvider.IsDefined(Type, Boolean)

指示是否在该成员上定义了一个或多个 attributeType 实例。

(继承自 MemberInfo)

扩展方法

GetCustomAttribute(MemberInfo, Type)

检索应用于指定成员的指定类型的自定义特性。

GetCustomAttribute(MemberInfo, Type, Boolean)

检索应用于指定成员的指定类型的自定义特性,并可选择检查该成员的上级。

GetCustomAttribute<T>(MemberInfo)

检索应用于指定成员的指定类型的自定义特性。

GetCustomAttribute<T>(MemberInfo, Boolean)

检索应用于指定成员的指定类型的自定义特性,并可选择检查该成员的上级。

GetCustomAttributes(MemberInfo)

检索应用于指定成员的自定义特性集合。

GetCustomAttributes(MemberInfo, Boolean)

检索应用于指定成员的自定义特性集合,并可选择检查该成员的上级。

GetCustomAttributes(MemberInfo, Type)

检索应用于指定成员的指定类型的自定义特性集合。

GetCustomAttributes(MemberInfo, Type, Boolean)

检索应用于指定成员的指定类型的自定义特性集合,并可选择检查该成员的上级。

GetCustomAttributes<T>(MemberInfo)

检索应用于指定成员的指定类型的自定义特性集合。

GetCustomAttributes<T>(MemberInfo, Boolean)

检索应用于指定成员的指定类型的自定义特性集合,并可选择检查该成员的上级。

IsDefined(MemberInfo, Type)

确定是否将指定类型的任何自定义属性应用于指定的成员。

IsDefined(MemberInfo, Type, Boolean)

指示一个指定类型的自定义特性是否应用于一个指定的数字,并选择性地应用于其的上级。

GetMetadataToken(MemberInfo)

获取给定成员的元数据令牌(如果可用)。

HasMetadataToken(MemberInfo)

返回表示元数据令牌是否可用于指定的成员的值。

GetAccessors(PropertyInfo)

发现属性 (Property) 的属性 (Attribute) 并提供对属性 (Property) 元数据的访问。

GetAccessors(PropertyInfo, Boolean)

发现属性 (Property) 的属性 (Attribute) 并提供对属性 (Property) 元数据的访问。

GetGetMethod(PropertyInfo)

发现属性 (Property) 的属性 (Attribute) 并提供对属性 (Property) 元数据的访问。

GetGetMethod(PropertyInfo, Boolean)

发现属性 (Property) 的属性 (Attribute) 并提供对属性 (Property) 元数据的访问。

GetSetMethod(PropertyInfo)

发现属性 (Property) 的属性 (Attribute) 并提供对属性 (Property) 元数据的访问。

GetSetMethod(PropertyInfo, Boolean)

发现属性 (Property) 的属性 (Attribute) 并提供对属性 (Property) 元数据的访问。

适用于

线程安全性

此类型是线程安全的。