MethodBuilder 類別

定義

定義並表示動態類別上的方法(或建構子)。

public ref class MethodBuilder sealed : System::Reflection::MethodInfo, System::Runtime::InteropServices::_MethodBuilder
public ref class MethodBuilder sealed : System::Reflection::MethodInfo
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
public sealed class MethodBuilder : System.Reflection.MethodInfo, System.Runtime.InteropServices._MethodBuilder
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class MethodBuilder : System.Reflection.MethodInfo, System.Runtime.InteropServices._MethodBuilder
public sealed class MethodBuilder : System.Reflection.MethodInfo
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
type MethodBuilder = class
    inherit MethodInfo
    interface _MethodBuilder
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type MethodBuilder = class
    inherit MethodInfo
    interface _MethodBuilder
type MethodBuilder = class
    inherit MethodInfo
Public NotInheritable Class MethodBuilder
Inherits MethodInfo
Implements _MethodBuilder
Public NotInheritable Class MethodBuilder
Inherits MethodInfo
繼承
屬性
實作

範例

以下範例使用該 MethodBuilder 類別在動態型別中建立方法。


using System;
using System.Reflection;
using System.Reflection.Emit;

class DemoMethodBuilder
{
    public static void AddMethodDynamically (TypeBuilder myTypeBld,
                                             string mthdName,
                                             Type[] mthdParams,
                                             Type returnType,
                                             string mthdAction)
    {

        MethodBuilder myMthdBld = myTypeBld.DefineMethod(
                                             mthdName,
                                             MethodAttributes.Public |
                                             MethodAttributes.Static,
                                             returnType,
                                             mthdParams);

        ILGenerator ILout = myMthdBld.GetILGenerator();

        int numParams = mthdParams.Length;

        for (byte x=0; x < numParams; x++)
        {
            ILout.Emit(OpCodes.Ldarg_S, x);
        }

        if (numParams > 1)
        {
            for (int y=0; y<(numParams-1); y++)
            {
                switch (mthdAction)
                {
                    case "A": ILout.Emit(OpCodes.Add);
                              break;
                    case "M": ILout.Emit(OpCodes.Mul);
                              break;
                    default: ILout.Emit(OpCodes.Add);
                              break;
                }
            }
        }
        ILout.Emit(OpCodes.Ret);
    }

    public static void Main()
    {
        AppDomain myDomain = AppDomain.CurrentDomain;
        AssemblyName asmName = new AssemblyName();
        asmName.Name = "MyDynamicAsm";

        AssemblyBuilder myAsmBuilder = myDomain.DefineDynamicAssembly(
                                       asmName,
                                       AssemblyBuilderAccess.RunAndSave);

        ModuleBuilder myModule = myAsmBuilder.DefineDynamicModule("MyDynamicAsm",
                                                                  "MyDynamicAsm.dll");

        TypeBuilder myTypeBld = myModule.DefineType("MyDynamicType",
                                                    TypeAttributes.Public);

        // Get info from the user to build the method dynamically.
        Console.WriteLine("Let's build a simple method dynamically!");
        Console.WriteLine("Please enter a few numbers, separated by spaces.");
        string inputNums = Console.ReadLine();
        Console.Write("Do you want to [A]dd (default) or [M]ultiply these numbers? ");
        string myMthdAction = Console.ReadLine().ToUpper();
        Console.Write("Lastly, what do you want to name your new dynamic method? ");
        string myMthdName = Console.ReadLine();

        // Process inputNums into an array and create a corresponding Type array
        int index = 0;
        string[] inputNumsList = inputNums.Split();

        Type[] myMthdParams = new Type[inputNumsList.Length];
        object[] inputValsList = new object[inputNumsList.Length];

        foreach (string inputNum in inputNumsList)
        {
            inputValsList[index] = (object)Convert.ToInt32(inputNum);
                myMthdParams[index] = typeof(int);
                index++;
        }

        // Now, call the method building method with the parameters, passing the
        // TypeBuilder by reference.
        AddMethodDynamically(myTypeBld,
                             myMthdName,
                             myMthdParams,
                             typeof(int),
                             myMthdAction);

        Type myType = myTypeBld.CreateType();

        Console.WriteLine("---");
        Console.WriteLine("The result of {0} the inputted values is: {1}",
                          ((myMthdAction == "M") ? "multiplying" : "adding"),
                          myType.InvokeMember(myMthdName,
                          BindingFlags.InvokeMethod | BindingFlags.Public |
                          BindingFlags.Static,
                          null,
                          null,
                          inputValsList));
        Console.WriteLine("---");

        // Let's take a look at the method we created.
        // If you are interested in seeing the MSIL generated dynamically for the method
        // your program generated, change to the directory where you ran the compiled
        // code sample and type "ildasm MyDynamicAsm.dll" at the prompt. When the list
        // of manifest contents appears, click on "MyDynamicType" and then on the name of
        // of the method you provided during execution.

        myAsmBuilder.Save("MyDynamicAsm.dll");

        MethodInfo myMthdInfo = myType.GetMethod(myMthdName);
        Console.WriteLine("Your Dynamic Method: {0};", myMthdInfo.ToString());
    }
}
Imports System.Reflection
Imports System.Reflection.Emit

Class DemoMethodBuilder
   
   Public Shared Sub AddMethodDynamically(ByVal myTypeBld As TypeBuilder, _
                                          ByVal mthdName As String, _
                                          ByVal mthdParams() As Type, _
                                          ByVal returnType As Type, _
                                          ByVal mthdAction As String)
      
      Dim myMthdBld As MethodBuilder = myTypeBld.DefineMethod(mthdName, _
                                       MethodAttributes.Public Or MethodAttributes.Static, _
                                       returnType, _
                                       mthdParams)
      
      Dim ILout As ILGenerator = myMthdBld.GetILGenerator()
      
      Dim numParams As Integer = mthdParams.Length
      
      Dim x As Byte
      For x = 0 To numParams - 1
         ILout.Emit(OpCodes.Ldarg_S, x)
      Next x
      
      If numParams > 1 Then
         Dim y As Integer
         For y = 0 To (numParams - 1) - 1
            Select Case mthdAction
               Case "A"
                  ILout.Emit(OpCodes.Add)
               Case "M"
                  ILout.Emit(OpCodes.Mul)
               Case Else
                  ILout.Emit(OpCodes.Add)
            End Select
         Next y
      End If
      ILout.Emit(OpCodes.Ret)
   End Sub 
    
   
   Public Shared Sub Main()
      
      Dim myDomain As AppDomain = AppDomain.CurrentDomain
      Dim asmName As New AssemblyName()
      asmName.Name = "MyDynamicAsm"
      
      Dim myAsmBuilder As AssemblyBuilder = myDomain.DefineDynamicAssembly(asmName, _
                                            AssemblyBuilderAccess.RunAndSave)
      
      Dim myModule As ModuleBuilder = myAsmBuilder.DefineDynamicModule("MyDynamicAsm", _
                                                                       "MyDynamicAsm.dll")
      
      Dim myTypeBld As TypeBuilder = myModule.DefineType("MyDynamicType", TypeAttributes.Public)
      
      ' Get info from the user to build the method dynamically.
      Console.WriteLine("Let's build a simple method dynamically!")
      Console.WriteLine("Please enter a few numbers, separated by spaces.")
      Dim inputNums As String = Console.ReadLine()
      Console.Write("Do you want to [A]dd (default) or [M]ultiply these numbers? ")
      Dim myMthdAction As String = Console.ReadLine().ToUpper()
      Console.Write("Lastly, what do you want to name your new dynamic method? ")
      Dim myMthdName As String = Console.ReadLine()
      
      ' Process inputNums into an array and create a corresponding Type array 
      Dim index As Integer = 0
      Dim inputNumsList As String() = inputNums.Split()
      
      Dim myMthdParams(inputNumsList.Length - 1) As Type
      Dim inputValsList(inputNumsList.Length - 1) As Object
      
      
      Dim inputNum As String
      For Each inputNum In  inputNumsList
         inputValsList(index) = CType(Convert.ToInt32(inputNum), Object)
         myMthdParams(index) = GetType(Integer)
         index += 1
      Next inputNum
      
      ' Now, call the method building method with the parameters, passing the 
      ' TypeBuilder by reference.
      AddMethodDynamically(myTypeBld, myMthdName, myMthdParams, GetType(Integer), myMthdAction)
      
      Dim myType As Type = myTypeBld.CreateType()
     
      Dim description as String 
      If myMthdAction = "M" Then
         description = "multiplying"
      Else
         description = "adding"
      End If

      Console.WriteLine("---")
      Console.WriteLine("The result of {0} the values is: {1}", _
                         description, _
                         myType.InvokeMember(myMthdName, _
                                             BindingFlags.InvokeMethod _
                                               Or BindingFlags.Public _
                                               Or BindingFlags.Static, _
                                             Nothing, _
                                             Nothing, _
                                             inputValsList)) 
      Console.WriteLine("---")

      ' If you are interested in seeing the MSIL generated dynamically for the method
      ' your program generated, change to the directory where you ran the compiled
      ' code sample and type "ildasm MyDynamicAsm.dll" at the prompt. When the list
      ' of manifest contents appears, click on "MyDynamicType" and then on the name of
      ' of the method you provided during execution.
 
      myAsmBuilder.Save("MyDynamicAsm.dll") 

      Dim myMthdInfo As MethodInfo = myType.GetMethod(myMthdName)
      Console.WriteLine("Your Dynamic Method: {0};", myMthdInfo.ToString())
   End Sub 
End Class

備註

欲了解更多關於此 API 的資訊,請參閱 MethodBuilder 的補充 API 備註

屬性

名稱 Description
Attributes

取得此方法的屬性。

CallingConvention

回傳方法的呼叫慣例。

ContainsGenericParameters

此類型不支援。

CustomAttributes

會獲得包含該成員自訂屬性的集合。

(繼承來源 MemberInfo)
DeclaringType

回傳宣告此方法的型別。

InitLocals

取得或設定一個布林值,指定此方法中的局部變數是否為零初始化。 此屬性的預設值為 true

IsAbstract

會得到一個值,表示該方法是否為抽象。

(繼承來源 MethodBase)
IsAssembly

獲得一個值,表示此方法或建構子的潛在可見性是否由 Assembly描述;也就是說,該方法或建構器最多對同一組裝中的其他型別可見,對組裝外的衍生型別則無法看到。

(繼承來源 MethodBase)
IsConstructedGenericMethod

定義並表示動態類別上的方法(或建構子)。

IsConstructor

會得到一個值,表示該方法是否為建構子。

(繼承來源 MethodBase)
IsFamily

獲得一個值,表示此方法或建構子的可見性是否由 Family描述;也就是說,該方法或建構子僅在其類別及其衍生類別中可見。

(繼承來源 MethodBase)
IsFamilyAndAssembly

會得到一個值,表示此方法或建構子的可見性是否由 FamANDAssem描述;也就是說,該方法或建構子可以被導出類別呼叫,但前提是它們位於同一組建構中。

(繼承來源 MethodBase)
IsFamilyOrAssembly

會得到一個值,表示此方法或建構子的潛在可見性是否由 FamORAssem描述;也就是說,該方法或建構子可以被派生類別呼叫,無論它們所在的位置,或同一組合語言中的類別。

(繼承來源 MethodBase)
IsFinal

得到一個值,表示此方法是否為 final

(繼承來源 MethodBase)
IsGenericMethod

會得到一個值,表示該方法是否為通用方法。

IsGenericMethodDefinition

會得到一個值,表示目前 MethodBuilder 物件是否代表一般方法的定義。

IsHideBySig

會得到一個值,表示導出類別中是否只有同類型且簽名完全相同的成員被隱藏。

(繼承來源 MethodBase)
IsPrivate

會獲得一個值,表示該成員是否為私人。

(繼承來源 MethodBase)
IsPublic

會有一個值來表示這是否是一個公開方法。

(繼承來源 MethodBase)
IsSecurityCritical

在所有情況下都投擲 a NotSupportedException

IsSecurityCritical

會獲得一個值,表示目前的方法或建構子在當前信任層級下是安全關鍵還是安全關鍵,因此可以執行關鍵操作。

(繼承來源 MethodBase)
IsSecuritySafeCritical

在所有情況下都投擲 a NotSupportedException

IsSecuritySafeCritical

獲得一個值,表示目前的方法或建構子在當前信任層級是否為安全關鍵;也就是說,它是否能執行關鍵操作,且是否能被透明程式碼存取。

(繼承來源 MethodBase)
IsSecurityTransparent

在所有情況下都投擲 a NotSupportedException

IsSecurityTransparent

會獲得一個值,表示目前的方法或建構子在目前信任層級是否透明,因此無法執行關鍵操作。

(繼承來源 MethodBase)
IsSpecialName

會得到一個值,表示此方法是否有特殊名稱。

(繼承來源 MethodBase)
IsStatic

獲得一個值,表示該方法是否為 static

(繼承來源 MethodBase)
IsVirtual

獲得一個值,表示該方法是否為 virtual

(繼承來源 MethodBase)
MemberType

會得到 MemberTypes 一個值,表示該成員是一個方法。

(繼承來源 MethodInfo)
MetadataToken

會得到一個識別元資料元素的值。

(繼承來源 MemberInfo)
MethodHandle

取得方法的內部 handle。 使用此代言人來存取底層的元資料代言人。

MethodImplementationFlags

取得 MethodImplAttributes 指定方法實作屬性的旗標。

(繼承來源 MethodBase)
Module

取得目前方法所定義的模組。

Name

取得此方法名稱。

ReflectedType

擷取在反射中用來取得此物件的類別。

ReturnParameter

取得 ParameterInfo 一個包含方法回傳類型資訊的物件,例如該回傳類型是否有自訂修飾符。

ReturnType

取得由 MethodBuilder所表示的方法的回傳類型。

ReturnType

取得此方法的回傳類型。

(繼承來源 MethodInfo)
ReturnTypeCustomAttributes

回傳方法回傳類型中的自訂屬性。

Signature

取得方法的簽名。

方法

名稱 Description
AddDeclarativeSecurity(SecurityAction, PermissionSet)

為此方法加入宣告式安全性。

CreateDelegate(Type, Object)

從此方法建立指定類型的代理,並以指定目標為目標。

(繼承來源 MethodInfo)
CreateDelegate(Type)

從此方法建立指定類型的代理。

(繼承來源 MethodInfo)
CreateMethodBody(Byte[], Int32)

利用提供的 Microsoft 中介語言(MSIL)指令組成的位元組陣列建立方法主體。

DefineGenericParameters(String[])

設定目前方法的通用型別參數數量,指定其名稱,並回傳可用於定義其約束的物件陣列 GenericTypeParameterBuilder

DefineParameter(Int32, ParameterAttributes, String)

設定參數屬性及該方法參數名稱,或該方法的回傳值。 回傳一個 ParameterBuilder,可用來套用自訂屬性。

Equals(Object)

判斷給定物件是否等於此實例。

GetBaseDefinition()

回傳一個方法的基礎實作。

GetCustomAttributes(Boolean)

會回傳此方法所有自訂屬性。

GetCustomAttributes(Type, Boolean)

回傳由指定類型識別的自訂屬性。

GetCustomAttributesData()

回傳一份物件清單 CustomAttributeData ,代表已套用於目標成員的屬性資料。

(繼承來源 MemberInfo)
GetGenericArguments()

如果是通用的,則會回傳一個代表方法類型參數的物件陣列 GenericTypeParameterBuilder

GetGenericMethodDefinition()

回傳此方法。

GetHashCode()

取得此方法的雜湊碼。

GetILGenerator()

此方法回傳 ILGenerator,預設Microsoft中介語言(MSIL)串流大小為 64 位元組。

GetILGenerator(Int32)

會回傳此方法的 ILGenerator,並指定Microsoft中間語言(MSIL)串流大小。

GetMethodBody()

當在衍生類別中覆寫時,會獲得 MethodBody 一個物件,提供存取 MSIL 串流、本地變數及當前方法例外的存取權。

(繼承來源 MethodBase)
GetMethodImplementationFlags()

回傳方法的實作旗標。

GetModule()

回傳包含此方法的模組參考。

GetParameters()

回傳此方法的參數。

GetToken()

回傳 MethodToken 代表此方法的標記。

GetType()

發現方法屬性並提供方法元資料存取。

(繼承來源 MethodInfo)
HasSameMetadataDefinitionAs(MemberInfo)

定義並表示動態類別上的方法(或建構子)。

(繼承來源 MemberInfo)
Invoke(Object, BindingFlags, Binder, Object[], CultureInfo)

動態地在給定物件上呼叫此實例所反映的方法,傳遞指定的參數,並在給定綁定器的限制下傳遞。

Invoke(Object, Object[])

呼叫目前實例所代表的方法或建構子,使用指定的參數。

(繼承來源 MethodInfo)
IsDefined(Type, Boolean)

檢查指定的自訂屬性類型是否已被定義。

MakeGenericMethod(Type[])

回傳一個由當前通用方法定義並使用指定的通用型別參數構建的通用方法。

MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
SetCustomAttribute(ConstructorInfo, Byte[])

使用指定的自訂屬性 blob 設定自訂屬性。

SetCustomAttribute(CustomAttributeBuilder)

使用自訂屬性建構器設定自訂屬性。

SetImplementationFlags(MethodImplAttributes)

設定此方法的實作旗標。

SetMarshal(UnmanagedMarshal)
已淘汰.

設定此方法返回類型的編組資訊。

SetMethodBody(Byte[], Int32, Byte[], IEnumerable<ExceptionHandler>, IEnumerable<Int32>)

透過使用指定的 Microsoft 中介語言(MSIL)指令的位元組陣列來建立方法的主體。

SetParameters(Type[])

設定方法的參數數量與類型。

SetReturnType(Type)

設定方法的回傳類型。

SetSignature(Type, Type[], Type[], Type[], Type[][], Type[][])

設定方法簽名,包括回傳類型、參數類型,以及返回類型和參數類型的必要與可選自訂修飾符。

SetSymCustomAttribute(String, Byte[])

用 blob 設定一個符號自訂屬性。

ToString()

會以字串形式回傳此 MethodBuilder 實例。

明確介面實作

名稱 Description
_MemberInfo.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 MemberInfo)
_MemberInfo.GetType()

取得 Type 一個代表該類別的 MemberInfo 物件。

(繼承來源 MemberInfo)
_MemberInfo.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。

(繼承來源 MemberInfo)
_MemberInfo.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 MemberInfo)
_MemberInfo.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開屬性和方法的存取權。

(繼承來源 MemberInfo)
_MethodBase.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 MethodBase)
_MethodBase.GetType()

關於此成員的描述,請參見 GetType()

(繼承來源 MethodBase)
_MethodBase.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。

(繼承來源 MethodBase)
_MethodBase.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 MethodBase)
_MethodBase.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開屬性和方法的存取權。

(繼承來源 MethodBase)
_MethodBase.IsAbstract

關於此成員的描述,請參見 IsAbstract

(繼承來源 MethodBase)
_MethodBase.IsAssembly

關於此成員的描述,請參見 IsAssembly

(繼承來源 MethodBase)
_MethodBase.IsConstructor

關於此成員的描述,請參見 IsConstructor

(繼承來源 MethodBase)
_MethodBase.IsFamily

關於此成員的描述,請參見 IsFamily

(繼承來源 MethodBase)
_MethodBase.IsFamilyAndAssembly

關於此成員的描述,請參見 IsFamilyAndAssembly

(繼承來源 MethodBase)
_MethodBase.IsFamilyOrAssembly

關於此成員的描述,請參見 IsFamilyOrAssembly

(繼承來源 MethodBase)
_MethodBase.IsFinal

關於此成員的描述,請參見 IsFinal

(繼承來源 MethodBase)
_MethodBase.IsHideBySig

關於此成員的描述,請參見 IsHideBySig

(繼承來源 MethodBase)
_MethodBase.IsPrivate

關於此成員的描述,請參見 IsPrivate

(繼承來源 MethodBase)
_MethodBase.IsPublic

關於此成員的描述,請參見 IsPublic

(繼承來源 MethodBase)
_MethodBase.IsSpecialName

關於此成員的描述,請參見 IsSpecialName

(繼承來源 MethodBase)
_MethodBase.IsStatic

關於此成員的描述,請參見 IsStatic

(繼承來源 MethodBase)
_MethodBase.IsVirtual

關於此成員的描述,請參見 IsVirtual

(繼承來源 MethodBase)
_MethodBuilder.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

_MethodBuilder.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。

_MethodBuilder.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

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

提供物件所公開屬性和方法的存取權。

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

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 MethodInfo)
_MethodInfo.GetType()

提供從 COM 存取 GetType() 該方法的存取。

(繼承來源 MethodInfo)
_MethodInfo.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取 物件的型別資訊,可用來取得介面的類型資訊。

(繼承來源 MethodInfo)
_MethodInfo.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 MethodInfo)
_MethodInfo.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開屬性和方法的存取權。

(繼承來源 MethodInfo)

擴充方法

名稱 Description
GetCustomAttribute(MemberInfo, Type, Boolean)

擷取指定類型的自訂屬性,套用於指定成員,並可選擇性地檢查該成員的祖先。

GetCustomAttribute(MemberInfo, Type)

擷取指定型別的自訂屬性,套用到指定成員。

GetCustomAttribute<T>(MemberInfo, Boolean)

擷取指定類型的自訂屬性,套用於指定成員,並可選擇性地檢查該成員的祖先。

GetCustomAttribute<T>(MemberInfo)

擷取指定型別的自訂屬性,套用到指定成員。

GetCustomAttributes(MemberInfo, Boolean)

擷取一套套用於指定成員的自訂屬性,並可選擇性地檢查該成員的祖先。

GetCustomAttributes(MemberInfo, Type, Boolean)

擷取一組指定類型的自訂屬性,套用於指定成員,並可選擇性檢查該成員的祖先。

GetCustomAttributes(MemberInfo, Type)

擷取一組指定類型的自訂屬性,套用到指定成員。

GetCustomAttributes(MemberInfo)

擷取一套套用於指定成員的自訂屬性集合。

GetCustomAttributes<T>(MemberInfo, Boolean)

擷取一組指定類型的自訂屬性,套用於指定成員,並可選擇性檢查該成員的祖先。

GetCustomAttributes<T>(MemberInfo)

擷取一組指定類型的自訂屬性,套用到指定成員。

GetRuntimeBaseDefinition(MethodInfo)

擷取代表指定方法的物件,該物件在直接或間接基底類別中,該方法首次宣告該類別。

IsDefined(MemberInfo, Type, Boolean)

表示是否將特定類型的自訂屬性套用於指定成員,並可選擇套用於其祖先。

IsDefined(MemberInfo, Type)

表示是否套用特定類型的自訂屬性給指定成員。

適用於