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)

傳回

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.GetCustomAttributes MemberInfo.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.

適用於