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 是否描述此方法或建構函式 (Constructor) 的潛在可視性;亦即,最多只有相同組件 (Assembly) 中的其他型別可以看見該方法或建構函式,組件外部的衍生型別 (Derived Type) 則看不見它們。

(繼承來源 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

取得值,指出這個成員是否為私用的 (Private)。

(繼承來源 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

取得方法內部中繼資料 (Metadata) 表示的控制代碼。

(繼承來源 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)

取得 ILGenerator 具有指定的 MSIL 資料流大小的物件,可以用來建置此建構函式的方法主體。

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)

在衍生類別中實作時,請叫用在指定 ConstructorInfo 條件約束 (Constraint) 下有指定引數的這個 Binder 所反映的建構函式。

(繼承來源 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 Intermediate Language (MSIL) 指令的指定位元組陣列,建立建構函式的主體。

SetSymCustomAttribute(String, Byte[])

設定此建構函式之與符號資訊相關聯的自訂屬性。

ToString()

傳回這個 ConstructorBuilder 執行個體做為 String

明確介面實作

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

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

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

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

(繼承來源 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)

將一組名稱對應至一組對應的分派識別項 (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)
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)

傳回值,指出所指定成員是否有可用的中繼資料語彙基元。

適用於