ConstructorBuilder 类

定义

定义并表示动态类的构造函数。

public ref class ConstructorBuilder sealed : System::Reflection::ConstructorInfo
public ref class ConstructorBuilder abstract : System::Reflection::ConstructorInfo
public ref class ConstructorBuilder sealed : System::Reflection::ConstructorInfo, System::Runtime::InteropServices::_ConstructorBuilder
public sealed class ConstructorBuilder : System.Reflection.ConstructorInfo
public abstract class ConstructorBuilder : System.Reflection.ConstructorInfo
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
public sealed class ConstructorBuilder : System.Reflection.ConstructorInfo, System.Runtime.InteropServices._ConstructorBuilder
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class ConstructorBuilder : System.Reflection.ConstructorInfo, System.Runtime.InteropServices._ConstructorBuilder
type ConstructorBuilder = class
    inherit ConstructorInfo
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
type ConstructorBuilder = class
    inherit ConstructorInfo
    interface _ConstructorBuilder
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type ConstructorBuilder = class
    inherit ConstructorInfo
    interface _ConstructorBuilder
Public NotInheritable Class ConstructorBuilder
Inherits ConstructorInfo
Public MustInherit Class ConstructorBuilder
Inherits ConstructorInfo
Public NotInheritable Class ConstructorBuilder
Inherits ConstructorInfo
Implements _ConstructorBuilder
继承
属性
实现

示例

以下代码示例演示 的上下文用法 ConstructorBuilder

using namespace System;
using namespace System::Threading;
using namespace System::Reflection;
using namespace System::Reflection::Emit;
Type^ DynamicPointTypeGen()
{
   Type^ pointType = nullptr;
   array<Type^>^temp0 = {int::typeid,int::typeid,int::typeid};
   array<Type^>^ctorParams = temp0;
   AppDomain^ myDomain = Thread::GetDomain();
   AssemblyName^ myAsmName = gcnew AssemblyName;
   myAsmName->Name = "MyDynamicAssembly";
   AssemblyBuilder^ myAsmBuilder = myDomain->DefineDynamicAssembly( myAsmName, AssemblyBuilderAccess::RunAndSave );
   ModuleBuilder^ pointModule = myAsmBuilder->DefineDynamicModule( "PointModule", "Point.dll" );
   TypeBuilder^ pointTypeBld = pointModule->DefineType( "Point", TypeAttributes::Public );
   FieldBuilder^ xField = pointTypeBld->DefineField( "x", int::typeid, FieldAttributes::Public );
   FieldBuilder^ yField = pointTypeBld->DefineField( "y", int::typeid, FieldAttributes::Public );
   FieldBuilder^ zField = pointTypeBld->DefineField( "z", int::typeid, FieldAttributes::Public );
   Type^ objType = Type::GetType( "System.Object" );
   ConstructorInfo^ objCtor = objType->GetConstructor( gcnew array<Type^>(0) );
   ConstructorBuilder^ pointCtor = pointTypeBld->DefineConstructor( MethodAttributes::Public, CallingConventions::Standard, ctorParams );
   ILGenerator^ ctorIL = pointCtor->GetILGenerator();
   
   // NOTE: ldarg.0 holds the "this" reference - ldarg.1, ldarg.2, and ldarg.3
   // hold the actual passed parameters. ldarg.0 is used by instance methods
   // to hold a reference to the current calling bject instance. Static methods
   // do not use arg.0, since they are not instantiated and hence no reference
   // is needed to distinguish them.
   ctorIL->Emit( OpCodes::Ldarg_0 );
   
   // Here, we wish to create an instance of System::Object by invoking its
   // constructor, as specified above.
   ctorIL->Emit( OpCodes::Call, objCtor );
   
   // Now, we'll load the current instance in arg 0, along
   // with the value of parameter "x" stored in arg 1, into stfld.
   ctorIL->Emit( OpCodes::Ldarg_0 );
   ctorIL->Emit( OpCodes::Ldarg_1 );
   ctorIL->Emit( OpCodes::Stfld, xField );
   
   // Now, we store arg 2 "y" in the current instance with stfld.
   ctorIL->Emit( OpCodes::Ldarg_0 );
   ctorIL->Emit( OpCodes::Ldarg_2 );
   ctorIL->Emit( OpCodes::Stfld, yField );
   
   // Last of all, arg 3 "z" gets stored in the current instance.
   ctorIL->Emit( OpCodes::Ldarg_0 );
   ctorIL->Emit( OpCodes::Ldarg_3 );
   ctorIL->Emit( OpCodes::Stfld, zField );
   
   // Our work complete, we return.
   ctorIL->Emit( OpCodes::Ret );
   
   // Now, let's create three very simple methods so we can see our fields.
   array<String^>^temp1 = {"GetX","GetY","GetZ"};
   array<String^>^mthdNames = temp1;
   System::Collections::IEnumerator^ myEnum = mthdNames->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      String^ mthdName = safe_cast<String^>(myEnum->Current);
      MethodBuilder^ getFieldMthd = pointTypeBld->DefineMethod( mthdName, MethodAttributes::Public, int::typeid, nullptr );
      ILGenerator^ mthdIL = getFieldMthd->GetILGenerator();
      mthdIL->Emit( OpCodes::Ldarg_0 );
      if ( mthdName->Equals( "GetX" ) )
            mthdIL->Emit( OpCodes::Ldfld, xField );
      else
      if ( mthdName->Equals( "GetY" ) )
            mthdIL->Emit( OpCodes::Ldfld, yField );
      else
      if ( mthdName->Equals( "GetZ" ) )
            mthdIL->Emit( OpCodes::Ldfld, zField );



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

   pointType = pointTypeBld->CreateType();
   
   // Let's save it, just for posterity.
   myAsmBuilder->Save( "Point.dll" );
   return pointType;
}

int main()
{
   Type^ myDynamicType = nullptr;
   Object^ aPoint = nullptr;
   array<Type^>^temp2 = {int::typeid,int::typeid,int::typeid};
   array<Type^>^aPtypes = temp2;
   array<Object^>^temp3 = {4,5,6};
   array<Object^>^aPargs = temp3;
   
   // Call the  method to build our dynamic class.
   myDynamicType = DynamicPointTypeGen();
   Console::WriteLine( "Some information about my new Type '{0}':", myDynamicType->FullName );
   Console::WriteLine( "Assembly: '{0}'", myDynamicType->Assembly );
   Console::WriteLine( "Attributes: '{0}'", myDynamicType->Attributes );
   Console::WriteLine( "Module: '{0}'", myDynamicType->Module );
   Console::WriteLine( "Members: " );
   System::Collections::IEnumerator^ myEnum = myDynamicType->GetMembers()->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      MemberInfo^ member = safe_cast<MemberInfo^>(myEnum->Current);
      Console::WriteLine( "-- {0} {1};", member->MemberType, member->Name );
   }

   Console::WriteLine( "---" );
   
   // Let's take a look at the constructor we created.
   ConstructorInfo^ myDTctor = myDynamicType->GetConstructor( aPtypes );
   Console::WriteLine( "Constructor: {0};", myDTctor );
   Console::WriteLine( "---" );
   
   // Now, we get to use our dynamically-created class by invoking the constructor.
   aPoint = myDTctor->Invoke( aPargs );
   Console::WriteLine( "aPoint is type {0}.", aPoint->GetType() );
   
   // Finally, let's reflect on the instance of our new type - aPoint - and
   // make sure everything proceeded according to plan.
   Console::WriteLine( "aPoint.x = {0}", myDynamicType->InvokeMember( "GetX", BindingFlags::InvokeMethod, nullptr, aPoint, gcnew array<Object^>(0) ) );
   Console::WriteLine( "aPoint.y = {0}", myDynamicType->InvokeMember( "GetY", BindingFlags::InvokeMethod, nullptr, aPoint, gcnew array<Object^>(0) ) );
   Console::WriteLine( "aPoint.z = {0}", myDynamicType->InvokeMember( "GetZ", BindingFlags::InvokeMethod, nullptr, aPoint, gcnew array<Object^>(0) ) );
   
   // +++ OUTPUT +++
   // Some information about my new Type 'Point':
   // Assembly: 'MyDynamicAssembly, Version=0.0.0.0'
   // Attributes: 'AutoLayout, AnsiClass, NotPublic, Public'
   // Module: 'PointModule'
   // Members:
   // -- Field x;
   // -- Field y;
   // -- Field z;
   // -- Method GetHashCode;
   // -- Method Equals;
   // -- Method ToString;
   // -- Method GetType;
   // -- Constructor .ctor;
   // ---
   // Constructor: Void .ctor(Int32, Int32, Int32);
   // ---
   // aPoint is type Point.
   // aPoint.x = 4
   // aPoint.y = 5
   // aPoint.z = 6
}

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

class TestCtorBuilder {

    public static Type DynamicPointTypeGen() {
    
       Type pointType = null;
       Type[] ctorParams = new Type[] {typeof(int),
                        typeof(int),
                        typeof(int)};
    
       AppDomain myDomain = Thread.GetDomain();
       AssemblyName myAsmName = new AssemblyName();
       myAsmName.Name = "MyDynamicAssembly";
    
       AssemblyBuilder myAsmBuilder = myDomain.DefineDynamicAssembly(
                      myAsmName,
                      AssemblyBuilderAccess.RunAndSave);

       ModuleBuilder pointModule = myAsmBuilder.DefineDynamicModule("PointModule",
                                    "Point.dll");

       TypeBuilder pointTypeBld = pointModule.DefineType("Point",
                                      TypeAttributes.Public);

       FieldBuilder xField = pointTypeBld.DefineField("x", typeof(int),
                                                          FieldAttributes.Public);
       FieldBuilder yField = pointTypeBld.DefineField("y", typeof(int),
                                                          FieldAttributes.Public);
       FieldBuilder zField = pointTypeBld.DefineField("z", typeof(int),
                                                          FieldAttributes.Public);

           Type objType = Type.GetType("System.Object");
           ConstructorInfo objCtor = objType.GetConstructor(new Type[0]);

       ConstructorBuilder pointCtor = pointTypeBld.DefineConstructor(
                      MethodAttributes.Public,
                      CallingConventions.Standard,
                      ctorParams);
       ILGenerator ctorIL = pointCtor.GetILGenerator();

       // NOTE: ldarg.0 holds the "this" reference - ldarg.1, ldarg.2, and ldarg.3
       // hold the actual passed parameters. ldarg.0 is used by instance methods
       // to hold a reference to the current calling object instance. Static methods
       // do not use arg.0, since they are not instantiated and hence no reference
       // is needed to distinguish them.

           ctorIL.Emit(OpCodes.Ldarg_0);

       // Here, we wish to create an instance of System.Object by invoking its
       // constructor, as specified above.

           ctorIL.Emit(OpCodes.Call, objCtor);

       // Now, we'll load the current instance ref in arg 0, along
       // with the value of parameter "x" stored in arg 1, into stfld.

           ctorIL.Emit(OpCodes.Ldarg_0);
           ctorIL.Emit(OpCodes.Ldarg_1);
           ctorIL.Emit(OpCodes.Stfld, xField);

       // Now, we store arg 2 "y" in the current instance with stfld.

           ctorIL.Emit(OpCodes.Ldarg_0);
           ctorIL.Emit(OpCodes.Ldarg_2);
           ctorIL.Emit(OpCodes.Stfld, yField);

       // Last of all, arg 3 "z" gets stored in the current instance.

           ctorIL.Emit(OpCodes.Ldarg_0);
           ctorIL.Emit(OpCodes.Ldarg_3);
           ctorIL.Emit(OpCodes.Stfld, zField);

           // Our work complete, we return.

       ctorIL.Emit(OpCodes.Ret);

       // Now, let's create three very simple methods so we can see our fields.

       string[] mthdNames = new string[] {"GetX", "GetY", "GetZ"};

           foreach (string mthdName in mthdNames) {
              MethodBuilder getFieldMthd = pointTypeBld.DefineMethod(
                           mthdName,
                           MethodAttributes.Public,
                                           typeof(int),
                                           null);
          ILGenerator mthdIL = getFieldMthd.GetILGenerator();
    
          mthdIL.Emit(OpCodes.Ldarg_0);
          switch (mthdName) {
             case "GetX": mthdIL.Emit(OpCodes.Ldfld, xField);
                  break;
             case "GetY": mthdIL.Emit(OpCodes.Ldfld, yField);
                  break;
             case "GetZ": mthdIL.Emit(OpCodes.Ldfld, zField);
                  break;
          }
          mthdIL.Emit(OpCodes.Ret);
           }
       // Finally, we create the type.

       pointType = pointTypeBld.CreateType();

       // Let's save it, just for posterity.
    
       myAsmBuilder.Save("Point.dll");
    
       return pointType;
    }

    public static void Main() {
    
       Type myDynamicType = null;
           object aPoint = null;
       Type[] aPtypes = new Type[] {typeof(int), typeof(int), typeof(int)};
           object[] aPargs = new object[] {4, 5, 6};
    
       // Call the  method to build our dynamic class.

       myDynamicType = DynamicPointTypeGen();

       Console.WriteLine("Some information about my new Type '{0}':",
                  myDynamicType.FullName);
       Console.WriteLine("Assembly: '{0}'", myDynamicType.Assembly);
       Console.WriteLine("Attributes: '{0}'", myDynamicType.Attributes);
       Console.WriteLine("Module: '{0}'", myDynamicType.Module);
       Console.WriteLine("Members: ");
       foreach (MemberInfo member in myDynamicType.GetMembers()) {
        Console.WriteLine("-- {0} {1};", member.MemberType, member.Name);
       }

           Console.WriteLine("---");

       // Let's take a look at the constructor we created.

       ConstructorInfo myDTctor = myDynamicType.GetConstructor(aPtypes);
           Console.WriteLine("Constructor: {0};", myDTctor.ToString());

           Console.WriteLine("---");
    
           // Now, we get to use our dynamically-created class by invoking the constructor.

       aPoint = myDTctor.Invoke(aPargs);
           Console.WriteLine("aPoint is type {0}.", aPoint.GetType());

       // Finally, let's reflect on the instance of our new type - aPoint - and
       // make sure everything proceeded according to plan.

       Console.WriteLine("aPoint.x = {0}",
                 myDynamicType.InvokeMember("GetX",
                                BindingFlags.InvokeMethod,
                            null,
                            aPoint,
                            new object[0]));
       Console.WriteLine("aPoint.y = {0}",
                 myDynamicType.InvokeMember("GetY",
                                BindingFlags.InvokeMethod,
                            null,
                            aPoint,
                            new object[0]));
       Console.WriteLine("aPoint.z = {0}",
                 myDynamicType.InvokeMember("GetZ",
                                BindingFlags.InvokeMethod,
                            null,
                            aPoint,
                            new object[0]));

       // +++ OUTPUT +++
       // Some information about my new Type 'Point':
       // Assembly: 'MyDynamicAssembly, Version=0.0.0.0'
       // Attributes: 'AutoLayout, AnsiClass, NotPublic, Public'
       // Module: 'PointModule'
       // Members:
       // -- Field x;
       // -- Field y;
       // -- Field z;
           // -- Method GetHashCode;
           // -- Method Equals;
           // -- Method ToString;
           // -- Method GetType;
           // -- Constructor .ctor;
       // ---
       // Constructor: Void .ctor(Int32, Int32, Int32);
       // ---
       // aPoint is type Point.
       // aPoint.x = 4
       // aPoint.y = 5
       // aPoint.z = 6
    }
}

Imports System.Threading
Imports System.Reflection
Imports System.Reflection.Emit

 _

Class TestCtorBuilder
   
   
   Public Shared Function DynamicPointTypeGen() As Type
      
      Dim pointType As Type = Nothing
      Dim ctorParams() As Type = {GetType(Integer), GetType(Integer), GetType(Integer)}
      
      Dim myDomain As AppDomain = Thread.GetDomain()
      Dim myAsmName As New AssemblyName()
      myAsmName.Name = "MyDynamicAssembly"
      
      Dim myAsmBuilder As AssemblyBuilder = myDomain.DefineDynamicAssembly(myAsmName, AssemblyBuilderAccess.RunAndSave)
      
      Dim pointModule As ModuleBuilder = myAsmBuilder.DefineDynamicModule("PointModule", "Point.dll")
      
      Dim pointTypeBld As TypeBuilder = pointModule.DefineType("Point", TypeAttributes.Public)
      
      Dim xField As FieldBuilder = pointTypeBld.DefineField("x", GetType(Integer), FieldAttributes.Public)
      Dim yField As FieldBuilder = pointTypeBld.DefineField("y", GetType(Integer), FieldAttributes.Public)
      Dim zField As FieldBuilder = pointTypeBld.DefineField("z", GetType(Integer), FieldAttributes.Public)
      
      Dim objType As Type = Type.GetType("System.Object")
      Dim objCtor As ConstructorInfo = objType.GetConstructor(New Type() {})
      
      Dim pointCtor As ConstructorBuilder = pointTypeBld.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, ctorParams)
      Dim ctorIL As ILGenerator = pointCtor.GetILGenerator()
      
      ' NOTE: ldarg.0 holds the "this" reference - ldarg.1, ldarg.2, and ldarg.3
      ' hold the actual passed parameters. ldarg.0 is used by instance methods
      ' to hold a reference to the current calling object instance. Static methods
      ' do not use arg.0, since they are not instantiated and hence no reference
      ' is needed to distinguish them. 
      ctorIL.Emit(OpCodes.Ldarg_0)
      
      ' Here, we wish to create an instance of System.Object by invoking its
      ' constructor, as specified above.
      ctorIL.Emit(OpCodes.Call, objCtor)
      
      ' Now, we'll load the current instance ref in arg 0, along
      ' with the value of parameter "x" stored in arg 1, into stfld.
      ctorIL.Emit(OpCodes.Ldarg_0)
      ctorIL.Emit(OpCodes.Ldarg_1)
      ctorIL.Emit(OpCodes.Stfld, xField)
      
      ' Now, we store arg 2 "y" in the current instance with stfld.
      ctorIL.Emit(OpCodes.Ldarg_0)
      ctorIL.Emit(OpCodes.Ldarg_2)
      ctorIL.Emit(OpCodes.Stfld, yField)
      
      ' Last of all, arg 3 "z" gets stored in the current instance.
      ctorIL.Emit(OpCodes.Ldarg_0)
      ctorIL.Emit(OpCodes.Ldarg_3)
      ctorIL.Emit(OpCodes.Stfld, zField)
      
      ' Our work complete, we return.
      ctorIL.Emit(OpCodes.Ret)
      
      ' Now, let's create three very simple methods so we can see our fields.
      Dim mthdNames() As String = {"GetX", "GetY", "GetZ"}
      
      Dim mthdName As String
      For Each mthdName In  mthdNames
         Dim getFieldMthd As MethodBuilder = pointTypeBld.DefineMethod(mthdName, MethodAttributes.Public, GetType(Integer), Nothing)
         Dim mthdIL As ILGenerator = getFieldMthd.GetILGenerator()
         
         mthdIL.Emit(OpCodes.Ldarg_0)
         Select Case mthdName
            Case "GetX"
               mthdIL.Emit(OpCodes.Ldfld, xField)
            Case "GetY"
               mthdIL.Emit(OpCodes.Ldfld, yField)
            Case "GetZ"
               mthdIL.Emit(OpCodes.Ldfld, zField)
         End Select
         
         mthdIL.Emit(OpCodes.Ret)
      Next mthdName 
      ' Finally, we create the type.
      pointType = pointTypeBld.CreateType()
      
      ' Let's save it, just for posterity.
      myAsmBuilder.Save("Point.dll")
      
      Return pointType
   End Function 'DynamicPointTypeGen
    
   
   Public Shared Sub Main()
      
      Dim myDynamicType As Type = Nothing
      Dim aPoint As Object = Nothing
      Dim aPtypes() As Type = {GetType(Integer), GetType(Integer), GetType(Integer)}
      Dim aPargs() As Object = {4, 5, 6}
      
      ' Call the  method to build our dynamic class.
      myDynamicType = DynamicPointTypeGen()
      
      Console.WriteLine("Some information about my new Type '{0}':", myDynamicType.FullName)
      Console.WriteLine("Assembly: '{0}'", myDynamicType.Assembly)
      Console.WriteLine("Attributes: '{0}'", myDynamicType.Attributes)
      Console.WriteLine("Module: '{0}'", myDynamicType.Module)
      Console.WriteLine("Members: ")
      Dim member As MemberInfo
      For Each member In  myDynamicType.GetMembers()
         Console.WriteLine("-- {0} {1};", member.MemberType, member.Name)
      Next member
      
      Console.WriteLine("---")
      
      ' Let's take a look at the constructor we created.
      Dim myDTctor As ConstructorInfo = myDynamicType.GetConstructor(aPtypes)
      Console.WriteLine("Constructor: {0};", myDTctor.ToString())
      
      Console.WriteLine("---")
      
      ' Now, we get to use our dynamically-created class by invoking the constructor. 
      aPoint = myDTctor.Invoke(aPargs)
      Console.WriteLine("aPoint is type {0}.", aPoint.GetType())
      
      
      ' Finally, let's reflect on the instance of our new type - aPoint - and
      ' make sure everything proceeded according to plan.
      Console.WriteLine("aPoint.x = {0}", myDynamicType.InvokeMember("GetX", BindingFlags.InvokeMethod, Nothing, aPoint, New Object() {}))
      Console.WriteLine("aPoint.y = {0}", myDynamicType.InvokeMember("GetY", BindingFlags.InvokeMethod, Nothing, aPoint, New Object() {}))
      Console.WriteLine("aPoint.z = {0}", myDynamicType.InvokeMember("GetZ", BindingFlags.InvokeMethod, Nothing, aPoint, New Object() {}))
   End Sub
End Class



' +++ OUTPUT +++
' Some information about my new Type 'Point':
' Assembly: 'MyDynamicAssembly, Version=0.0.0.0'
' Attributes: 'AutoLayout, AnsiClass, NotPublic, Public'
' Module: 'PointModule'
' Members: 
' -- Field x;
' -- Field y;
' -- Field z;
' -- Method GetHashCode;
' -- Method Equals;
' -- Method ToString;
' -- Method GetType;
' -- Constructor .ctor;
' ---
' Constructor: Void .ctor(Int32, Int32, Int32);
' ---
' aPoint is type Point.
' aPoint.x = 4
' aPoint.y = 5
' aPoint.z = 6

注解

ConstructorBuilder 用于全面描述 Microsoft 中间语言 (MSIL) 的构造函数,包括名称、属性、签名和构造函数正文。 它与 类结合使用, TypeBuilder 在运行时创建类。 调用 DefineConstructor 以获取 的 ConstructorBuilder实例。

如果未为动态类型定义构造函数,则会自动提供无参数构造函数,并调用基类的无参数构造函数。

如果使用 ConstructorBuilder 为动态类型定义构造函数,则不会提供无参数构造函数。 除了定义的构造函数之外,还可以使用以下选项来提供无参数构造函数:

  • 如果需要一个只调用基类的无参数构造函数的无参数构造函数,可以使用 TypeBuilder.DefineDefaultConstructor 方法创建一个 (,并选择性地限制对它的访问) 。 不要为此无参数构造函数提供实现。 如果这样做,则在尝试使用 构造函数时会引发异常。 调用 方法时 TypeBuilder.CreateType 不会引发异常。

  • 如果你希望无参数构造函数执行的功能不仅仅是调用基类的无参数构造函数,或者调用基类的另一个构造函数,或者完全执行其他操作,则必须使用 TypeBuilder.DefineConstructor 方法创建 一个 ConstructorBuilder,并提供你自己的实现。

构造函数

ConstructorBuilder()

初始化 ConstructorBuilder 类的新实例。

属性

Attributes

获取此构造函数的属性。

CallingConvention

获取一个 CallingConventions 值,该值取决于声明类型是否为泛型。

CallingConvention

获取一个值,该值指示此方法的调用约定。

(继承自 MethodBase)
ContainsGenericParameters

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

(继承自 MethodBase)
CustomAttributes

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

(继承自 MemberInfo)
DeclaringType

获取对声明此成员的类型的 Type 对象的引用。

InitLocals

获取或设置在此构造函数中的本地变量是否应初始化为零。

InitLocalsCore

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

IsAbstract

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

(继承自 MethodBase)
IsAssembly

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

(继承自 MethodBase)
IsCollectible

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

(继承自 MemberInfo)
IsConstructedGenericMethod

定义并表示动态类的构造函数。

(继承自 MethodBase)
IsConstructor

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

(继承自 MethodBase)
IsFamily

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

(继承自 MethodBase)
IsFamilyAndAssembly

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

(继承自 MethodBase)
IsFamilyOrAssembly

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

(继承自 MethodBase)
IsFinal

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

(继承自 MethodBase)
IsGenericMethod

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

(继承自 MethodBase)
IsGenericMethodDefinition

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

(继承自 MethodBase)
IsHideBySig

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

(继承自 MethodBase)
IsPrivate

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

(继承自 MethodBase)
IsPublic

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

(继承自 MethodBase)
IsSecurityCritical

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

(继承自 MethodBase)
IsSecuritySafeCritical

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

(继承自 MethodBase)
IsSecurityTransparent

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

(继承自 MethodBase)
IsSpecialName

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

(继承自 MethodBase)
IsStatic

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

(继承自 MethodBase)
IsVirtual

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

(继承自 MethodBase)
MemberType

获取 MemberTypes 值,该值指示此成员是构造函数。

(继承自 ConstructorInfo)
MetadataToken

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

MetadataToken

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

(继承自 MemberInfo)
MethodHandle

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

MethodHandle

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

(继承自 MethodBase)
MethodImplementationFlags

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

MethodImplementationFlags

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

(继承自 MethodBase)
Module

获取在其中定义此构造函数的动态模块。

Module

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

(继承自 MemberInfo)
Name

检索此构造函数的名称。

ReflectedType

保存对从中获取此对象的 Type 对象的引用。

ReflectedType

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

(继承自 MemberInfo)
ReturnType
已过时.

获取 null

Signature

检索字符串形式的字段的签名。

方法

AddDeclarativeSecurity(SecurityAction, PermissionSet)

将声明性安全添加到此构造函数。

DefineParameter(Int32, ParameterAttributes, String)

定义此构造函数的参数。

DefineParameterCore(Int32, ParameterAttributes, String)

在派生类中重写时,定义此构造函数的参数。

Equals(Object)

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

(继承自 ConstructorInfo)
GetCustomAttributes(Boolean)

返回为此构造函数定义的所有自定义属性。

GetCustomAttributes(Boolean)

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

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

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

GetCustomAttributes(Type, Boolean)

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

(继承自 MemberInfo)
GetCustomAttributesData()

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

(继承自 MemberInfo)
GetGenericArguments()

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

(继承自 MethodBase)
GetHashCode()

返回此实例的哈希代码。

(继承自 ConstructorInfo)
GetILGenerator()

获取此构造函数的 ILGenerator

GetILGenerator(Int32)

获取具有指定 MSIL 流大小的 ILGenerator 对象,它可以用来生成此构造函数的方法体。

GetILGeneratorCore(Int32)

在派生类中重写时,获取 ILGenerator 可用于为此构造函数发出方法主体的 。

GetMethodBody()

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

(继承自 MethodBase)
GetMethodImplementationFlags()

返回此构造函数的方法实现标志。

GetMethodImplementationFlags()

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

(继承自 MethodBase)
GetModule()

返回包含此构造函数的模块的引用。

GetParameters()

返回此构造函数的参数。

GetToken()

返回表示此构造函数的标记的 MethodToken

GetType()

发现类构造函数的属性,并提供对构造函数元数据的访问权限。

(继承自 ConstructorInfo)
HasSameMetadataDefinitionAs(MemberInfo)

定义并表示动态类的构造函数。

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

动态调用由给定对象上的此实例所表示的构造函数,一并传递指定的参数,并受给定绑定器的约束。

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

在派生类中实现时,在指定 Binder 的约束下调用具有指定参数的此 ConstructorInfo 所反映的构造函数。

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

在指定 Binder 的约束下,用指定的参数动态调用此实例反射的构造函数。

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

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

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

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

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

调用由具有指定参数的实例反映的构造函数,为不常用的参数提供默认值。

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

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

IsDefined(Type, Boolean)

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

(继承自 MemberInfo)
MemberwiseClone()

创建当前 Object 的浅表副本。

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

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

SetCustomAttribute(CustomAttributeBuilder)

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

SetCustomAttributeCore(ConstructorInfo, ReadOnlySpan<Byte>)

在派生类中重写时,在此构造函数上设置自定义属性。

SetImplementationFlags(MethodImplAttributes)

设置此构造函数的方法实现标志。

SetImplementationFlagsCore(MethodImplAttributes)

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

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

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

SetSymCustomAttribute(String, Byte[])

设置此构造函数与符号信息关联的自定义属性。

ToString()

将此 ConstructorBuilder 实例作为 String 返回。

显式接口实现

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

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

_ConstructorBuilder.GetTypeInfo(UInt32, UInt32, IntPtr)

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

_ConstructorBuilder.GetTypeInfoCount(UInt32)

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

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

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

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

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

(继承自 ConstructorInfo)
_ConstructorInfo.GetType()

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

(继承自 ConstructorInfo)
_ConstructorInfo.GetTypeInfo(UInt32, UInt32, IntPtr)

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

(继承自 ConstructorInfo)
_ConstructorInfo.GetTypeInfoCount(UInt32)

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

(继承自 ConstructorInfo)
_ConstructorInfo.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

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

(继承自 ConstructorInfo)
_ConstructorInfo.Invoke_2(Object, BindingFlags, Binder, Object[], CultureInfo)

为 COM 对象提供对 Invoke(Object, BindingFlags, Binder, Object[], CultureInfo) 方法的与版本无关的访问。

(继承自 ConstructorInfo)
_ConstructorInfo.Invoke_3(Object, Object[])

为 COM 对象提供对 Invoke(Object, Object[]) 方法的与版本无关的访问。

(继承自 ConstructorInfo)
_ConstructorInfo.Invoke_4(BindingFlags, Binder, Object[], CultureInfo)

为 COM 对象提供对 Invoke(BindingFlags, Binder, Object[], CultureInfo) 方法的与版本无关的访问。

(继承自 ConstructorInfo)
_ConstructorInfo.Invoke_5(Object[])

为 COM 对象提供对 Invoke(Object[]) 方法的与版本无关的访问。

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

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

适用于