MethodBuilder 类

定义

定义并表示动态类上的方法(或构造函数)。

public ref class MethodBuilder sealed : System::Reflection::MethodInfo
public ref class MethodBuilder abstract : System::Reflection::MethodInfo
public ref class MethodBuilder sealed : System::Reflection::MethodInfo, System::Runtime::InteropServices::_MethodBuilder
public sealed class MethodBuilder : System.Reflection.MethodInfo
public abstract class MethodBuilder : 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
type MethodBuilder = class
    inherit 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
Public NotInheritable Class MethodBuilder
Inherits MethodInfo
Public MustInherit Class MethodBuilder
Inherits MethodInfo
Public NotInheritable Class MethodBuilder
Inherits MethodInfo
Implements _MethodBuilder
继承
属性
实现

示例

以下示例使用 MethodBuilder 类在动态类型中创建方法。

using namespace System;
using namespace System::Reflection;
using namespace System::Reflection::Emit;

void AddMethodDynamically( TypeBuilder^ myTypeBld, 
                           String^ mthdName, 
                           array<Type^>^ mthdParams, 
                           Type^ returnType, 
                           String^ mthdAction )
{
   MethodBuilder^ myMthdBld = myTypeBld->DefineMethod( mthdName, static_cast<MethodAttributes>(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++ )
      {
         if ( mthdAction->Equals( "A" ) )
                  ILOut->Emit( OpCodes::Add );
         else
         if ( mthdAction->Equals( "M" ) )
                  ILOut->Emit( OpCodes::Mul );
         else
                  ILOut->Emit( OpCodes::Add );

      }
   }

   ILOut->Emit( OpCodes::Ret );
};

void main()
{
   AppDomain^ myDomain = AppDomain::CurrentDomain;
   AssemblyName^ asmName = gcnew 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;
   array<String^>^inputNumsList = inputNums->Split();
   array<Type^>^myMthdParams = gcnew array<Type^>(inputNumsList->Length);
   array<Object^>^inputValsList = gcnew array<Object^>(inputNumsList->Length);
   for each (String^ inputNum in inputNumsList)
   {
      inputValsList[ index ] = Convert::ToInt32( inputNum );
      myMthdParams[ index ] = int::typeid;
      index++;
   }

   
   // Now, call the method building method with the parameters, passing the
   // TypeBuilder by reference.
   AddMethodDynamically( myTypeBld, 
                         myMthdName, 
                         myMthdParams, 
                         int::typeid, 
                         myMthdAction );
   Type^ myType = myTypeBld->CreateType();

   Console::WriteLine( "---" );
   Console::WriteLine( "The result of {0} the inputted values is: {1}", 
                       ((myMthdAction->Equals( "M" )) ? "multiplying" : "adding"), 
                       myType->InvokeMember( myMthdName, 
                                             BindingFlags::InvokeMethod | BindingFlags::Public | BindingFlags::Static, 
                       nullptr, 
                       nullptr, 
                       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 );
}

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 说明

构造函数

MethodBuilder()

初始化 MethodBuilder 类的新实例。

属性

Attributes

检索此方法的属性。

CallingConvention

返回此方法的调用约定。

ContainsGenericParameters

不支持此类型。

ContainsGenericParameters

获取一个值,该值指示泛型方法是否包含未分配的泛型类型参数。

(继承自 MethodInfo)
CustomAttributes

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

(继承自 MemberInfo)
DeclaringType

返回声明此方法的类型。

InitLocals

获取或设置一个布尔值,该值指定此方法中的局部变量是否初始化为零。 此属性的默认值为 true

InitLocalsCore

在派生类中重写时,获取或设置一个值,该值指示此方法中的局部变量是否为零初始化。

IsAbstract

获取一个值,该值指示此方法是否为抽象方法。

(继承自 MethodBase)
IsAssembly

获取一个值,该值指示此方法或构造函数的潜在可见性是否由 Assembly 描述;也就是说,此方法或构造函数只对同一程序集中的其他类型可见,而对该程序集以外的派生类型则不可见。

(继承自 MethodBase)
IsCollectible

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

(继承自 MemberInfo)
IsConstructedGenericMethod

定义并表示动态类上的方法(或构造函数)。

IsConstructedGenericMethod

定义并表示动态类上的方法(或构造函数)。

(继承自 MethodBase)
IsConstructor

获取一个值,该值指示此方法是否为构造函数。

(继承自 MethodBase)
IsFamily

获取一个值,该值指示此方法或构造函数的可见性是否由 Family 描述;也就是说,此方法或构造函数仅在其类和派生类内可见。

(继承自 MethodBase)
IsFamilyAndAssembly

获取一个值,该值指示此方法或构造函数的可见性是否由 FamANDAssem 描述;也就是说,此方法或构造函数可由派生类调用,但仅当这些派生类在同一程序集中时。

(继承自 MethodBase)
IsFamilyOrAssembly

获取一个值,该值指示此方法或构造函数的潜在可见性是否由 FamORAssem 描述;也就是说,此方法或构造函数可由派生类(无论其位置如何)和同一程序集中的类调用。

(继承自 MethodBase)
IsFinal

获取一个值,该值指示此方法是否为 final

(继承自 MethodBase)
IsGenericMethod

获取一个值,该值指示方法是否为泛型方法。

IsGenericMethod

获取一个值,该值指示当前方法是否为泛型方法。

(继承自 MethodInfo)
IsGenericMethodDefinition

获取一个值,该值指示当前 MethodBuilder 对象是否表示泛型方法的定义。

IsGenericMethodDefinition

获取一个值,该值指示当前 MethodInfo 是否表示泛型方法的定义。

(继承自 MethodInfo)
IsHideBySig

获取一个值,该值指示是否只有一个签名完全相同的同一种类的成员在派生类中是隐藏的。

(继承自 MethodBase)
IsPrivate

获取一个值,该值指示此成员是否是私有的。

(继承自 MethodBase)
IsPublic

获取一个值,该值指示这是否是一个公共方法。

(继承自 MethodBase)
IsSecurityCritical

在所有情况下均引发 NotSupportedException

IsSecurityCritical

获取一个值,该值指示当前方法或构造函数在当前信任级别上是安全关键的还是安全可靠关键的,因此可以执行关键操作。

(继承自 MethodBase)
IsSecuritySafeCritical

在所有情况下均引发 NotSupportedException

IsSecuritySafeCritical

获取一个值,该值指示当前方法或构造函数在当前信任级别上是安全可靠关键的;即它是否可以执行关键操作并可以由透明代码访问。

(继承自 MethodBase)
IsSecurityTransparent

在所有情况下均引发 NotSupportedException

IsSecurityTransparent

获取一个值,该值指示当前方法或构造函数在当前信任级别上是透明的,因此无法执行关键操作。

(继承自 MethodBase)
IsSpecialName

获取一个值,该值指示此方法是否具有特殊名称。

(继承自 MethodBase)
IsStatic

获取一个值,该值指示方法是否为 static

(继承自 MethodBase)
IsVirtual

获取一个值,该值指示方法是否为 virtual

(继承自 MethodBase)
MemberType

获取一个 MemberTypes 值,该值指示此成员是方法。

(继承自 MethodInfo)
MetadataToken

获取一个标记,该标记用于标识元数据中的当前动态模块。

MetadataToken

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

(继承自 MemberInfo)
MethodHandle

检索此方法的内部句柄。 使用此句柄来访问基础元数据句柄。

MethodHandle

获取方法的内部元数据表示形式的句柄。

(继承自 MethodBase)
MethodImplementationFlags

定义并表示动态类上的方法(或构造函数)。

MethodImplementationFlags

获取指定方法实现特性的 MethodImplAttributes 标志。

(继承自 MethodBase)
Module

获取在其中定义了当前方法的模块。

Module

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

(继承自 MemberInfo)
Name

检索此方法的名称。

ReflectedType

检索在反射中用于获取此对象的类。

ReflectedType

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

(继承自 MemberInfo)
ReturnParameter

获取一个 ParameterInfo 对象,该对象包含有关方法的返回类型的信息(例如返回类型是否具有自定义修饰符)。

ReturnParameter

获取一个 ParameterInfo 对象,该对象包含有关方法的返回类型的信息(例如返回类型是否具有自定义修饰符)。

(继承自 MethodInfo)
ReturnType

获取此 MethodBuilder 所表示的方法的返回类型。

ReturnType

获取此方法的返回类型。

(继承自 MethodInfo)
ReturnTypeCustomAttributes

返回此方法的返回类型的自定义属性。

ReturnTypeCustomAttributes

获取返回类型的自定义属性。

(继承自 MethodInfo)
Signature

检索方法的签名。

方法

AddDeclarativeSecurity(SecurityAction, PermissionSet)

向此方法添加声明性安全。

CreateDelegate(Type)

从此方法创建指定类型的委托。

(继承自 MethodInfo)
CreateDelegate(Type, Object)

从此方法创建具有指定目标的指定类型的委托。

(继承自 MethodInfo)
CreateDelegate<T>()

从此方法创建 T 类型的委托。

(继承自 MethodInfo)
CreateDelegate<T>(Object)

从此方法创建具有指定目标的 T 类型的委托。

(继承自 MethodInfo)
CreateMethodBody(Byte[], Int32)

使用 Microsoft 中间语言 (MSIL) 指令提供的字节数组的创建方法的主体。

DefineGenericParameters(String[])

设置当前方法的泛型类型参数的数目,指定其名称并返回一个可用于定义其约束的 GenericTypeParameterBuilder 对象的数组。

DefineGenericParametersCore(String[])

在派生类中重写时,设置当前方法的泛型类型参数数,指定其名称,并返回可用于定义其约束的对象 GenericTypeParameterBuilder 数组。

DefineParameter(Int32, ParameterAttributes, String)

设置参数属性和此方法的参数名称或此方法的返回值的名称。 返回可用于应用自定义属性的 ParameterBuilder。

DefineParameterCore(Int32, ParameterAttributes, String)

在派生类中重写时,定义此方法的参数或返回参数。

Equals(Object)

确定给定对象是否等于此实例。

GetBaseDefinition()

返回方法的基实现。

GetBaseDefinition()

当在派生类中被重写时,为直接或间接的基类(用该实例表示的方法首先在此类中声明)上的方法返回 MethodInfo 对象。

(继承自 MethodInfo)
GetCustomAttributes(Boolean)

返回为此方法定义的所有自定义属性。

GetCustomAttributes(Boolean)

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

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

返回由给定类型标识的自定义属性。

GetCustomAttributes(Type, Boolean)

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

(继承自 MemberInfo)
GetCustomAttributesData()

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

(继承自 MemberInfo)
GetGenericArguments()

返回表示此方法的类型参数的 GenericTypeParameterBuilder 对象数组(如果为泛型)。

GetGenericArguments()

返回 Type 对象的数组,这些对象表示泛型方法的类型实参或泛型方法定义的类型形参。

(继承自 MethodInfo)
GetGenericMethodDefinition()

返回此方法。

GetGenericMethodDefinition()

返回一个 MethodInfo 对象,该对象表示可从其构造当前方法的泛型方法定义。

(继承自 MethodInfo)
GetHashCode()

获取此方法的哈希代码。

GetILGenerator()

为此方法返回默认 Microsoft 中间语言 (MSIL) 流大小为 64 字节的 ILGenerator

GetILGenerator(Int32)

为此方法返回具有指定的 Microsoft 中间语言 (MSIL) 流大小的 ILGenerator

GetILGeneratorCore(Int32)

在派生类中重写时,获取 ILGenerator 可用于发出此方法的方法体的 。

GetMethodBody()

在派生类中重写后,获取 MethodBody 对象,该对象提供对 MSIL 流、局部变量和当前方法的异常的访问。

(继承自 MethodBase)
GetMethodImplementationFlags()

为此方法返回实现标志。

GetMethodImplementationFlags()

在派生的类中重写时,返回 MethodImplAttributes 标志。

(继承自 MethodBase)
GetModule()

返回对包含此方法的模块的引用。

GetParameters()

返回此方法的参数。

GetToken()

返回表示此方法的标记的 MethodToken

GetType()

发现方法的属性并提供对方法元数据的访问。

(继承自 MethodInfo)
HasSameMetadataDefinitionAs(MemberInfo)

定义并表示动态类上的方法(或构造函数)。

(继承自 MemberInfo)
Invoke(Object, BindingFlags, Binder, Object[], CultureInfo)

动态调用方法,此方法由此实例在给定对象上进行反射,传递指定的参数,并受给定绑定器的约束。

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

当在派生类中重写时,调用具有给定参数的反射的方法或构造函数。

(继承自 MethodBase)
Invoke(Object, Object[])

使用指定参数调用由当前实例表示的方法或构造函数。

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

检查是否定义了指定的自定义属性类型。

IsDefined(Type, Boolean)

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

(继承自 MemberInfo)
MakeGenericMethod(Type[])

返回使用指定泛型类型参数从当前泛型方法定义构造的泛型方法。

MakeGenericMethod(Type[])

用类型数组的元素替代当前泛型方法定义的类型参数,并返回表示结果构造方法的 MethodInfo 对象。

(继承自 MethodInfo)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
SetCustomAttribute(ConstructorInfo, Byte[])

使用指定的自定义属性 blob 设置自定义属性。

SetCustomAttribute(CustomAttributeBuilder)

使用自定义属性生成器设置自定义属性。

SetCustomAttributeCore(ConstructorInfo, ReadOnlySpan<Byte>)

在派生类中重写时,在此程序集上设置自定义属性。

SetImplementationFlags(MethodImplAttributes)

为此方法设置实现标志。

SetImplementationFlagsCore(MethodImplAttributes)

在派生类中重写时,设置此方法的实现标志。

SetMarshal(UnmanagedMarshal)
已过时.

设置此方法的返回类型的封送处理信息。

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

通过使用 Microsoft 中间语言 (MSIL) 指令指定的字节数组创建方法的主体。

SetParameters(Type[])

为方法设置参数的数量和类型。

SetReturnType(Type)

设置方法的返回类型。

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

设置方法签名,包括返回类型、参数类型以及返回类型和参数类型所需和可选的自定义修饰符。

SetSignatureCore(Type, Type[], Type[], Type[], Type[][], Type[][])

在派生类中重写时,设置方法签名,包括返回类型、参数类型以及返回类型和参数类型的必需和可选自定义修饰符。

SetSymCustomAttribute(String, Byte[])

使用 blob 设置符号自定义属性。

ToString()

将此 MethodBuilder 实例作为字符串返回。

显式接口实现

_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)
_MethodBase.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

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

(继承自 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)

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

_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)

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

(继承自 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)
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)

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

GetBaseDefinition(MethodInfo)

定义并表示动态类上的方法(或构造函数)。

GetRuntimeBaseDefinition(MethodInfo)

检索表示在此方法最先声明的直接或间接类上的指定方法的对象。

适用于