TypeBuilder 类

定义

在运行时定义并创建类的新实例。

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

示例

下面的代码示例演示如何定义和使用动态程序集。 示例程序集包含一个类型 , MyDynamicType该类型具有一个私有字段、一个获取和设置私有字段的属性、初始化私有字段的构造函数,以及一个将用户提供的数字乘以私有字段值并返回结果的方法。

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

void main()
{
    // This code creates an assembly that contains one type,
    // named "MyDynamicType", that has a private field, a property
    // that gets and sets the private field, constructors that
    // initialize the private field, and a method that multiplies
    // a user-supplied number by the private field value and returns
    // the result. In Visual C++ the type might look like this:
    /*
      public ref class MyDynamicType
      {
      private:
          int m_number;

      public:
          MyDynamicType() : m_number(42) {};
          MyDynamicType(int initNumber) : m_number(initNumber) {};
      
          property int Number
          {
              int get() { return m_number; }
              void set(int value) { m_number = value; }
          }

          int MyMethod(int multiplier)
          {
              return m_number * multiplier;
          }
      };
    */
      
    AssemblyName^ aName = gcnew AssemblyName("DynamicAssemblyExample");
    AssemblyBuilder^ ab = 
        AssemblyBuilder::DefineDynamicAssembly(
            aName, 
            AssemblyBuilderAccess::Run);

    // The module name is usually the same as the assembly name
    ModuleBuilder^ mb = 
        ab->DefineDynamicModule(aName->Name);
      
    TypeBuilder^ tb = mb->DefineType(
        "MyDynamicType", 
         TypeAttributes::Public);

    // Add a private field of type int (Int32).
    FieldBuilder^ fbNumber = tb->DefineField(
        "m_number", 
        int::typeid, 
        FieldAttributes::Private);

    // Define a constructor that takes an integer argument and 
    // stores it in the private field. 
    array<Type^>^ parameterTypes = { int::typeid };
    ConstructorBuilder^ ctor1 = tb->DefineConstructor(
        MethodAttributes::Public, 
        CallingConventions::Standard, 
        parameterTypes);

    ILGenerator^ ctor1IL = ctor1->GetILGenerator();
    // For a constructor, argument zero is a reference to the new
    // instance. Push it on the stack before calling the base
    // class constructor. Specify the default constructor of the 
    // base class (System::Object) by passing an empty array of 
    // types (Type::EmptyTypes) to GetConstructor.
    ctor1IL->Emit(OpCodes::Ldarg_0);
    ctor1IL->Emit(OpCodes::Call, 
        Object::typeid->GetConstructor(Type::EmptyTypes));
    // Push the instance on the stack before pushing the argument
    // that is to be assigned to the private field m_number.
    ctor1IL->Emit(OpCodes::Ldarg_0);
    ctor1IL->Emit(OpCodes::Ldarg_1);
    ctor1IL->Emit(OpCodes::Stfld, fbNumber);
    ctor1IL->Emit(OpCodes::Ret);

    // Define a default constructor that supplies a default value
    // for the private field. For parameter types, pass the empty
    // array of types or pass nullptr.
    ConstructorBuilder^ ctor0 = tb->DefineConstructor(
        MethodAttributes::Public, 
        CallingConventions::Standard, 
        Type::EmptyTypes);

    ILGenerator^ ctor0IL = ctor0->GetILGenerator();
    ctor0IL->Emit(OpCodes::Ldarg_0);
    ctor0IL->Emit(OpCodes::Call, 
        Object::typeid->GetConstructor(Type::EmptyTypes));
    // For a constructor, argument zero is a reference to the new
    // instance. Push it on the stack before pushing the default
    // value on the stack.
    ctor0IL->Emit(OpCodes::Ldarg_0);
    ctor0IL->Emit(OpCodes::Ldc_I4_S, 42);
    ctor0IL->Emit(OpCodes::Stfld, fbNumber);
    ctor0IL->Emit(OpCodes::Ret);

    // Define a property named Number that gets and sets the private 
    // field.
    //
    // The last argument of DefineProperty is nullptr, because the
    // property has no parameters. (If you don't specify nullptr, you must
    // specify an array of Type objects. For a parameterless property,
    // use the built-in array with no elements: Type::EmptyTypes)
    PropertyBuilder^ pbNumber = tb->DefineProperty(
        "Number", 
        PropertyAttributes::HasDefault, 
        int::typeid, 
        nullptr);
      
    // The property "set" and property "get" methods require a special
    // set of attributes.
    MethodAttributes getSetAttr = MethodAttributes::Public | 
        MethodAttributes::SpecialName | MethodAttributes::HideBySig;

    // Define the "get" accessor method for Number. The method returns
    // an integer and has no arguments. (Note that nullptr could be 
    // used instead of Types::EmptyTypes)
    MethodBuilder^ mbNumberGetAccessor = tb->DefineMethod(
        "get_Number", 
        getSetAttr, 
        int::typeid, 
        Type::EmptyTypes);
      
    ILGenerator^ numberGetIL = mbNumberGetAccessor->GetILGenerator();
    // For an instance property, argument zero is the instance. Load the 
    // instance, then load the private field and return, leaving the
    // field value on the stack.
    numberGetIL->Emit(OpCodes::Ldarg_0);
    numberGetIL->Emit(OpCodes::Ldfld, fbNumber);
    numberGetIL->Emit(OpCodes::Ret);
    
    // Define the "set" accessor method for Number, which has no return
    // type and takes one argument of type int (Int32).
    MethodBuilder^ mbNumberSetAccessor = tb->DefineMethod(
        "set_Number", 
        getSetAttr, 
        nullptr, 
        gcnew array<Type^> { int::typeid });
      
    ILGenerator^ numberSetIL = mbNumberSetAccessor->GetILGenerator();
    // Load the instance and then the numeric argument, then store the
    // argument in the field.
    numberSetIL->Emit(OpCodes::Ldarg_0);
    numberSetIL->Emit(OpCodes::Ldarg_1);
    numberSetIL->Emit(OpCodes::Stfld, fbNumber);
    numberSetIL->Emit(OpCodes::Ret);
      
    // Last, map the "get" and "set" accessor methods to the 
    // PropertyBuilder. The property is now complete. 
    pbNumber->SetGetMethod(mbNumberGetAccessor);
    pbNumber->SetSetMethod(mbNumberSetAccessor);

    // Define a method that accepts an integer argument and returns
    // the product of that integer and the private field m_number. This
    // time, the array of parameter types is created on the fly.
    MethodBuilder^ meth = tb->DefineMethod(
        "MyMethod", 
        MethodAttributes::Public, 
        int::typeid, 
        gcnew array<Type^> { int::typeid });

    ILGenerator^ methIL = meth->GetILGenerator();
    // To retrieve the private instance field, load the instance it
    // belongs to (argument zero). After loading the field, load the 
    // argument one and then multiply. Return from the method with 
    // the return value (the product of the two numbers) on the 
    // execution stack.
    methIL->Emit(OpCodes::Ldarg_0);
    methIL->Emit(OpCodes::Ldfld, fbNumber);
    methIL->Emit(OpCodes::Ldarg_1);
    methIL->Emit(OpCodes::Mul);
    methIL->Emit(OpCodes::Ret);

    // Finish the type->
    Type^ t = tb->CreateType();

    // Because AssemblyBuilderAccess includes Run, the code can be
    // executed immediately. Start by getting reflection objects for
    // the method and the property.
    MethodInfo^ mi = t->GetMethod("MyMethod");
    PropertyInfo^ pi = t->GetProperty("Number");
  
    // Create an instance of MyDynamicType using the default 
    // constructor. 
    Object^ o1 = Activator::CreateInstance(t);

    // Display the value of the property, then change it to 127 and 
    // display it again. Use nullptr to indicate that the property
    // has no index.
    Console::WriteLine("o1->Number: {0}", pi->GetValue(o1, nullptr));
    pi->SetValue(o1, 127, nullptr);
    Console::WriteLine("o1->Number: {0}", pi->GetValue(o1, nullptr));

    // Call MyMethod, passing 22, and display the return value, 22
    // times 127. Arguments must be passed as an array, even when
    // there is only one.
    array<Object^>^ arguments = { 22 };
    Console::WriteLine("o1->MyMethod(22): {0}", 
        mi->Invoke(o1, arguments));

    // Create an instance of MyDynamicType using the constructor
    // that specifies m_Number. The constructor is identified by
    // matching the types in the argument array. In this case, 
    // the argument array is created on the fly. Display the 
    // property value.
    Object^ o2 = Activator::CreateInstance(t, 
        gcnew array<Object^> { 5280 });
    Console::WriteLine("o2->Number: {0}", pi->GetValue(o2, nullptr));
};

/* This code produces the following output:

o1->Number: 42
o1->Number: 127
o1->MyMethod(22): 2794
o2->Number: 5280
 */
using System;
using System.Reflection;
using System.Reflection.Emit;

class DemoAssemblyBuilder
{
    public static void Main()
    {
        // This code creates an assembly that contains one type,
        // named "MyDynamicType", that has a private field, a property
        // that gets and sets the private field, constructors that
        // initialize the private field, and a method that multiplies
        // a user-supplied number by the private field value and returns
        // the result. In C# the type might look like this:
        /*
        public class MyDynamicType
        {
            private int m_number;

            public MyDynamicType() : this(42) {}
            public MyDynamicType(int initNumber)
            {
                m_number = initNumber;
            }

            public int Number
            {
                get { return m_number; }
                set { m_number = value; }
            }

            public int MyMethod(int multiplier)
            {
                return m_number * multiplier;
            }
        }
        */

        var aName = new AssemblyName("DynamicAssemblyExample");
        AssemblyBuilder ab =
            AssemblyBuilder.DefineDynamicAssembly(
                aName,
                AssemblyBuilderAccess.Run);

        // The module name is usually the same as the assembly name.
        ModuleBuilder mb = ab.DefineDynamicModule(aName.Name ?? "DynamicAssemblyExample");

        TypeBuilder tb = mb.DefineType(
            "MyDynamicType",
             TypeAttributes.Public);

        // Add a private field of type int (Int32).
        FieldBuilder fbNumber = tb.DefineField(
            "m_number",
            typeof(int),
            FieldAttributes.Private);

        // Define a constructor that takes an integer argument and
        // stores it in the private field.
        Type[] parameterTypes = { typeof(int) };
        ConstructorBuilder ctor1 = tb.DefineConstructor(
            MethodAttributes.Public,
            CallingConventions.Standard,
            parameterTypes);

        ILGenerator ctor1IL = ctor1.GetILGenerator();
        // For a constructor, argument zero is a reference to the new
        // instance. Push it on the stack before calling the base
        // class constructor. Specify the default constructor of the
        // base class (System.Object) by passing an empty array of
        // types (Type.EmptyTypes) to GetConstructor.
        ctor1IL.Emit(OpCodes.Ldarg_0);
        ConstructorInfo? ci = typeof(object).GetConstructor(Type.EmptyTypes);
        ctor1IL.Emit(OpCodes.Call, ci!);
        // Push the instance on the stack before pushing the argument
        // that is to be assigned to the private field m_number.
        ctor1IL.Emit(OpCodes.Ldarg_0);
        ctor1IL.Emit(OpCodes.Ldarg_1);
        ctor1IL.Emit(OpCodes.Stfld, fbNumber);
        ctor1IL.Emit(OpCodes.Ret);

        // Define a default constructor that supplies a default value
        // for the private field. For parameter types, pass the empty
        // array of types or pass null.
        ConstructorBuilder ctor0 = tb.DefineConstructor(
            MethodAttributes.Public,
            CallingConventions.Standard,
            Type.EmptyTypes);

        ILGenerator ctor0IL = ctor0.GetILGenerator();
        // For a constructor, argument zero is a reference to the new
        // instance. Push it on the stack before pushing the default
        // value on the stack, then call constructor ctor1.
        ctor0IL.Emit(OpCodes.Ldarg_0);
        ctor0IL.Emit(OpCodes.Ldc_I4_S, 42);
        ctor0IL.Emit(OpCodes.Call, ctor1);
        ctor0IL.Emit(OpCodes.Ret);

        // Define a property named Number that gets and sets the private
        // field.
        //
        // The last argument of DefineProperty is null, because the
        // property has no parameters. (If you don't specify null, you must
        // specify an array of Type objects. For a parameterless property,
        // use the built-in array with no elements: Type.EmptyTypes)
        PropertyBuilder pbNumber = tb.DefineProperty(
            "Number",
            PropertyAttributes.HasDefault,
            typeof(int),
            null);

        // The property "set" and property "get" methods require a special
        // set of attributes.
        MethodAttributes getSetAttr = MethodAttributes.Public |
            MethodAttributes.SpecialName | MethodAttributes.HideBySig;

        // Define the "get" accessor method for Number. The method returns
        // an integer and has no arguments. (Note that null could be
        // used instead of Types.EmptyTypes)
        MethodBuilder mbNumberGetAccessor = tb.DefineMethod(
            "get_Number",
            getSetAttr,
            typeof(int),
            Type.EmptyTypes);

        ILGenerator numberGetIL = mbNumberGetAccessor.GetILGenerator();
        // For an instance property, argument zero is the instance. Load the
        // instance, then load the private field and return, leaving the
        // field value on the stack.
        numberGetIL.Emit(OpCodes.Ldarg_0);
        numberGetIL.Emit(OpCodes.Ldfld, fbNumber);
        numberGetIL.Emit(OpCodes.Ret);

        // Define the "set" accessor method for Number, which has no return
        // type and takes one argument of type int (Int32).
        MethodBuilder mbNumberSetAccessor = tb.DefineMethod(
            "set_Number",
            getSetAttr,
            null,
            new Type[] { typeof(int) });

        ILGenerator numberSetIL = mbNumberSetAccessor.GetILGenerator();
        // Load the instance and then the numeric argument, then store the
        // argument in the field.
        numberSetIL.Emit(OpCodes.Ldarg_0);
        numberSetIL.Emit(OpCodes.Ldarg_1);
        numberSetIL.Emit(OpCodes.Stfld, fbNumber);
        numberSetIL.Emit(OpCodes.Ret);

        // Last, map the "get" and "set" accessor methods to the
        // PropertyBuilder. The property is now complete.
        pbNumber.SetGetMethod(mbNumberGetAccessor);
        pbNumber.SetSetMethod(mbNumberSetAccessor);

        // Define a method that accepts an integer argument and returns
        // the product of that integer and the private field m_number. This
        // time, the array of parameter types is created on the fly.
        MethodBuilder meth = tb.DefineMethod(
            "MyMethod",
            MethodAttributes.Public,
            typeof(int),
            new Type[] { typeof(int) });

        ILGenerator methIL = meth.GetILGenerator();
        // To retrieve the private instance field, load the instance it
        // belongs to (argument zero). After loading the field, load the
        // argument one and then multiply. Return from the method with
        // the return value (the product of the two numbers) on the
        // execution stack.
        methIL.Emit(OpCodes.Ldarg_0);
        methIL.Emit(OpCodes.Ldfld, fbNumber);
        methIL.Emit(OpCodes.Ldarg_1);
        methIL.Emit(OpCodes.Mul);
        methIL.Emit(OpCodes.Ret);

        // Finish the type.
        Type? t = tb.CreateType();

        // Because AssemblyBuilderAccess includes Run, the code can be
        // executed immediately. Start by getting reflection objects for
        // the method and the property.
        MethodInfo? mi = t?.GetMethod("MyMethod");
        PropertyInfo? pi = t?.GetProperty("Number");

        // Create an instance of MyDynamicType using the default
        // constructor.
        object? o1 = null;
        if (t is not null)
            o1 = Activator.CreateInstance(t);

        // Display the value of the property, then change it to 127 and
        // display it again. Use null to indicate that the property
        // has no index.
        Console.WriteLine("o1.Number: {0}", pi?.GetValue(o1, null));
        pi?.SetValue(o1, 127, null);
        Console.WriteLine("o1.Number: {0}", pi?.GetValue(o1, null));

        // Call MyMethod, passing 22, and display the return value, 22
        // times 127. Arguments must be passed as an array, even when
        // there is only one.
        object[] arguments = { 22 };
        Console.WriteLine("o1.MyMethod(22): {0}",
            mi?.Invoke(o1, arguments));

        // Create an instance of MyDynamicType using the constructor
        // that specifies m_Number. The constructor is identified by
        // matching the types in the argument array. In this case,
        // the argument array is created on the fly. Display the
        // property value.
        object? o2 = null;
        if (t is not null)
            Activator.CreateInstance(t, new object[] { 5280 });
        Console.WriteLine("o2.Number: {0}", pi?.GetValue(o2, null));
    }
}

/* This code produces the following output:

o1.Number: 42
o1.Number: 127
o1.MyMethod(22): 2794
o2.Number: 5280
 */
Imports System.Reflection
Imports System.Reflection.Emit

Class DemoAssemblyBuilder

    Public Shared Sub Main()

        ' This code creates an assembly that contains one type,
        ' named "MyDynamicType", that has a private field, a property
        ' that gets and sets the private field, constructors that
        ' initialize the private field, and a method that multiplies
        ' a user-supplied number by the private field value and returns
        ' the result. The code might look like this in Visual Basic:
        '
        'Public Class MyDynamicType
        '    Private m_number As Integer
        '
        '    Public Sub New()
        '        Me.New(42)
        '    End Sub
        '
        '    Public Sub New(ByVal initNumber As Integer)
        '        m_number = initNumber
        '    End Sub
        '
        '    Public Property Number As Integer
        '        Get
        '            Return m_number
        '        End Get
        '        Set
        '            m_Number = Value
        '        End Set
        '    End Property
        '
        '    Public Function MyMethod(ByVal multiplier As Integer) As Integer
        '        Return m_Number * multiplier
        '    End Function
        'End Class
      
        Dim aName As New AssemblyName("DynamicAssemblyExample")
        Dim ab As AssemblyBuilder = _
            AssemblyBuilder.DefineDynamicAssembly( _
                aName, _
                AssemblyBuilderAccess.Run)

        ' The module name is usually the same as the assembly name.
        Dim mb As ModuleBuilder = ab.DefineDynamicModule( _
            aName.Name)
      
        Dim tb As TypeBuilder = _
            mb.DefineType("MyDynamicType", TypeAttributes.Public)

        ' Add a private field of type Integer (Int32).
        Dim fbNumber As FieldBuilder = tb.DefineField( _
            "m_number", _
            GetType(Integer), _
            FieldAttributes.Private)

        ' Define a constructor that takes an integer argument and 
        ' stores it in the private field. 
        Dim parameterTypes() As Type = { GetType(Integer) }
        Dim ctor1 As ConstructorBuilder = _
            tb.DefineConstructor( _
                MethodAttributes.Public, _
                CallingConventions.Standard, _
                parameterTypes)

        Dim ctor1IL As ILGenerator = ctor1.GetILGenerator()
        ' For a constructor, argument zero is a reference to the new
        ' instance. Push it on the stack before calling the base
        ' class constructor. Specify the default constructor of the 
        ' base class (System.Object) by passing an empty array of 
        ' types (Type.EmptyTypes) to GetConstructor.
        ctor1IL.Emit(OpCodes.Ldarg_0)
        ctor1IL.Emit(OpCodes.Call, _
            GetType(Object).GetConstructor(Type.EmptyTypes))
        ' Push the instance on the stack before pushing the argument
        ' that is to be assigned to the private field m_number.
        ctor1IL.Emit(OpCodes.Ldarg_0)
        ctor1IL.Emit(OpCodes.Ldarg_1)
        ctor1IL.Emit(OpCodes.Stfld, fbNumber)
        ctor1IL.Emit(OpCodes.Ret)

        ' Define a default constructor that supplies a default value
        ' for the private field. For parameter types, pass the empty
        ' array of types or pass Nothing.
        Dim ctor0 As ConstructorBuilder = tb.DefineConstructor( _
            MethodAttributes.Public, _
            CallingConventions.Standard, _
            Type.EmptyTypes)

        Dim ctor0IL As ILGenerator = ctor0.GetILGenerator()
        ' For a constructor, argument zero is a reference to the new
        ' instance. Push it on the stack before pushing the default
        ' value on the stack, then call constructor ctor1.
        ctor0IL.Emit(OpCodes.Ldarg_0)
        ctor0IL.Emit(OpCodes.Ldc_I4_S, 42)
        ctor0IL.Emit(OpCodes.Call, ctor1)
        ctor0IL.Emit(OpCodes.Ret)

        ' Define a property named Number that gets and sets the private 
        ' field.
        '
        ' The last argument of DefineProperty is Nothing, because the
        ' property has no parameters. (If you don't specify Nothing, you must
        ' specify an array of Type objects. For a parameterless property,
        ' use the built-in array with no elements: Type.EmptyTypes)
        Dim pbNumber As PropertyBuilder = tb.DefineProperty( _
            "Number", _
            PropertyAttributes.HasDefault, _
            GetType(Integer), _
            Nothing)
      
        ' The property Set and property Get methods require a special
        ' set of attributes.
        Dim getSetAttr As MethodAttributes = _
            MethodAttributes.Public Or MethodAttributes.SpecialName _
                Or MethodAttributes.HideBySig

        ' Define the "get" accessor method for Number. The method returns
        ' an integer and has no arguments. (Note that Nothing could be 
        ' used instead of Types.EmptyTypes)
        Dim mbNumberGetAccessor As MethodBuilder = tb.DefineMethod( _
            "get_Number", _
            getSetAttr, _
            GetType(Integer), _
            Type.EmptyTypes)
      
        Dim numberGetIL As ILGenerator = mbNumberGetAccessor.GetILGenerator()
        ' For an instance property, argument zero is the instance. Load the 
        ' instance, then load the private field and return, leaving the
        ' field value on the stack.
        numberGetIL.Emit(OpCodes.Ldarg_0)
        numberGetIL.Emit(OpCodes.Ldfld, fbNumber)
        numberGetIL.Emit(OpCodes.Ret)
        
        ' Define the "set" accessor method for Number, which has no return
        ' type and takes one argument of type Integer (Int32).
        Dim mbNumberSetAccessor As MethodBuilder = _
            tb.DefineMethod( _
                "set_Number", _
                getSetAttr, _
                Nothing, _
                New Type() { GetType(Integer) })
      
        Dim numberSetIL As ILGenerator = mbNumberSetAccessor.GetILGenerator()
        ' Load the instance and then the numeric argument, then store the
        ' argument in the field.
        numberSetIL.Emit(OpCodes.Ldarg_0)
        numberSetIL.Emit(OpCodes.Ldarg_1)
        numberSetIL.Emit(OpCodes.Stfld, fbNumber)
        numberSetIL.Emit(OpCodes.Ret)
      
        ' Last, map the "get" and "set" accessor methods to the 
        ' PropertyBuilder. The property is now complete. 
        pbNumber.SetGetMethod(mbNumberGetAccessor)
        pbNumber.SetSetMethod(mbNumberSetAccessor)

        ' Define a method that accepts an integer argument and returns
        ' the product of that integer and the private field m_number. This
        ' time, the array of parameter types is created on the fly.
        Dim meth As MethodBuilder = tb.DefineMethod( _
            "MyMethod", _
            MethodAttributes.Public, _
            GetType(Integer), _
            New Type() { GetType(Integer) })

        Dim methIL As ILGenerator = meth.GetILGenerator()
        ' To retrieve the private instance field, load the instance it
        ' belongs to (argument zero). After loading the field, load the 
        ' argument one and then multiply. Return from the method with 
        ' the return value (the product of the two numbers) on the 
        ' execution stack.
        methIL.Emit(OpCodes.Ldarg_0)
        methIL.Emit(OpCodes.Ldfld, fbNumber)
        methIL.Emit(OpCodes.Ldarg_1)
        methIL.Emit(OpCodes.Mul)
        methIL.Emit(OpCodes.Ret)

        ' Finish the type.
        Dim t As Type = tb.CreateType()

        ' Because AssemblyBuilderAccess includes Run, the code can be
        ' executed immediately. Start by getting reflection objects for
        ' the method and the property.
        Dim mi As MethodInfo = t.GetMethod("MyMethod")
        Dim pi As PropertyInfo = t.GetProperty("Number")
  
        ' Create an instance of MyDynamicType using the default 
        ' constructor. 
        Dim o1 As Object = Activator.CreateInstance(t)

        ' Display the value of the property, then change it to 127 and 
        ' display it again. Use Nothing to indicate that the property
        ' has no index.
        Console.WriteLine("o1.Number: {0}", pi.GetValue(o1, Nothing))
        pi.SetValue(o1, 127, Nothing)
        Console.WriteLine("o1.Number: {0}", pi.GetValue(o1, Nothing))

        ' Call MyMethod, passing 22, and display the return value, 22
        ' times 127. Arguments must be passed as an array, even when
        ' there is only one.
        Dim arguments() As Object = { 22 }
        Console.WriteLine("o1.MyMethod(22): {0}", _
            mi.Invoke(o1, arguments))

        ' Create an instance of MyDynamicType using the constructor
        ' that specifies m_Number. The constructor is identified by
        ' matching the types in the argument array. In this case, 
        ' the argument array is created on the fly. Display the 
        ' property value.
        Dim o2 As Object = Activator.CreateInstance(t, _
            New Object() { 5280 })
        Console.WriteLine("o2.Number: {0}", pi.GetValue(o2, Nothing))
      
    End Sub  
End Class

' This code produces the following output:
'
'o1.Number: 42
'o1.Number: 127
'o1.MyMethod(22): 2794
'o2.Number: 5280

下面的代码示例演示如何使用 TypeBuilder动态生成类型。

using namespace System;
using namespace System::Threading;
using namespace System::Reflection;
using namespace System::Reflection::Emit;
Type^ DynamicDotProductGen()
{
   Type^ ivType = nullptr;
   array<Type^>^temp0 = {int::typeid,int::typeid,int::typeid};
   array<Type^>^ctorParams = temp0;
   AppDomain^ myDomain = Thread::GetDomain();
   AssemblyName^ myAsmName = gcnew AssemblyName;
   myAsmName->Name = "IntVectorAsm";
   AssemblyBuilder^ myAsmBuilder = myDomain->DefineDynamicAssembly( myAsmName, AssemblyBuilderAccess::RunAndSave );
   ModuleBuilder^ IntVectorModule = myAsmBuilder->DefineDynamicModule( "IntVectorModule", "Vector.dll" );
   TypeBuilder^ ivTypeBld = IntVectorModule->DefineType( "IntVector", TypeAttributes::Public );
   FieldBuilder^ xField = ivTypeBld->DefineField( "x", int::typeid, FieldAttributes::Private );
   FieldBuilder^ yField = ivTypeBld->DefineField( "y", int::typeid, FieldAttributes::Private );
   FieldBuilder^ zField = ivTypeBld->DefineField( "z", int::typeid, FieldAttributes::Private );
   Type^ objType = Type::GetType( "System.Object" );
   ConstructorInfo^ objCtor = objType->GetConstructor( gcnew array<Type^>(0) );
   ConstructorBuilder^ ivCtor = ivTypeBld->DefineConstructor( MethodAttributes::Public, CallingConventions::Standard, ctorParams );
   ILGenerator^ ctorIL = ivCtor->GetILGenerator();
   ctorIL->Emit( OpCodes::Ldarg_0 );
   ctorIL->Emit( OpCodes::Call, objCtor );
   ctorIL->Emit( OpCodes::Ldarg_0 );
   ctorIL->Emit( OpCodes::Ldarg_1 );
   ctorIL->Emit( OpCodes::Stfld, xField );
   ctorIL->Emit( OpCodes::Ldarg_0 );
   ctorIL->Emit( OpCodes::Ldarg_2 );
   ctorIL->Emit( OpCodes::Stfld, yField );
   ctorIL->Emit( OpCodes::Ldarg_0 );
   ctorIL->Emit( OpCodes::Ldarg_3 );
   ctorIL->Emit( OpCodes::Stfld, zField );
   ctorIL->Emit( OpCodes::Ret );
   
   // This method will find the dot product of the stored vector
   // with another.
   array<Type^>^temp1 = {ivTypeBld};
   array<Type^>^dpParams = temp1;
   
   // Here, you create a MethodBuilder containing the
   // name, the attributes (public, static, private, and so on),
   // the return type (int, in this case), and a array of Type
   // indicating the type of each parameter. Since the sole parameter
   // is a IntVector, the very class you're creating, you will
   // pass in the TypeBuilder (which is derived from Type) instead of
   // a Type object for IntVector, avoiding an exception.
   // -- This method would be declared in C# as:
   //    public int DotProduct(IntVector aVector)
   MethodBuilder^ dotProductMthd = ivTypeBld->DefineMethod( "DotProduct", MethodAttributes::Public, int::typeid, dpParams );
   
   // A ILGenerator can now be spawned, attached to the MethodBuilder.
   ILGenerator^ mthdIL = dotProductMthd->GetILGenerator();
   
   // Here's the body of our function, in MSIL form. We're going to find the
   // "dot product" of the current vector instance with the passed vector
   // instance. For reference purposes, the equation is:
   // (x1 * x2) + (y1 * y2) + (z1 * z2) = the dot product
   // First, you'll load the reference to the current instance "this"
   // stored in argument 0 (ldarg.0) onto the stack. Ldfld, the subsequent
   // instruction, will pop the reference off the stack and look up the
   // field "x", specified by the FieldInfo token "xField".
   mthdIL->Emit( OpCodes::Ldarg_0 );
   mthdIL->Emit( OpCodes::Ldfld, xField );
   
   // That completed, the value stored at field "x" is now atop the stack.
   // Now, you'll do the same for the Object reference we passed as a
   // parameter, stored in argument 1 (ldarg.1). After Ldfld executed,
   // you'll have the value stored in field "x" for the passed instance
   // atop the stack.
   mthdIL->Emit( OpCodes::Ldarg_1 );
   mthdIL->Emit( OpCodes::Ldfld, xField );
   
   // There will now be two values atop the stack - the "x" value for the
   // current vector instance, and the "x" value for the passed instance.
   // You'll now multiply them, and push the result onto the evaluation stack.
   mthdIL->Emit( OpCodes::Mul_Ovf_Un );
   
   // Now, repeat this for the "y" fields of both vectors.
   mthdIL->Emit( OpCodes::Ldarg_0 );
   mthdIL->Emit( OpCodes::Ldfld, yField );
   mthdIL->Emit( OpCodes::Ldarg_1 );
   mthdIL->Emit( OpCodes::Ldfld, yField );
   mthdIL->Emit( OpCodes::Mul_Ovf_Un );
   
   // At this time, the results of both multiplications should be atop
   // the stack. You'll now add them and push the result onto the stack.
   mthdIL->Emit( OpCodes::Add_Ovf_Un );
   
   // Multiply both "z" field and push the result onto the stack.
   mthdIL->Emit( OpCodes::Ldarg_0 );
   mthdIL->Emit( OpCodes::Ldfld, zField );
   mthdIL->Emit( OpCodes::Ldarg_1 );
   mthdIL->Emit( OpCodes::Ldfld, zField );
   mthdIL->Emit( OpCodes::Mul_Ovf_Un );
   
   // Finally, add the result of multiplying the "z" fields with the
   // result of the earlier addition, and push the result - the dot product -
   // onto the stack.
   mthdIL->Emit( OpCodes::Add_Ovf_Un );
   
   // The "ret" opcode will pop the last value from the stack and return it
   // to the calling method. You're all done!
   mthdIL->Emit( OpCodes::Ret );
   ivType = ivTypeBld->CreateType();
   return ivType;
}

int main()
{
   Type^ IVType = nullptr;
   Object^ aVector1 = nullptr;
   Object^ aVector2 = nullptr;
   array<Type^>^temp2 = {int::typeid,int::typeid,int::typeid};
   array<Type^>^aVtypes = temp2;
   array<Object^>^temp3 = {10,10,10};
   array<Object^>^aVargs1 = temp3;
   array<Object^>^temp4 = {20,20,20};
   array<Object^>^aVargs2 = temp4;
   
   // Call the  method to build our dynamic class.
   IVType = DynamicDotProductGen();
   Console::WriteLine( "---" );
   ConstructorInfo^ myDTctor = IVType->GetConstructor( aVtypes );
   aVector1 = myDTctor->Invoke( aVargs1 );
   aVector2 = myDTctor->Invoke( aVargs2 );
   array<Object^>^passMe = gcnew array<Object^>(1);
   passMe[ 0 ] = dynamic_cast<Object^>(aVector2);
   Console::WriteLine( "(10, 10, 10) . (20, 20, 20) = {0}", IVType->InvokeMember( "DotProduct", BindingFlags::InvokeMethod, nullptr, aVector1, passMe ) );
}

// +++ OUTPUT +++
// ---
// (10, 10, 10) . (20, 20, 20) = 600
using System;
using System.Threading;
using System.Reflection;
using System.Reflection.Emit;

class TestILGenerator
{
    public static Type DynamicDotProductGen()
    {
       Type ivType = null;
       Type[] ctorParams = new Type[] { typeof(int),
                                typeof(int),
                        typeof(int)};
    
       AppDomain myDomain = Thread.GetDomain();
       AssemblyName myAsmName = new AssemblyName();
       myAsmName.Name = "IntVectorAsm";
    
       AssemblyBuilder myAsmBuilder = myDomain.DefineDynamicAssembly(
                      myAsmName,
                      AssemblyBuilderAccess.RunAndSave);

       ModuleBuilder IntVectorModule = myAsmBuilder.DefineDynamicModule("IntVectorModule",
                                        "Vector.dll");

       TypeBuilder ivTypeBld = IntVectorModule.DefineType("IntVector",
                                      TypeAttributes.Public);

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

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

       ConstructorBuilder ivCtor = ivTypeBld.DefineConstructor(
                      MethodAttributes.Public,
                      CallingConventions.Standard,
                      ctorParams);
       ILGenerator ctorIL = ivCtor.GetILGenerator();
           ctorIL.Emit(OpCodes.Ldarg_0);
           ctorIL.Emit(OpCodes.Call, objCtor);
           ctorIL.Emit(OpCodes.Ldarg_0);
           ctorIL.Emit(OpCodes.Ldarg_1);
           ctorIL.Emit(OpCodes.Stfld, xField);
           ctorIL.Emit(OpCodes.Ldarg_0);
           ctorIL.Emit(OpCodes.Ldarg_2);
           ctorIL.Emit(OpCodes.Stfld, yField);
           ctorIL.Emit(OpCodes.Ldarg_0);
           ctorIL.Emit(OpCodes.Ldarg_3);
           ctorIL.Emit(OpCodes.Stfld, zField);
       ctorIL.Emit(OpCodes.Ret);

       // This method will find the dot product of the stored vector
       // with another.

       Type[] dpParams = new Type[] { ivTypeBld };

           // Here, you create a MethodBuilder containing the
       // name, the attributes (public, static, private, and so on),
       // the return type (int, in this case), and a array of Type
       // indicating the type of each parameter. Since the sole parameter
       // is a IntVector, the very class you're creating, you will
       // pass in the TypeBuilder (which is derived from Type) instead of
       // a Type object for IntVector, avoiding an exception.

       // -- This method would be declared in C# as:
       //    public int DotProduct(IntVector aVector)

           MethodBuilder dotProductMthd = ivTypeBld.DefineMethod(
                                  "DotProduct",
                          MethodAttributes.Public,
                                          typeof(int),
                                          dpParams);

       // A ILGenerator can now be spawned, attached to the MethodBuilder.

       ILGenerator mthdIL = dotProductMthd.GetILGenerator();
    
       // Here's the body of our function, in MSIL form. We're going to find the
       // "dot product" of the current vector instance with the passed vector
       // instance. For reference purposes, the equation is:
       // (x1 * x2) + (y1 * y2) + (z1 * z2) = the dot product

       // First, you'll load the reference to the current instance "this"
       // stored in argument 0 (ldarg.0) onto the stack. Ldfld, the subsequent
       // instruction, will pop the reference off the stack and look up the
       // field "x", specified by the FieldInfo token "xField".

       mthdIL.Emit(OpCodes.Ldarg_0);
       mthdIL.Emit(OpCodes.Ldfld, xField);

       // That completed, the value stored at field "x" is now atop the stack.
       // Now, you'll do the same for the object reference we passed as a
       // parameter, stored in argument 1 (ldarg.1). After Ldfld executed,
       // you'll have the value stored in field "x" for the passed instance
       // atop the stack.

       mthdIL.Emit(OpCodes.Ldarg_1);
       mthdIL.Emit(OpCodes.Ldfld, xField);

           // There will now be two values atop the stack - the "x" value for the
       // current vector instance, and the "x" value for the passed instance.
       // You'll now multiply them, and push the result onto the evaluation stack.

       mthdIL.Emit(OpCodes.Mul_Ovf_Un);

       // Now, repeat this for the "y" fields of both vectors.

       mthdIL.Emit(OpCodes.Ldarg_0);
       mthdIL.Emit(OpCodes.Ldfld, yField);
       mthdIL.Emit(OpCodes.Ldarg_1);
       mthdIL.Emit(OpCodes.Ldfld, yField);
       mthdIL.Emit(OpCodes.Mul_Ovf_Un);

       // At this time, the results of both multiplications should be atop
       // the stack. You'll now add them and push the result onto the stack.

       mthdIL.Emit(OpCodes.Add_Ovf_Un);

       // Multiply both "z" field and push the result onto the stack.
       mthdIL.Emit(OpCodes.Ldarg_0);
       mthdIL.Emit(OpCodes.Ldfld, zField);
       mthdIL.Emit(OpCodes.Ldarg_1);
       mthdIL.Emit(OpCodes.Ldfld, zField);
       mthdIL.Emit(OpCodes.Mul_Ovf_Un);

       // Finally, add the result of multiplying the "z" fields with the
       // result of the earlier addition, and push the result - the dot product -
       // onto the stack.
       mthdIL.Emit(OpCodes.Add_Ovf_Un);

       // The "ret" opcode will pop the last value from the stack and return it
       // to the calling method. You're all done!

       mthdIL.Emit(OpCodes.Ret);

       ivType = ivTypeBld.CreateType();

       return ivType;
    }

    public static void Main() {
    
       Type IVType = null;
           object aVector1 = null;
           object aVector2 = null;
       Type[] aVtypes = new Type[] {typeof(int), typeof(int), typeof(int)};
           object[] aVargs1 = new object[] {10, 10, 10};
           object[] aVargs2 = new object[] {20, 20, 20};
    
       // Call the  method to build our dynamic class.

       IVType = DynamicDotProductGen();

           Console.WriteLine("---");

       ConstructorInfo myDTctor = IVType.GetConstructor(aVtypes);
       aVector1 = myDTctor.Invoke(aVargs1);
       aVector2 = myDTctor.Invoke(aVargs2);

       object[] passMe = new object[1];
           passMe[0] = (object)aVector2;

       Console.WriteLine("(10, 10, 10) . (20, 20, 20) = {0}",
                 IVType.InvokeMember("DotProduct",
                          BindingFlags.InvokeMethod,
                          null,
                          aVector1,
                          passMe));

       // +++ OUTPUT +++
       // ---
       // (10, 10, 10) . (20, 20, 20) = 600
    }
}
Imports System.Threading
Imports System.Reflection
Imports System.Reflection.Emit

 _


Class TestILGenerator
   
   
   Public Shared Function DynamicDotProductGen() As Type
      
      Dim ivType 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 = "IntVectorAsm"
      
      Dim myAsmBuilder As AssemblyBuilder = myDomain.DefineDynamicAssembly( _
                        myAsmName, _
                        AssemblyBuilderAccess.RunAndSave)
      
      Dim IntVectorModule As ModuleBuilder = myAsmBuilder.DefineDynamicModule( _
                         "IntVectorModule", _
                         "Vector.dll")
      
      Dim ivTypeBld As TypeBuilder = IntVectorModule.DefineType("IntVector", TypeAttributes.Public)
      
      Dim xField As FieldBuilder = ivTypeBld.DefineField("x", _
                                 GetType(Integer), _
                                 FieldAttributes.Private)
      Dim yField As FieldBuilder = ivTypeBld.DefineField("y", _ 
                                 GetType(Integer), _
                                 FieldAttributes.Private)
      Dim zField As FieldBuilder = ivTypeBld.DefineField("z", _
                                 GetType(Integer), _
                                 FieldAttributes.Private)
      
      
      Dim objType As Type = Type.GetType("System.Object")
      Dim objCtor As ConstructorInfo = objType.GetConstructor(New Type() {})
      
      Dim ivCtor As ConstructorBuilder = ivTypeBld.DefineConstructor( _
                     MethodAttributes.Public, _
                     CallingConventions.Standard, _
                     ctorParams)
      Dim ctorIL As ILGenerator = ivCtor.GetILGenerator()
      ctorIL.Emit(OpCodes.Ldarg_0)
      ctorIL.Emit(OpCodes.Call, objCtor)
      ctorIL.Emit(OpCodes.Ldarg_0)
      ctorIL.Emit(OpCodes.Ldarg_1)
      ctorIL.Emit(OpCodes.Stfld, xField)
      ctorIL.Emit(OpCodes.Ldarg_0)
      ctorIL.Emit(OpCodes.Ldarg_2)
      ctorIL.Emit(OpCodes.Stfld, yField)
      ctorIL.Emit(OpCodes.Ldarg_0)
      ctorIL.Emit(OpCodes.Ldarg_3)
      ctorIL.Emit(OpCodes.Stfld, zField)
      ctorIL.Emit(OpCodes.Ret)
     

      ' Now, you'll construct the method find the dot product of two vectors. First,
      ' let's define the parameters that will be accepted by the method. In this case,
      ' it's an IntVector itself!

      Dim dpParams() As Type = {ivTypeBld}
      
      ' Here, you create a MethodBuilder containing the
      ' name, the attributes (public, static, private, and so on),
      ' the return type (int, in this case), and a array of Type
      ' indicating the type of each parameter. Since the sole parameter
      ' is a IntVector, the very class you're creating, you will
      ' pass in the TypeBuilder (which is derived from Type) instead of 
      ' a Type object for IntVector, avoiding an exception. 
      ' -- This method would be declared in VB.NET as:
      '    Public Function DotProduct(IntVector aVector) As Integer

      Dim dotProductMthd As MethodBuilder = ivTypeBld.DefineMethod("DotProduct", _
                        MethodAttributes.Public, GetType(Integer), _
                                            dpParams)
      
      ' A ILGenerator can now be spawned, attached to the MethodBuilder.
      Dim mthdIL As ILGenerator = dotProductMthd.GetILGenerator()
      
      ' Here's the body of our function, in MSIL form. We're going to find the
      ' "dot product" of the current vector instance with the passed vector 
      ' instance. For reference purposes, the equation is:
      ' (x1 * x2) + (y1 * y2) + (z1 * z2) = the dot product
      ' First, you'll load the reference to the current instance "this"
      ' stored in argument 0 (ldarg.0) onto the stack. Ldfld, the subsequent
      ' instruction, will pop the reference off the stack and look up the
      ' field "x", specified by the FieldInfo token "xField".
      mthdIL.Emit(OpCodes.Ldarg_0)
      mthdIL.Emit(OpCodes.Ldfld, xField)
      
      ' That completed, the value stored at field "x" is now atop the stack.
      ' Now, you'll do the same for the object reference we passed as a
      ' parameter, stored in argument 1 (ldarg.1). After Ldfld executed,
      ' you'll have the value stored in field "x" for the passed instance
      ' atop the stack.
      mthdIL.Emit(OpCodes.Ldarg_1)
      mthdIL.Emit(OpCodes.Ldfld, xField)
      
      ' There will now be two values atop the stack - the "x" value for the
      ' current vector instance, and the "x" value for the passed instance.
      ' You'll now multiply them, and push the result onto the evaluation stack.
      mthdIL.Emit(OpCodes.Mul_Ovf_Un)
      
      ' Now, repeat this for the "y" fields of both vectors.
      mthdIL.Emit(OpCodes.Ldarg_0)
      mthdIL.Emit(OpCodes.Ldfld, yField)
      mthdIL.Emit(OpCodes.Ldarg_1)
      mthdIL.Emit(OpCodes.Ldfld, yField)
      mthdIL.Emit(OpCodes.Mul_Ovf_Un)
      
      ' At this time, the results of both multiplications should be atop
      ' the stack. You'll now add them and push the result onto the stack.
      mthdIL.Emit(OpCodes.Add_Ovf_Un)
      
      ' Multiply both "z" field and push the result onto the stack.
      mthdIL.Emit(OpCodes.Ldarg_0)
      mthdIL.Emit(OpCodes.Ldfld, zField)
      mthdIL.Emit(OpCodes.Ldarg_1)
      mthdIL.Emit(OpCodes.Ldfld, zField)
      mthdIL.Emit(OpCodes.Mul_Ovf_Un)
      
      ' Finally, add the result of multiplying the "z" fields with the
      ' result of the earlier addition, and push the result - the dot product -
      ' onto the stack.
      mthdIL.Emit(OpCodes.Add_Ovf_Un)
      
      ' The "ret" opcode will pop the last value from the stack and return it
      ' to the calling method. You're all done!
      mthdIL.Emit(OpCodes.Ret)
      
      
      ivType = ivTypeBld.CreateType()
      
      Return ivType
   End Function 'DynamicDotProductGen
    
   
   Public Shared Sub Main()
      
      Dim IVType As Type = Nothing
      Dim aVector1 As Object = Nothing
      Dim aVector2 As Object = Nothing
      Dim aVtypes() As Type = {GetType(Integer), GetType(Integer), GetType(Integer)}
      Dim aVargs1() As Object = {10, 10, 10}
      Dim aVargs2() As Object = {20, 20, 20}
      
      ' Call the  method to build our dynamic class.
      IVType = DynamicDotProductGen()
      
      
      Dim myDTctor As ConstructorInfo = IVType.GetConstructor(aVtypes)
      aVector1 = myDTctor.Invoke(aVargs1)
      aVector2 = myDTctor.Invoke(aVargs2)
      
      Console.WriteLine("---")
      Dim passMe(0) As Object
      passMe(0) = CType(aVector2, Object)
      
      Console.WriteLine("(10, 10, 10) . (20, 20, 20) = {0}", _
                        IVType.InvokeMember("DotProduct", BindingFlags.InvokeMethod, _
                        Nothing, aVector1, passMe))
   End Sub
End Class



' +++ OUTPUT +++
' ---
' (10, 10, 10) . (20, 20, 20) = 600

注解

有关此 API 的详细信息,请参阅 TypeBuilder 的补充 API 备注

构造函数

TypeBuilder()

初始化 TypeBuilder 类的新实例。

字段

UnspecifiedTypeSize

表示未指定类型的总大小。

属性

Assembly

检索包含此类型定义的动态程序集。

AssemblyQualifiedName

返回由程序集的显示名称限定的此类型的全名。

Attributes

在运行时定义并创建类的新实例。

Attributes

获取与 Type 关联的属性。

(继承自 Type)
Attributes

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
BaseType

检索此类型的基类型。

ContainsGenericParameters

在运行时定义并创建类的新实例。

ContainsGenericParameters

获取一个值,该值指示当前 Type 对象是否具有尚未被特定类型替代的类型参数。

(继承自 Type)
ContainsGenericParameters

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
CustomAttributes

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

(继承自 MemberInfo)
DeclaredConstructors

获取由当前类型声明的构造函数的集合。

(继承自 TypeInfo)
DeclaredEvents

获取由当前类型定义的事件的集合。

(继承自 TypeInfo)
DeclaredFields

获取由当前类型定义的字段的集合。

(继承自 TypeInfo)
DeclaredMembers

获取由当前类型定义的成员的集合。

(继承自 TypeInfo)
DeclaredMethods

获取由当前类型定义的方法的集合。

(继承自 TypeInfo)
DeclaredNestedTypes

获取由当前类型定义的嵌套类型的集合。

(继承自 TypeInfo)
DeclaredProperties

获取由当前类型定义的属性的集合。

(继承自 TypeInfo)
DeclaringMethod

获取声明了当前泛型类型参数的方法。

DeclaringMethod

获取一个表示声明方法的 MethodBase(如果当前 Type 表示泛型方法的一个类型参数)。

(继承自 Type)
DeclaringType

返回声明此类型的类型。

FullName

检索此类型的完整路径。

GenericParameterAttributes

获取一个值,该值指示当前泛型类型参数的协变和特殊约束。

GenericParameterAttributes

获取描述当前泛型类型参数的协变和特殊约束的 GenericParameterAttributes 标志。

(继承自 Type)
GenericParameterPosition

获取声明参数的泛型类型的类型参数列表中的类型参数位置。

GenericParameterPosition

Type 对象表示泛型类型或泛型方法的类型参数时,获取类型参数在声明它的泛型类型或方法的类型参数列表中的位置。

(继承自 Type)
GenericTypeArguments

在运行时定义并创建类的新实例。

GenericTypeArguments

获取此类型泛型类型参数的数组。

(继承自 Type)
GenericTypeArguments

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GenericTypeParameters

获取当前实例泛型类型参数的数组。

(继承自 TypeInfo)
GUID

检索此类型的 GUID。

HasElementType

获取一个值,通过该值指示当前 Type 是包含还是引用另一类型,即当前 Type 是数组、指针还是通过引用传递。

(继承自 Type)
HasElementType

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
ImplementedInterfaces

获取当前类型实现的接口的集合。

(继承自 TypeInfo)
IsAbstract

获取一个值,通过该值指示 Type 是否为抽象的并且必须被重写。

(继承自 Type)
IsAbstract

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsAnsiClass

获取一个值,该值指示是否为 AnsiClass 选择了字符串格式属性 Type

(继承自 Type)
IsAnsiClass

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsArray

获取一个值,该值指示类型是否为数组。

(继承自 Type)
IsArray

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsAutoClass

获取一个值,该值指示是否为 AutoClass 选择了字符串格式属性 Type

(继承自 Type)
IsAutoClass

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsAutoLayout

获取指示当前类型的字段是否由公共语言运行时自动放置的值。

(继承自 Type)
IsAutoLayout

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsByRef

获取一个值,该值指示 Type 是否由引用传递。

(继承自 Type)
IsByRef

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsByRefLike

获取一个值,该值指示类型是否是与 byref 类似的结构。

IsByRefLike

获取一个值,该值指示类型是否是与 byref 类似的结构。

(继承自 Type)
IsClass

获取一个值,通过该值指示 Type 是否是一个类或委托;即,不是值类型或接口。

(继承自 Type)
IsClass

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsCollectible

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

(继承自 MemberInfo)
IsCOMObject

获取一个值,通过该值指示 Type 是否为 COM 对象。

(继承自 Type)
IsCOMObject

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsConstructedGenericType

获取指示此对象是否表示构造的泛型类型的值。

IsConstructedGenericType

获取指示此对象是否表示构造的泛型类型的值。 你可以创建构造型泛型类型的实例。

(继承自 Type)
IsContextful

获取一个值,通过该值指示 Type 在上下文中是否可以被承载。

(继承自 Type)
IsEnum

在运行时定义并创建类的新实例。

IsEnum

获取一个值,该值指示当前的 Type 是否表示枚举。

(继承自 Type)
IsEnum

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsExplicitLayout

获取指示当前类型的字段是否放置在显式指定的偏移量处的值。

(继承自 Type)
IsExplicitLayout

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsFunctionPointer

获取一个值,该值指示当前 Type 是否为函数指针。

(继承自 Type)
IsGenericMethodParameter

获取一个值,该值指示当前 Type 是否表示泛型方法定义中的类型参数。

(继承自 Type)
IsGenericParameter

获取一个值,该值指示当前类型是否是泛型类型参数。

IsGenericParameter

获取一个值,该值指示当前 Type 是否表示泛型类型或方法的定义中的类型参数。

(继承自 Type)
IsGenericType

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

IsGenericType

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

(继承自 Type)
IsGenericTypeDefinition

获取一个值,该值指示当前 TypeBuilder 是否表示可以用来构造其他泛型类型的泛型类型定义。

IsGenericTypeDefinition

获取一个值,该值指示当前 Type 是否表示可以用来构造其他泛型类型的泛型类型定义。

(继承自 Type)
IsGenericTypeParameter

获取一个值,该值指示当前 Type 是否表示泛型类型定义中的类型参数。

(继承自 Type)
IsImport

获取一个值,该值指示 Type 是否应用了 ComImportAttribute 属性,如果应用了该属性,则表示它是从 COM 类型库导入的。

(继承自 Type)
IsImport

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsInterface

获取一个值,通过该值指示 Type 是否是一个接口;即,不是类或值类型。

(继承自 Type)
IsInterface

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsLayoutSequential

获取指示当前类型的字段是否按顺序(定义顺序或发送到元数据的顺序)放置的值。

(继承自 Type)
IsLayoutSequential

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsMarshalByRef

获取一个值,该值指示 Type 是否按引用进行封送。

(继承自 Type)
IsMarshalByRef

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsNested

获取一个指示当前 Type 对象是否表示其定义嵌套在另一个类型的定义之内的类型的值。

(继承自 Type)
IsNested

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsNestedAssembly

获取一个值,通过该值指示 Type 是否是嵌套的并且只能在它自己的程序集内可见。

(继承自 Type)
IsNestedAssembly

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsNestedFamANDAssem

获取一个值,通过该值指示 Type 是否是嵌套的并且只对同时属于自己家族和自己程序集的类可见。

(继承自 Type)
IsNestedFamANDAssem

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsNestedFamily

获取一个值,通过该值指示 Type 是否是嵌套的并且只能在它自己的家族内可见。

(继承自 Type)
IsNestedFamily

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsNestedFamORAssem

获取一个值,通过该值指示 Type 是否是嵌套的并且只对属于它自己的家族或属于它自己的程序集的类可见。

(继承自 Type)
IsNestedFamORAssem

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsNestedPrivate

获取一个值,通过该值指示 Type 是否是嵌套的并声明为私有。

(继承自 Type)
IsNestedPrivate

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsNestedPublic

获取一个值,通过该值指示类是否是嵌套的并且声明为公共的。

(继承自 Type)
IsNestedPublic

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsNotPublic

获取一个值,该值指示 Type 是否声明为公共类型。

(继承自 Type)
IsNotPublic

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsPointer

获取一个值,通过该值指示 Type 是否为指针。

(继承自 Type)
IsPointer

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsPrimitive

获取一个值,通过该值指示 Type 是否为基元类型之一。

(继承自 Type)
IsPrimitive

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsPublic

获取一个值,该值指示 Type 是否声明为公共类型。

(继承自 Type)
IsPublic

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsSealed

获取一个值,该值指示 Type 是否声明为密封的。

(继承自 Type)
IsSealed

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsSecurityCritical

获取一个值,该值指示当前类型是安全-关键的还是安全-可靠-关键的,且因此是否可执行关键操作。

IsSecurityCritical

获取一个值,该值指示当前的类型在当前信任级别上是安全关键的还是安全可靠关键的,并因此可以执行关键操作。

(继承自 Type)
IsSecuritySafeCritical

获取一个值,该值指示当前类型是否为安全-可靠-关键,即它是否可执行关键操作且可由透明代码访问。

IsSecuritySafeCritical

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

(继承自 Type)
IsSecurityTransparent

获取一个值,该值指示当前类型是否透明,且因此是否无法指定关键操作。

IsSecurityTransparent

获取一个值,该值指示当前类型在当前信任级别上是否是透明的而无法执行关键操作。

(继承自 Type)
IsSerializable

在运行时定义并创建类的新实例。

IsSerializable
已过时.

获取一个值, Type 该值指示 是否可进行二进制序列化。

(继承自 Type)
IsSerializable

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsSignatureType

获取一个值,该值指示类型是否是签名类型。

(继承自 Type)
IsSpecialName

获取一个值,该值指示该类型是否具有需要特殊处理的名称。

(继承自 Type)
IsSpecialName

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsSZArray

在运行时定义并创建类的新实例。

IsSZArray

获取一个值,该值指示类型是否是仅可表示下限为零的一维数组的数组类型。

(继承自 Type)
IsTypeDefinition

在运行时定义并创建类的新实例。

IsTypeDefinition

获取一个值,该值指示类型是否是类型定义。

(继承自 Type)
IsUnicodeClass

获取一个值,该值指示是否为 UnicodeClass 选择了字符串格式属性 Type

(继承自 Type)
IsUnicodeClass

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsUnmanagedFunctionPointer

获取一个值,该值指示当前 Type 是否为非托管函数指针。

(继承自 Type)
IsValueType

获取一个值,通过该值指示 Type 是否为值类型。

(继承自 Type)
IsValueType

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsVariableBoundArray

在运行时定义并创建类的新实例。

IsVariableBoundArray

获取一个值,该值指示类型是否是可表示多维数组或具有任意下限的数组的数组类型。

(继承自 Type)
IsVisible

获取一个指示 Type 是否可由程序集之外的代码访问的值。

(继承自 Type)
IsVisible

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
MemberType

获取一个指示此成员是类型还是嵌套类型的 MemberTypes 值。

(继承自 Type)
MemberType

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
MetadataToken

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

MetadataToken

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

(继承自 MemberInfo)
Module

检索包含此类型定义的动态模块。

Name

检索此类型的名称。

Namespace

检索定义了此 TypeBuilder 的命名空间。

PackingSize

检索此类型的包装大小。

PackingSizeCore

在派生类中重写时,获取此类型的打包大小。

ReflectedType

返回用于获取此类型的类型。

ReflectedType

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

(继承自 MemberInfo)
Size

检索类型的总大小。

SizeCore

在派生类中重写时,获取类型的总大小。

StructLayoutAttribute

获取一个描述当前类型的布局的 StructLayoutAttribute

(继承自 Type)
StructLayoutAttribute

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
TypeHandle

不支持动态模块。

TypeInitializer

获取该类型的初始值设定项。

(继承自 Type)
TypeInitializer

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
TypeToken

返回此类型的类型标记。

UnderlyingSystemType

返回此 TypeBuilder 的基础系统类型。

UnderlyingSystemType

在运行时定义并创建类的新实例。

(继承自 TypeInfo)

方法

AddDeclarativeSecurity(SecurityAction, PermissionSet)

将声明性安全添加到此类型。

AddInterfaceImplementation(Type)

添加一个此类型实现的接口。

AddInterfaceImplementationCore(Type)

在派生类中重写时,添加此类型实现的接口。

AsType()

返回 Type 对象形式的当前类型。

(继承自 TypeInfo)
CreateType()

创建类的 Type 对象。 定义了类的字段和方法后,调用 CreateType 以加载其 Type 对象。

CreateTypeInfo()

获取一个表示此类型的 TypeInfo 对象。

CreateTypeInfoCore()

在派生类中重写时,获取表示 TypeInfo 此类型的 对象。

DefineConstructor(MethodAttributes, CallingConventions, Type[])

用给定的属性和签名,向类型中添加新的构造函数。

DefineConstructor(MethodAttributes, CallingConventions, Type[], Type[][], Type[][])

将新构造函数添加到该类型,其属性、签名和自定义修饰符已给定。

DefineConstructorCore(MethodAttributes, CallingConventions, Type[], Type[][], Type[][])

在派生类中重写时,使用给定的属性、签名和自定义修饰符向类型添加新构造函数。

DefineDefaultConstructor(MethodAttributes)

定义无参数构造函数。 在此处定义的构造函数将只调用父类的无参数构造函数。

DefineDefaultConstructorCore(MethodAttributes)

在派生类中重写时,定义无参数构造函数。 此处定义的构造函数调用父级的无参数构造函数。

DefineEvent(String, EventAttributes, Type)

将新事件添加到该类型,使用给定的名称、属性和事件类型。

DefineEventCore(String, EventAttributes, Type)

在派生类中重写时,将具有给定名称、属性和事件类型的新事件添加到类型。

DefineField(String, Type, FieldAttributes)

将新字段添加到该类型,其名称、属性和字段类型已给定。

DefineField(String, Type, Type[], Type[], FieldAttributes)

将新字段添加到该类型,其名称、属性、字段类型和自定义修饰符已给定。

DefineFieldCore(String, Type, Type[], Type[], FieldAttributes)

在派生类中重写时,将具有给定名称、属性、字段类型和自定义修饰符的新字段添加到类型。

DefineGenericParameters(String[])

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

DefineGenericParametersCore(String[])

在派生类中重写时,定义当前类型的泛型类型参数,并指定其编号和名称。

DefineInitializedData(String, Byte[], FieldAttributes)

在可移植可执行 (PE) 文件的 .sdata 部分定义已初始化的数据字段。

DefineInitializedDataCore(String, Byte[], FieldAttributes)

在派生类中重写时,在可移植可执行文件 (PE) 文件的 .sdata 节中定义初始化的数据字段。

DefineMethod(String, MethodAttributes)

向此类型添加新方法,使用指定的名称和方法属性。

DefineMethod(String, MethodAttributes, CallingConventions)

将具有指定的名称、 方法属性和调用约定的新方法添加到此类型。

DefineMethod(String, MethodAttributes, CallingConventions, Type, Type[])

使用指定的名称、方法属性、调用约定和方法签名向类型中添加新方法。

DefineMethod(String, MethodAttributes, CallingConventions, Type, Type[], Type[], Type[], Type[][], Type[][])

使用指定名称、方法属性、调用约定、方法签名和自定义修饰符向类型中添加新方法。

DefineMethod(String, MethodAttributes, Type, Type[])

向此类型添加新方法,并指定方法的名称、 属性和签名。

DefineMethodCore(String, MethodAttributes, CallingConventions, Type, Type[], Type[], Type[], Type[][], Type[][])

在派生类中重写时,将具有指定名称、方法属性、调用约定、方法签名和自定义修饰符的新方法添加到类型。

DefineMethodOverride(MethodInfo, MethodInfo)

指定实现给定方法声明的给定方法体(可能使用其他名称)。

DefineMethodOverrideCore(MethodInfo, MethodInfo)

在派生类中重写时,指定实现给定方法声明(可能具有不同名称)的给定方法主体。

DefineNestedType(String)

定义嵌套的类型,并给定其名称。

DefineNestedType(String, TypeAttributes)

已知名称和属性,定义嵌套类型。

DefineNestedType(String, TypeAttributes, Type)

定义嵌套类型,其名称、属性以及它所扩展的类型已给定。

DefineNestedType(String, TypeAttributes, Type, Int32)

定义嵌套类型,其名称、属性、该类型的总大小以及它所扩展的类型已给定。

DefineNestedType(String, TypeAttributes, Type, PackingSize)

定义嵌套类型,其名称、属性、它所扩展的类型以及封装大小已给定。

DefineNestedType(String, TypeAttributes, Type, PackingSize, Int32)

定义嵌套类型,指定其名称、 属性、 大小和它所扩展的类型。

DefineNestedType(String, TypeAttributes, Type, Type[])

定义嵌套类型,其名称、属性、它所扩展的类型以及它所实现的接口已给定。

DefineNestedTypeCore(String, TypeAttributes, Type, Type[], PackingSize, Int32)

在派生类中重写时,定义嵌套类型,给定其名称、属性、大小及其扩展的类型。

DefinePInvokeMethod(String, String, MethodAttributes, CallingConventions, Type, Type[], CallingConvention, CharSet)

定义 PInvoke 方法,指定方法的名称、定义方法所使用的 DLL 的名称、方法的属性、方法的调用约定、 方法的返回类型、 方法的参数类型,以及 PInvoke 标志。

DefinePInvokeMethod(String, String, String, MethodAttributes, CallingConventions, Type, Type[], CallingConvention, CharSet)

定义 PInvoke 方法,指定方法的名称、定义方法所使用的 DLL 的名称、入口点名称、 方法的属性、方法的调用约定、 方法的返回类型、 方法的参数类型,以及 PInvoke 标志。

DefinePInvokeMethod(String, String, String, MethodAttributes, CallingConventions, Type, Type[], Type[], Type[], Type[][], Type[][], CallingConvention, CharSet)

定义 PInvoke 方法,指定方法的名称、定义方法所使用的 DLL 的名称、入口点名称、方法的属性、方法的调用约定、方法的返回类型、方法的参数类型、PInvoke 标志,以及参数和返回类型的自定义修饰符。

DefinePInvokeMethodCore(String, String, String, MethodAttributes, CallingConventions, Type, Type[], Type[], Type[], Type[][], Type[][], CallingConvention, CharSet)

在派生类中重写时,使用提供的名称、DLL 名称、入口点名称、属性、调用约定、返回类型、参数类型、PInvoke 标志以及参数和返回类型的自定义修饰符定义 PInvoke 方法。

DefineProperty(String, PropertyAttributes, CallingConventions, Type, Type[])

将新属性添加到具有给定名称、属性、调用约定和属性签名的类型。

DefineProperty(String, PropertyAttributes, CallingConventions, Type, Type[], Type[], Type[], Type[][], Type[][])

将新属性添加到具有给定名称、调用约定、属性签名和自定义修饰符的类型。

DefineProperty(String, PropertyAttributes, Type, Type[])

将新属性添加到具有给定名称和属性签名的类型中。

DefineProperty(String, PropertyAttributes, Type, Type[], Type[], Type[], Type[][], Type[][])

将新属性添加到具有给定名称、属性签名和自定义修饰符的类型。

DefinePropertyCore(String, PropertyAttributes, CallingConventions, Type, Type[], Type[], Type[], Type[][], Type[][])

在派生类中重写时,将具有给定名称、调用约定、属性签名和自定义修饰符的新属性添加到类型。

DefineTypeInitializer()

定义此类型的初始值设定项。

DefineTypeInitializerCore()

在派生类中重写时,定义此类型的初始值设定项。

DefineUninitializedData(String, Int32, FieldAttributes)

在可移植可执行 (PE) 文件的 .sdata 部分中定义未初始化的数据字段。

DefineUninitializedDataCore(String, Int32, FieldAttributes)

在派生类中重写时,在可移植可执行文件 (PE) 文件的 节中 .sdata 定义未初始化的数据字段。

Equals(Object)

确定当前 Type 的基础系统类型是否与指定 Object 的基础系统类型相同。

(继承自 Type)
Equals(Object)

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

(继承自 MemberInfo)
Equals(Type)

确定当前 Type 的基础系统类型是否与指定 Type 的基础系统类型相同。

(继承自 Type)
FindInterfaces(TypeFilter, Object)

返回表示接口(由当前 Type 所实现或继承)的筛选列表的 Type 对象数组。

(继承自 Type)
FindInterfaces(TypeFilter, Object)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
FindMembers(MemberTypes, BindingFlags, MemberFilter, Object)

返回指定成员类型的 MemberInfo 对象的筛选数组。

(继承自 Type)
FindMembers(MemberTypes, BindingFlags, MemberFilter, Object)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetArrayRank()

在运行时定义并创建类的新实例。

GetArrayRank()

获取数组中的维数。

(继承自 Type)
GetArrayRank()

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetAttributeFlagsImpl()

在派生类中重写时,实现 Attributes 属性,并获取枚举值的按位组合(它指示与 Type 关联的特性)。

GetAttributeFlagsImpl()

在派生类中重写时,实现 Attributes 属性,并获取枚举值的按位组合(它指示与 Type 关联的特性)。

(继承自 Type)
GetConstructor(BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[])

用指定绑定约束和指定调用约定,搜索其参数与指定参数类型及修饰符匹配的构造函数。

(继承自 Type)
GetConstructor(BindingFlags, Binder, Type[], ParameterModifier[])

使用指定绑定约束搜索其参数与指定自变量类型和修饰符匹配的构造函数。

(继承自 Type)
GetConstructor(BindingFlags, Type[])

使用指定的绑定约束搜索其参数与指定参数类型匹配的构造函数。

(继承自 Type)
GetConstructor(Type, ConstructorInfo)

返回与指定泛型类型定义的构造函数相对应的指定构造泛型类型的构造函数。

GetConstructor(Type[])

搜索其参数与指定数组中的类型匹配的公共实例构造函数。

(继承自 Type)
GetConstructor(Type[])

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetConstructorImpl(BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[])

当在派生类中重写时,使用指定的绑定约束和指定的调用约定搜索其参数与指定的自变量类型和修饰符匹配的构造函数。

GetConstructorImpl(BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[])

当在派生类中重写时,使用指定的绑定约束和指定的调用约定搜索其参数与指定的自变量类型和修饰符匹配的构造函数。

(继承自 Type)
GetConstructors()

返回为当前 Type 定义的所有公共构造函数。

(继承自 Type)
GetConstructors()

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetConstructors(BindingFlags)

按照指定,返回 ConstructorInfo 对象的数组,表示为此类定义的公共和非公共构造函数。

GetConstructors(BindingFlags)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetCustomAttributes(Boolean)

返回为此类型定义的所有自定义属性。

GetCustomAttributes(Boolean)

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

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

返回当前类型的所有自定义属性,该属性可分配给指定类型。

GetCustomAttributes(Type, Boolean)

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

(继承自 MemberInfo)
GetCustomAttributesData()

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

(继承自 MemberInfo)
GetDeclaredEvent(String)

返回一个 对象,该对象表示由当前类型声明的指定事件。

(继承自 TypeInfo)
GetDeclaredField(String)

返回一个 对象,该对象表示由当前类型声明的指定字段。

(继承自 TypeInfo)
GetDeclaredMethod(String)

返回一个 对象,该对象表示由当前类型声明的指定方法。

(继承自 TypeInfo)
GetDeclaredMethods(String)

返回一个集合,该集合包含当前类型上声明的与指定名称匹配的所有方法。

(继承自 TypeInfo)
GetDeclaredNestedType(String)

返回一个 对象,该对象表示由当前类型声明的指定嵌套类型。

(继承自 TypeInfo)
GetDeclaredProperty(String)

返回一个 对象,该对象表示由当前类型声明的指定属性。

(继承自 TypeInfo)
GetDefaultMembers()

搜索为设置了 Type 的当前 DefaultMemberAttribute 定义的成员。

(继承自 Type)
GetDefaultMembers()

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetElementType()

调用此方法始终引发 NotSupportedException

GetEnumName(Object)

返回当前枚举类型中具有指定值的常数的名称。

(继承自 Type)
GetEnumName(Object)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetEnumNames()

返回当前枚举类型中各个成员的名称。

(继承自 Type)
GetEnumNames()

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetEnumUnderlyingType()

返回当前枚举类型的基础类型。

(继承自 Type)
GetEnumUnderlyingType()

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetEnumValues()

返回当前枚举类型中各个常数的值组成的数组。

(继承自 Type)
GetEnumValues()

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetEnumValuesAsUnderlyingType()

检索此枚举类型的基础类型常量的值数组。

(继承自 Type)
GetEvent(String)

返回表示指定的公共事件的 EventInfo 对象。

(继承自 Type)
GetEvent(String)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetEvent(String, BindingFlags)

返回具有指定名称的事件。

GetEvent(String, BindingFlags)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetEvents()

返回此类型声明或继承的公共事件。

GetEvents()

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetEvents(BindingFlags)

返回此类型声明的公共和非公共事件。

GetEvents(BindingFlags)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetField(String)

搜索具有指定名称的公共字段。

(继承自 Type)
GetField(String)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetField(String, BindingFlags)

返回由给定名称指定的字段。

GetField(String, BindingFlags)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetField(Type, FieldInfo)

返回指定的构造泛型类型的字段,该字段对应于泛型类型定义的指定字段。

GetFields()

返回当前 Type 的所有公共字段。

(继承自 Type)
GetFields()

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetFields(BindingFlags)

返回此类型声明的公共和非公共字段。

GetFields(BindingFlags)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetFunctionPointerCallingConventions()

在派生类中重写时,返回当前函数指针 Type的调用约定。

(继承自 Type)
GetFunctionPointerParameterTypes()

在派生类中重写时,返回当前函数指针 Type的参数类型。

(继承自 Type)
GetFunctionPointerReturnType()

在派生类中重写时,返回当前函数指针 Type的返回类型。

(继承自 Type)
GetGenericArguments()

返回一个 Type 对象的数组,表示泛型类型的类型变量或泛型类型定义的类型参数。

GetGenericArguments()

返回表示封闭式泛型类型的类型参数或泛型类型定义的类型参数的 Type 对象的数组。

(继承自 Type)
GetGenericArguments()

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetGenericParameterConstraints()

在运行时定义并创建类的新实例。

GetGenericParameterConstraints()

返回表示当前泛型类型参数约束的 Type 对象的数组。

(继承自 Type)
GetGenericParameterConstraints()

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetGenericTypeDefinition()

返回一个 Type 对象,该对象表示可从中获取当前类型的泛型类型定义。

GetGenericTypeDefinition()

返回一个表示可用于构造当前泛型类型的泛型类型定义的 Type 对象。

(继承自 Type)
GetHashCode()

返回此实例的哈希代码。

(继承自 Type)
GetHashCode()

返回此实例的哈希代码。

(继承自 MemberInfo)
GetInterface(String)

搜索具有指定名称的接口。

(继承自 Type)
GetInterface(String)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetInterface(String, Boolean)

返回由此类直接或间接实现的接口,该接口具有与给定接口名匹配的完全限定名。

GetInterface(String, Boolean)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetInterfaceMap(Type)

返回请求的接口的接口映射。

GetInterfaces()

返回在此类型及其基类上实现的所有接口的数组。

GetInterfaces()

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetMember(String)

搜索具有指定名称的公共成员。

(继承自 Type)
GetMember(String)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetMember(String, BindingFlags)

使用指定绑定约束搜索指定成员。

(继承自 Type)
GetMember(String, BindingFlags)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetMember(String, MemberTypes, BindingFlags)

按照指定,返回此类型声明或继承的所有公共和非公共成员。

GetMember(String, MemberTypes, BindingFlags)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetMembers()

返回为当前 Type 的所有公共成员。

(继承自 Type)
GetMembers()

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetMembers(BindingFlags)

返回此类型声明或继承的公共和非公共成员。

GetMembers(BindingFlags)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetMemberWithSameMetadataDefinitionAs(MemberInfo)

MemberInfo在与指定的 MemberInfo匹配的当前 Type 上搜索 。

(继承自 Type)
GetMethod(String)

搜索具有指定名称的公共方法。

(继承自 Type)
GetMethod(String)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetMethod(String, BindingFlags)

使用指定绑定约束搜索指定方法。

(继承自 Type)
GetMethod(String, BindingFlags)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetMethod(String, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[])

用指定的绑定约束和指定的调用约定,搜索参数与指定的参数类型及修饰符相匹配的指定方法。

(继承自 Type)
GetMethod(String, BindingFlags, Binder, Type[], ParameterModifier[])

使用指定绑定约束,搜索其参数与指定自变量类型及修饰符匹配的指定方法。

(继承自 Type)
GetMethod(String, BindingFlags, Type[])

使用指定的绑定约束搜索其参数与指定参数类型匹配的指定方法。

(继承自 Type)
GetMethod(String, Int32, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[])

使用指定的绑定约束和指定的调用约定搜索其参数与指定泛型参数计数、参数类型及修饰符匹配的指定方法。

(继承自 Type)
GetMethod(String, Int32, BindingFlags, Binder, Type[], ParameterModifier[])

使用指定绑定约束,搜索其参数与指定泛型参数计数、参数类型及修饰符匹配的指定方法。

(继承自 Type)
GetMethod(String, Int32, BindingFlags, Type[])

在运行时定义并创建类的新实例。

(继承自 Type)
GetMethod(String, Int32, Type[])

搜索其参数与指定泛型参数计数及参数类型匹配的指定公共方法。

(继承自 Type)
GetMethod(String, Int32, Type[], ParameterModifier[])

搜索其参数与指定泛型参数计数、参数类型及修饰符匹配的指定公共方法。

(继承自 Type)
GetMethod(String, Type[])

搜索其参数与指定参数类型匹配的指定公共方法。

(继承自 Type)
GetMethod(String, Type[])

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetMethod(String, Type[], ParameterModifier[])

搜索其参数与指定参数类型及修饰符匹配的指定公共方法。

(继承自 Type)
GetMethod(String, Type[], ParameterModifier[])

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetMethod(Type, MethodInfo)

返回与指定泛型类型定义的方法相对应的指定构造泛型类型的方法。

GetMethodImpl(String, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[])

当在派生类中重写时,使用指定的绑定约束和指定的调用约定搜索其参数与指定的自变量类型和修饰符匹配的指定方法。

GetMethodImpl(String, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[])

当在派生类中重写时,使用指定的绑定约束和指定的调用约定搜索其参数与指定的自变量类型和修饰符匹配的指定方法。

(继承自 Type)
GetMethodImpl(String, Int32, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[])

当在派生类中重写时,使用指定的绑定约束和指定的调用约定搜索其参数与指定泛型参数计数、参数类型和修饰符匹配的指定方法。

(继承自 Type)
GetMethods()

返回为当前 Type 的所有公共方法。

(继承自 Type)
GetMethods()

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetMethods(BindingFlags)

按照指定,返回此类型声明或继承的所有公共和非公共方法。

GetMethods(BindingFlags)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetNestedType(String)

搜索具有指定名称的公共嵌套类型。

(继承自 Type)
GetNestedType(String)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetNestedType(String, BindingFlags)

返回此类型声明的公共和非公共嵌套类型。

GetNestedType(String, BindingFlags)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetNestedTypes()

返回嵌套在当前的 Type 中的公共类型。

(继承自 Type)
GetNestedTypes()

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetNestedTypes(BindingFlags)

返回此类型声明或继承的公共和非公共嵌套类型。

GetNestedTypes(BindingFlags)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetOptionalCustomModifiers()

在派生类中重写时,返回当前 Type的可选自定义修饰符。

(继承自 Type)
GetProperties()

返回为当前 Type 的所有公共属性。

(继承自 Type)
GetProperties()

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetProperties(BindingFlags)

按照指定,返回此类型声明或继承的所有公共和非公共属性。

GetProperties(BindingFlags)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetProperty(String)

搜索具有指定名称的公共属性。

(继承自 Type)
GetProperty(String)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetProperty(String, BindingFlags)

使用指定的绑定约束搜索指定属性。

(继承自 Type)
GetProperty(String, BindingFlags)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetProperty(String, BindingFlags, Binder, Type, Type[], ParameterModifier[])

使用指定的绑定约束,搜索参数与指定的自变量类型及修饰符匹配的指定属性。

(继承自 Type)
GetProperty(String, Type)

搜索具有指定名称和返回类型的公共属性。

(继承自 Type)
GetProperty(String, Type)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetProperty(String, Type, Type[])

搜索其参数与指定自变量类型匹配的指定公共属性。

(继承自 Type)
GetProperty(String, Type, Type[])

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetProperty(String, Type, Type[], ParameterModifier[])

搜索其参数与指定自变量类型及修饰符匹配的指定公共属性。

(继承自 Type)
GetProperty(String, Type, Type[], ParameterModifier[])

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetProperty(String, Type[])

搜索其参数与指定自变量类型匹配的指定公共属性。

(继承自 Type)
GetProperty(String, Type[])

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
GetPropertyImpl(String, BindingFlags, Binder, Type, Type[], ParameterModifier[])

当在派生类中重写时,使用指定的绑定约束搜索其参数与指定的参数类型和修饰符匹配的指定属性。

GetPropertyImpl(String, BindingFlags, Binder, Type, Type[], ParameterModifier[])

当在派生类中重写时,使用指定的绑定约束搜索其参数与指定的参数类型和修饰符匹配的指定属性。

(继承自 Type)
GetRequiredCustomModifiers()

在派生类中重写时,返回当前 Type所需的自定义修饰符。

(继承自 Type)
GetType()

获取当前 Type

(继承自 Type)
GetType()

发现成员的属性并提供对成员元数据的访问权限。

(继承自 MemberInfo)
GetTypeCodeImpl()

返回此 Type 实例的基础类型代码。

(继承自 Type)
HasElementTypeImpl()

当在派生类中重写时,实现 HasElementType 属性,确定当前 Type 是否包含另一类型或对其引用;即,当前 Type 是否是数组、指针或由引用传递。

HasElementTypeImpl()

当在派生类中重写时,实现 HasElementType 属性,确定当前 Type 是否包含另一类型或对其引用;即,当前 Type 是否是数组、指针或由引用传递。

(继承自 Type)
HasSameMetadataDefinitionAs(MemberInfo)

在运行时定义并创建类的新实例。

(继承自 MemberInfo)
InvokeMember(String, BindingFlags, Binder, Object, Object[])

使用指定的绑定约束并匹配指定的参数列表,调用指定成员。

(继承自 Type)
InvokeMember(String, BindingFlags, Binder, Object, Object[], CultureInfo)

使用指定的绑定约束和匹配的指定参数列表及区域性来调用指定成员。

(继承自 Type)
InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[])

调用指定的成员。 在指定的活页夹和调用属性的约束下,要调用的方法必须为可访问,并且提供与指定的自变量列表最具体的匹配。

IsArrayImpl()

在派生类中重写时,实现 IsArray 属性并确定 Type 是否为数组。

IsArrayImpl()

在派生类中重写时,实现 IsArray 属性并确定 Type 是否为数组。

(继承自 Type)
IsAssignableFrom(Type)

获取一个值,该值指示是否可将指定的 Type 分配给此对象。

IsAssignableFrom(Type)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsAssignableFrom(TypeInfo)

获取一个值,该值表示是否可以将指定的 TypeInfo 对象赋值给此对象。

IsAssignableTo(Type)

确定当前类型是否可分配给指定 targetType 的变量。

(继承自 Type)
IsByRefImpl()

在派生类中重写时,实现 IsByRef 属性并确定Type 是否通过引用传递。

IsByRefImpl()

在派生类中重写时,实现 IsByRef 属性并确定Type 是否通过引用传递。

(继承自 Type)
IsCOMObjectImpl()

当在派生类中重写时,实现 IsCOMObject 属性并确定 Type 是否为 COM 对象。

IsCOMObjectImpl()

当在派生类中重写时,实现 IsCOMObject 属性并确定 Type 是否为 COM 对象。

(继承自 Type)
IsContextfulImpl()

实现 IsContextful 属性并确定 Type 在上下文中是否可以被承载。

(继承自 Type)
IsCreated()

返回一个值,该值指示是否已创建当前的动态类型。

IsCreatedCore()

在派生类中重写时,返回一个值,该值指示是否已创建当前动态类型。

IsDefined(Type, Boolean)

确定是否将自定义属性应用于当前类型。

IsDefined(Type, Boolean)

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

(继承自 MemberInfo)
IsEnumDefined(Object)

返回一个值,该值指示当前的枚举类型中是否存在指定的值。

(继承自 Type)
IsEnumDefined(Object)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsEquivalentTo(Type)

确定两个 COM 类型是否具有相同的标识,以及是否符合类型等效的条件。

(继承自 Type)
IsEquivalentTo(Type)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsInstanceOfType(Object)

确定指定的对象是否是当前 Type 的实例。

(继承自 Type)
IsInstanceOfType(Object)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsMarshalByRefImpl()

实现 IsMarshalByRef 属性并确定 Type 是否按引用来进行封送。

(继承自 Type)
IsPointerImpl()

在派生类中重写时,实现 IsPointer 属性并确定 Type 是否为指针。

IsPointerImpl()

在派生类中重写时,实现 IsPointer 属性并确定 Type 是否为指针。

(继承自 Type)
IsPrimitiveImpl()

在派生类中重写时,实现 IsPrimitive 属性并确定 Type 是否为基元类型之一。

IsPrimitiveImpl()

在派生类中重写时,实现 IsPrimitive 属性并确定 Type 是否为基元类型之一。

(继承自 Type)
IsSubclassOf(Type)

确定此类型是否派生自指定类型。

IsSubclassOf(Type)

在运行时定义并创建类的新实例。

(继承自 TypeInfo)
IsValueTypeImpl()

实现 IsValueType 属性并确定 Type 是否是值类型;即,它不是值类或接口。

(继承自 Type)
MakeArrayType()

返回 Type 对象,该对象表示当前类型的一维数组(下限为零)。

MakeArrayType()

返回 Type 对象,该对象表示当前类型的一维数组(下限为零)。

(继承自 Type)
MakeArrayType(Int32)

返回 Type 对象,此对象表示当前类型的具有指定维数的数组。

MakeArrayType(Int32)

返回 Type 对象,该对象表示一个具有指定维数的当前类型的数组。

(继承自 Type)
MakeByRefType()

返回一个 Type 对象,它在作为 ref 参数(Visual Basic 中的ByRef )传递时表示当前类型。

MakeByRefType()

返回表示作为 Type 参数(在 Visual Basic 中为 ref 参数)传递时的当前类型的 ByRef 对象。

(继承自 Type)
MakeGenericType(Type[])

将类型数组中的元素替换为当前泛型类型定义的类型参数,并返回生成的构造类型。

MakeGenericType(Type[])

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

(继承自 Type)
MakePointerType()

返回表示指向当前类型的非托管指针的类型的 Type 对象。

MakePointerType()

返回表示指向当前类型的指针的 Type 对象。

(继承自 Type)
MemberwiseClone()

创建当前 Object 的浅表副本。

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

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

SetCustomAttribute(CustomAttributeBuilder)

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

SetCustomAttributeCore(ConstructorInfo, ReadOnlySpan<Byte>)

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

SetParent(Type)

设置当前正在构造的类型的基类型。

SetParentCore(Type)

在派生类中重写时,设置当前正在构造的类型的基类型。

ToString()

返回不包括命名空间的类型的名称。

显式接口实现

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

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

(继承自 Type)
_Type.GetTypeInfo(UInt32, UInt32, IntPtr)

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

(继承自 Type)
_Type.GetTypeInfoCount(UInt32)

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

(继承自 Type)
_Type.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

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

(继承自 Type)
_TypeBuilder.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

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

_TypeBuilder.GetTypeInfo(UInt32, UInt32, IntPtr)

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

_TypeBuilder.GetTypeInfoCount(UInt32)

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

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

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

ICustomAttributeProvider.GetCustomAttributes(Boolean)

返回在该成员上定义的所有自定义特性的数组(已命名的特性除外),如果没有自定义特性,则返回空数组。

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

返回在该成员上定义、由类型标识的自定义属性数组,如果没有该类型的自定义属性,则返回空数组。

(继承自 MemberInfo)
ICustomAttributeProvider.IsDefined(Type, Boolean)

指示是否在该成员上定义了一个或多个 attributeType 实例。

(继承自 MemberInfo)
IReflectableType.GetTypeInfo()

返回当前类型为 TypeInfo 对象的表示形式。

(继承自 TypeInfo)

扩展方法

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)

指示一个指定类型的自定义特性是否应用于一个指定的数字,并选择性地应用于其的上级。

GetTypeInfo(Type)

返回指定类型的 TypeInfo 表示形式。

GetMetadataToken(MemberInfo)

获取给定成员的元数据令牌(如果可用)。

HasMetadataToken(MemberInfo)

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

GetRuntimeEvent(Type, String)

检索一个表示指定事件的对象。

GetRuntimeEvents(Type)

检索表示指定类型定义的所有事件的集合。

GetRuntimeField(Type, String)

检索表示指定字段的对象。

GetRuntimeFields(Type)

检索表示指定类型定义的所有字段的集合。

GetRuntimeInterfaceMap(TypeInfo, Type)

返回指定类型和指定接口的接口映射。

GetRuntimeMethod(Type, String, Type[])

检索表示指定方法的对象。

GetRuntimeMethods(Type)

检索表示指定类型定义的所有方法的集合。

GetRuntimeProperties(Type)

检索表示指定类型定义的所有属性的集合。

GetRuntimeProperty(Type, String)

检索表示指定属性的对象。

GetConstructor(Type, Type[])

在运行时定义并创建类的新实例。

GetConstructors(Type)

在运行时定义并创建类的新实例。

GetConstructors(Type, BindingFlags)

在运行时定义并创建类的新实例。

GetDefaultMembers(Type)

在运行时定义并创建类的新实例。

GetEvent(Type, String)

在运行时定义并创建类的新实例。

GetEvent(Type, String, BindingFlags)

在运行时定义并创建类的新实例。

GetEvents(Type)

在运行时定义并创建类的新实例。

GetEvents(Type, BindingFlags)

在运行时定义并创建类的新实例。

GetField(Type, String)

在运行时定义并创建类的新实例。

GetField(Type, String, BindingFlags)

在运行时定义并创建类的新实例。

GetFields(Type)

在运行时定义并创建类的新实例。

GetFields(Type, BindingFlags)

在运行时定义并创建类的新实例。

GetGenericArguments(Type)

在运行时定义并创建类的新实例。

GetInterfaces(Type)

在运行时定义并创建类的新实例。

GetMember(Type, String)

在运行时定义并创建类的新实例。

GetMember(Type, String, BindingFlags)

在运行时定义并创建类的新实例。

GetMembers(Type)

在运行时定义并创建类的新实例。

GetMembers(Type, BindingFlags)

在运行时定义并创建类的新实例。

GetMethod(Type, String)

在运行时定义并创建类的新实例。

GetMethod(Type, String, BindingFlags)

在运行时定义并创建类的新实例。

GetMethod(Type, String, Type[])

在运行时定义并创建类的新实例。

GetMethods(Type)

在运行时定义并创建类的新实例。

GetMethods(Type, BindingFlags)

在运行时定义并创建类的新实例。

GetNestedType(Type, String, BindingFlags)

在运行时定义并创建类的新实例。

GetNestedTypes(Type, BindingFlags)

在运行时定义并创建类的新实例。

GetProperties(Type)

在运行时定义并创建类的新实例。

GetProperties(Type, BindingFlags)

在运行时定义并创建类的新实例。

GetProperty(Type, String)

在运行时定义并创建类的新实例。

GetProperty(Type, String, BindingFlags)

在运行时定义并创建类的新实例。

GetProperty(Type, String, Type)

在运行时定义并创建类的新实例。

GetProperty(Type, String, Type, Type[])

在运行时定义并创建类的新实例。

IsAssignableFrom(Type, Type)

在运行时定义并创建类的新实例。

IsInstanceOfType(Type, Object)

在运行时定义并创建类的新实例。

适用于

另请参阅