MemberInfo.GetCustomAttributesData 方法

定義

傳回 CustomAttributeData 物件的清單,表示已套用至目標成員之屬性的資料。Returns a list of CustomAttributeData objects representing data about the attributes that have been applied to the target member.

public:
 virtual System::Collections::Generic::IList<System::Reflection::CustomAttributeData ^> ^ GetCustomAttributesData();
public virtual System.Collections.Generic.IList<System.Reflection.CustomAttributeData> GetCustomAttributesData ();
abstract member GetCustomAttributesData : unit -> System.Collections.Generic.IList<System.Reflection.CustomAttributeData>
override this.GetCustomAttributesData : unit -> System.Collections.Generic.IList<System.Reflection.CustomAttributeData>
Public Overridable Function GetCustomAttributesData () As IList(Of CustomAttributeData)

傳回

IList<CustomAttributeData>

CustomAttributeData 物件的泛型清單,表示已套用至目標成員之屬性的相關資料。A generic list of CustomAttributeData objects representing data about the attributes that have been applied to the target member.

備註

在僅限反映的內容中,您可以使用這個方法來檢查程式碼的自訂屬性,以在自訂屬性本身是在載入僅限反映內容的程式碼中定義的情況。Use this method to examine the custom attributes of code in the reflection-only context, in cases where the custom attributes themselves are defined in code that is loaded into the reflection-only context. 方法(例如 Attribute.GetCustomAttributesMemberInfo.GetCustomAttributes )無法在這種情況下使用,因為它們會建立屬性的實例。Methods like Attribute.GetCustomAttributes and MemberInfo.GetCustomAttributes cannot be used in such cases, because they create instances of the attributes. 無法執行僅限反映內容中的程式碼。Code in the reflection-only context cannot be executed. 如需詳細資訊和範例程式碼,請參閱 CustomAttributeData 類別。For more information and for example code, see the CustomAttributeData class.

這個方法會取得類型、嵌套型別和型別成員的自訂屬性資料,因為 Type 命名空間中代表型別成員的類別和類別 System.Reflection 都是衍生自 MemberInfoThis method gets custom attribute data for types, nested types, and type members, because the Type class and the classes in the System.Reflection namespace that represent type members all derive from MemberInfo.

適用於