TypeBuilderとは? わかりやすく解説

TypeBuilder クラス

クラス新しインスタンス実行時に定義および作成します

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<ClassInterfaceAttribute(ClassInterfaceType.None)> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class
 TypeBuilder
    Inherits Type
    Implements _TypeBuilder
[ClassInterfaceAttribute(ClassInterfaceType.None)] 
[ComVisibleAttribute(true)] 
public sealed class TypeBuilder : Type, _TypeBuilder
[ClassInterfaceAttribute(ClassInterfaceType::None)] 
[ComVisibleAttribute(true)] 
public ref class TypeBuilder sealed : public
 Type, _TypeBuilder
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.None) */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class TypeBuilder extends Type
 implements _TypeBuilder
ClassInterfaceAttribute(ClassInterfaceType.None) 
ComVisibleAttribute(true) 
public final class TypeBuilder extends
 Type implements _TypeBuilder
解説解説
メモメモ

このクラス適用される HostProtectionAttribute 属性Resources プロパティの値は、MayLeakOnAbort です。HostProtectionAttribute は、デスクトップ アプリケーション (一般的にはアイコンダブルクリックコマンド入力、またはブラウザURL入力して起動するアプリケーション) には影響しません。詳細については、HostProtectionAttribute クラストピックまたは「SQL Server プログラミングホスト保護属性」を参照してください

TypeBuilder は、実行時動的クラス作成制御するために使用するルート クラスです。TypeBuilder は、クラスの定義メソッドフィールド追加、および Runtime 内部でのクラス作成使用するルーチンセット提供します動的モジュールから新しTypeBuilder作成できます

不完全な型の Type オブジェクト取得するには、型の名前 ("MyType"、"MyType[]" など) を表す文字列を指定して ModuleBuilder.GetType を使用します

使用例使用例

次のコード例は、TypeBuilder使用して動的な型を作成する方法示してます。

Imports System
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 'Main
End Class 'TestILGenerator



' +++ 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 
        
    }
    
}

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
import System.*;
import System.Threading.*;
import System.Reflection.*;
import System.Reflection.Emit.*;

class TestILGenerator
{
   public static Type DynamicDotProductGen()
 
   {
        Type ivType = null;
        Type ctorParams[] = new Type[]{int.class.ToType()
,
            int.class.ToType(), int.class.ToType()};

        AppDomain myDomain = System.Threading.Thread.GetDomain();
        AssemblyName myAsmName =  new AssemblyName();
        myAsmName.set_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.class.ToType(), FieldAttributes.Private);
        FieldBuilder yField = ivTypeBld.DefineField("y",
            int.class.ToType(), FieldAttributes.Private);
        FieldBuilder zField = ivTypeBld.DefineField("z",
            int.class.ToType(), 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 VJ# as:
        //    public int DotProduct(IntVector aVector)
        MethodBuilder dotProductMthd = ivTypeBld.DefineMethod("DotProduct"
,
            MethodAttributes.Public, int .class.ToType(),
 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 ;
   } //DynamicDotProductGen
     
    public static void main(String[]
 args)
    {
        Type ivType = null;
        Object aVector1 = null;
        Object aVector2 = null;
        Type aVtypes[] = new Type[] {
            int.class.ToType(), int.class.ToType(),
 int.class.ToType()};
        Object aVargs1[] = new Object[] { (Int32)10, (Int32)10,
 (Int32)10};
        Object aVargs2[] = new Object[] { (Int32)20, (Int32)20,
 (Int32)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.set_Item(0, ((Object)(aVector2)));
        Console.WriteLine("(10, 10, 10) . (20, 20, 20) = {0}",
            ivType.InvokeMember("DotProduct", BindingFlags.InvokeMethod
,
            null, aVector1, passMe));
    } //main
} //TestILGenerator
// +++ OUTPUT +++
// ---
// (10, 10, 10) . (20, 20, 20) = 600 
継承階層継承階層
System.Object
   System.Reflection.MemberInfo
     System.Type
      System.Reflection.Emit.TypeBuilder
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

TypeBuilder フィールド


パブリック フィールドパブリック フィールド

  名前 説明
パブリック フィールド UnspecifiedTypeSize 型の合計サイズ指定されていないことを表します
参照参照

関連項目

TypeBuilder クラス
System.Reflection.Emit 名前空間

その他の技術情報

リフレクション出力による型の定義
方法 : リフレクション出力使用してジェネリック型定義する

TypeBuilder プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ Assembly オーバーライドされます。 この型定義が含まれ動的アセンブリ取得します
パブリック プロパティ AssemblyQualifiedName オーバーライドされますアセンブリ表示名修飾されたこの型の完全名返します
パブリック プロパティ Attributes  Type関連付けられている属性取得します。 ( Type から継承されます。)
パブリック プロパティ BaseType オーバーライドされます。 この型の基本型取得します
パブリック プロパティ ContainsGenericParameters  現在の Type オブジェクト特定の型で置き換えられていない型パラメータ持っているどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ DeclaringMethod オーバーライドされます現在のジェネリック型パラメータ宣言したメソッド取得します
パブリック プロパティ DeclaringType オーバーライドされます。 この型を宣言した型を返します
パブリック プロパティ DefaultBinder  既定バインダへの参照取得します。このバインダは、InvokeMember によって呼び出される適切なメンバ選択するための内部規則実装ます。 ( Type から継承されます。)
パブリック プロパティ FullName オーバーライドされます。 この型の完全パス取得します
パブリック プロパティ GenericParameterAttributes オーバーライドされます現在のジェネリック型パラメータ共変性特殊な制約を示す値を取得します
パブリック プロパティ GenericParameterPosition オーバーライドされますパラメータ宣言したジェネリック型型パラメータ リスト内の型パラメータ位置取得します
パブリック プロパティ GUID オーバーライドされます。 この型の GUID取得します
パブリック プロパティ HasElementType  現在の Type別の型を包含または参照しているかどうか、つまり現在の Type配列ポインタ、または参照渡しかどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsAbstract  Type抽象型で、オーバーライドする必要があるかどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsAnsiClass  Type に、文字列書式属性として AnsiClass選択されているかどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsArray  Type配列かどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsAutoClass  Type に、文字列書式属性として AutoClass選択されているかどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsAutoLayout  Type に、クラスレイアウト属性として AutoLayout選択されているかどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsByRef  Type参照渡しかどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsClass  Typeクラスであり、値型インターフェイスでないかどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsCOMObject  TypeCOM オブジェクトかどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsContextful  Typeコンテキスト内で管理できるかどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsEnum  現在の Type列挙体であるどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsExplicitLayout  Type に、クラスレイアウト属性として ExplicitLayout選択されているかどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsGenericParameter オーバーライドされます現在の型がジェネリック型パラメータかどうかを示す値を取得します
パブリック プロパティ IsGenericType オーバーライドされます現在の型がジェネリック型かどうかを示す値を取得します
パブリック プロパティ IsGenericTypeDefinition オーバーライドされます現在の TypeBuilder が、他のジェネリック型構築できるジェネリック型の定義を表しているかどうかを示す値を取得します
パブリック プロパティ IsImport  Type が ComImportAttribute 属性持っているかどうかを示す (つまり、COM タイプ ライブラリからインポートされたかどうかを示す) 値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsInterface  Typeインターフェイスであり、クラス値型でないかどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsLayoutSequential  Type に、クラスレイアウト属性として SequentialLayout選択されているかどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsMarshalByRef  Type参照渡しマーシャリングされるかどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsNested  現在の Type オブジェクトが、別の型の定義内に入れ子になっている定義で定義された型を表しているかどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsNestedAssembly  Type入れ子になっていて、それ自体属すアセンブリ内でだけ参照可能かどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsNestedFamANDAssem  Type入れ子になっていて、それ自体属すファミリアセンブリ両方属しているクラスだけから参照可能かどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsNestedFamily  Type入れ子になっていて、それ自体属すファミリ内でだけ参照可能かどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsNestedFamORAssem  Type入れ子になっていて、それ自体属すファミリまたはアセンブリいずれかに属しているクラスだけから参照可能かどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsNestedPrivate  Type入れ子になっていて、プライベートとして宣言されているかどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsNestedPublic  クラス入れ子になっていて、パブリックとして宣言されているかどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsNotPublic  Typeパブリックとして宣言されていないかどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsPointer  Typeポインタかどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsPrimitive  Typeプリミティブ型1 つかどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsPublic  Typeパブリックとして宣言されているかどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsSealed  Typesealed として宣言されているかどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsSerializable  Typeシリアル化できるかどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsSpecialName  Type の名前が特別な処理を必要とするかどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsUnicodeClass  Type に、文字列書式属性として UnicodeClass選択されているかどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsValueType  Type値型かどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ IsVisible  Typeアセンブリ外側コードからアクセスできるかどうかを示す値を取得します。 ( Type から継承されます。)
パブリック プロパティ MemberType  このメンバが型であるか、または入れ子にされた型であるかを示す MemberTypes 値を取得します。 ( Type から継承されます。)
パブリック プロパティ MetadataToken  メタデータ要素識別する値を取得します。 ( MemberInfo から継承されます。)
パブリック プロパティ Module オーバーライドされます。 この型の定義が含まれている動的モジュール取得します
パブリック プロパティ Name オーバーライドされます。 この型の name取得します
パブリック プロパティ Namespace オーバーライドされます。 この TypeBuilder定義した名前空間取得します
パブリック プロパティ PackingSize この型のパッキング サイズ取得します
パブリック プロパティ ReflectedType オーバーライドされます。 この型を取得するために使用した型を返します
パブリック プロパティ Size 型の合計サイズ取得します
パブリック プロパティ StructLayoutAttribute  現在の型のレイアウト説明する StructLayoutAttribute を取得します。 ( Type から継承されます。)
パブリック プロパティ TypeHandle オーバーライドされます動的モジュールではサポートされません。
パブリック プロパティ TypeInitializer  Typeクラス初期化子取得します。 ( Type から継承されます。)
パブリック プロパティ TypeToken この型の型トークン返します
パブリック プロパティ UnderlyingSystemType オーバーライドされます。 この TypeBuilder の基になるシステム型を返します
参照参照

関連項目

TypeBuilder クラス
System.Reflection.Emit 名前空間

その他の技術情報

リフレクション出力による型の定義
方法 : リフレクション出力使用してジェネリック型定義する

TypeBuilder メソッド


パブリック メソッドパブリック メソッド

  名前 説明
パブリック メソッド AddDeclarativeSecurity この型に宣言セキュリティ追加します
パブリック メソッド AddInterfaceImplementation この型で実装するインターフェイス追加します
パブリック メソッド CreateType このクラスType オブジェクト作成しますクラスフィールドメソッド定義した後、Type オブジェクト読み込むために、CreateType呼び出します。
パブリック メソッド DefineConstructor オーバーロードされます新しコンストラクタ動的型追加します
パブリック メソッド DefineDefaultConstructor 既定コンストラクタ定義します。ここで定義されコンストラクタは、親の既定コンストラクタ呼び出すだけです。
パブリック メソッド DefineEvent 指定した名前、属性、およびイベントの種類使用して新しイベントを型に追加します
パブリック メソッド DefineField オーバーロードされます新しフィールド動的型追加します
パブリック メソッド DefineGenericParameters 数と名前を指定して現在の型のジェネリック型パラメータ定義し制約設定するために使用できる GenericTypeParameterBuilder オブジェクト配列返します
パブリック メソッド DefineInitializedData 移植可能な実行可能 (PE) ファイルの .sdata セクション初期化済みデータ フィールド定義します
パブリック メソッド DefineMethod オーバーロードされますメソッドを型に追加します
パブリック メソッド DefineMethodOverride 指定したメソッド宣言実装するメソッド本体指定します
パブリック メソッド DefineNestedType オーバーロードされます入れ子にされた型定義します
パブリック メソッド DefinePInvokeMethod オーバーロードされますPInvoke メソッド定義します
パブリック メソッド DefineProperty オーバーロードされます新しプロパティを型に追加します
パブリック メソッド DefineTypeInitializer この型の初期化子定義します
パブリック メソッド DefineUninitializedData 移植可能な実行可能 (PE) ファイルの .sdata セクション初期化されていないデータ フィールド定義します
パブリック メソッド Equals  オーバーロードされます現在の Type の基になるシステム型が、指定した Object または Type の基になるシステム型と同じかどうか判断します。 ( Type から継承されます。)
パブリック メソッド FindInterfaces  現在の Type によって実装または継承されているインターフェイスフィルタ適用済みリストを表す、Type オブジェクト配列返します。 ( Type から継承されます。)
パブリック メソッド FindMembers  指定したメンバ型の MemberInfo オブジェクト配列フィルタ適用して返します。 ( Type から継承されます。)
パブリック メソッド GetArrayRank  Array次元数を取得します。 ( Type から継承されます。)
パブリック メソッド GetConstructor オーバーロードされます指定した基準一致するコンストラクタ返します
パブリック メソッド GetConstructors オーバーロードされます現在の TypeBuilder によって定義されコンストラクタ返します
パブリック メソッド GetCustomAttributes オーバーロードされますオーバーライドされます。 この型に対して定義されているカスタム属性返します
パブリック メソッド GetDefaultMembers  DefaultMemberAttribute が設定されている現在の Type定義されているメンバ検索します。 ( Type から継承されます。)
パブリック メソッド GetElementType オーバーライドされます。 このメソッド呼び出すと、必ず NotSupportedException がスローさます。
パブリック メソッド GetEvent オーバーロードされます現在の TypeBuilder によって定義されイベント返します
パブリック メソッド GetEvents オーバーロードされますオーバーライドされます現在の TypeBuilder によって定義されイベント返します
パブリック メソッド GetField オーバーロードされます現在の TypeBuilder によって定義されフィールド返します
パブリック メソッド GetFields オーバーロードされます現在の TypeBuilder によって定義されフィールド返します
パブリック メソッド GetGenericArguments オーバーライドされますジェネリック型型引数、またはジェネリック型の定義の型パラメータを表す Type オブジェクト配列返します
パブリック メソッド GetGenericParameterConstraints  現在のジェネリック型パラメータの制約を表す Type オブジェクト返します。 ( Type から継承されます。)
パブリック メソッド GetGenericTypeDefinition オーバーライドされます現在の型を取得できるジェネリック型の定義を表す Type オブジェクト返します
パブリック メソッド GetHashCode  このインスタンスハッシュ コード返します。 ( Type から継承されます。)
パブリック メソッド GetInterface オーバーロードされます現在の TypeBuilder によって実装されたインターフェイス返します
パブリック メソッド GetInterfaceMap オーバーライドされます要求したインターフェイス対すインターフェイス割り当て返します
パブリック メソッド GetInterfaces オーバーライドされます。 この型と基本型実装されているすべてのインターフェイス配列返します
パブリック メソッド GetMember オーバーロードされます現在の TypeBuilder によって定義されメンバ返します
パブリック メソッド GetMembers オーバーロードされます現在の TypeBuilder によって定義されメンバ返します
パブリック メソッド GetMethod オーバーロードされます指定した基準一致するメソッド返します
パブリック メソッド GetMethods オーバーロードされます現在の TypeBuilder によって定義されメソッド返します
パブリック メソッド GetNestedType オーバーロードされます現在の TypeBuilder によって定義され入れ子にされた型返します
パブリック メソッド GetNestedTypes オーバーロードされます現在の TypeBuilder によって定義され入れ子にされた型返します
パブリック メソッド GetProperties オーバーロードされます現在の TypeBuilder によって定義されプロパティ返します
パブリック メソッド GetProperty  オーバーロードされます現在の Type特定のプロパティ取得します。 ( Type から継承されます。)
パブリック メソッド GetType  オーバーロードされます指定された型を表す Type オブジェクト取得します。 ( Type から継承されます。)
パブリック メソッド GetTypeArray  指定した配列内のオブジェクトの型を取得します。 ( Type から継承されます。)
パブリック メソッド GetTypeCode  指定した Type の基になる型コード取得します。 ( Type から継承されます。)
パブリック メソッド GetTypeFromCLSID  オーバーロードされます指定したクラス ID (CLSID) に関連付けられている型を取得します。 ( Type から継承されます。)
パブリック メソッド GetTypeFromHandle  指定したハンドルによって参照される型を取得します。 ( Type から継承されます。)
パブリック メソッド GetTypeFromProgID  オーバーロードされます指定したプログラム ID (ProgID) に関連付けられている型を取得します。 ( Type から継承されます。)
パブリック メソッド GetTypeHandle  指定したオブジェクトTypeハンドル取得します。 ( Type から継承されます。)
パブリック メソッド InvokeMember オーバーロードされます現在の TypeBuilder によって定義されメンバ呼び出します。
パブリック メソッド IsAssignableFrom オーバーライドされます指定した Typeインスタンス現在の Typeインスタンス代入できるかどうか判断します
パブリック メソッド IsCreated 現在の動的型作成されているかどうかを示す値を返します
パブリック メソッド IsDefined オーバーライドされますカスタム属性現在の型に適用されているかどうか判断します
パブリック メソッド IsInstanceOfType  指定したオブジェクト現在の Typeインスタンスかどうかを判断します。 ( Type から継承されます。)
パブリック メソッド IsSubclassOf オーバーライドされます。 この型が指定した型から派生しているかどうか判断します
パブリック メソッド MakeArrayType オーバーロードされますオーバーライドされます現在の型の配列を表す Type オブジェクト返します
パブリック メソッド MakeByRefType オーバーライドされますref パラメータ (Visual Basic では ByRef) として渡され場合現在の型を表す Type オブジェクト返します
パブリック メソッド MakeGenericType オーバーライドされます現在のジェネリック型の定義の型パラメータを型の配列要素置き換えその結果である構築された型返します
パブリック メソッド MakePointerType オーバーライドされます現在の型へのアンマネージ ポインタの型を表す Type オブジェクト返します
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 ( Object から継承されます。)
パブリック メソッド ReflectionOnlyGetType  大文字と小文字区別する検索実行し、型が見つからない場合例外スローするかどうか指定して指定した名前の Type取得します。型は実行ではなくリフレクションのためだけに読み込まれます。 ( Type から継承されます。)
パブリック メソッド SetCustomAttribute オーバーロードされますカスタム属性設定します
パブリック メソッド SetParent 現在構築中の型の基本型設定します
パブリック メソッド ToString オーバーライドされます名前空間含まない型の名前を返します
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.Runtime.InteropServices._TypeBuilder.GetIDsOfNames 一連の名前を対応する一連のディスパッチ識別子割り当てます
インターフェイスの明示的な実装 System.Runtime.InteropServices._TypeBuilder.GetTypeInfo オブジェクト型情報取得しますその後は、インターフェイス型情報取得使用できます
インターフェイスの明示的な実装 System.Runtime.InteropServices._TypeBuilder.GetTypeInfoCount オブジェクト提供する型情報インターフェイスの数 (0 または 1) を取得します
インターフェイスの明示的な実装 System.Runtime.InteropServices._TypeBuilder.Invoke オブジェクト公開するプロパティおよびメソッドアクセスできるようにします。
参照参照

関連項目

TypeBuilder クラス
System.Reflection.Emit 名前空間

その他の技術情報

リフレクション出力による型の定義
方法 : リフレクション出力使用してジェネリック型定義する

TypeBuilder メンバ

クラス新しインスタンス実行時に定義および作成します

TypeBuilder データ型公開されるメンバを以下の表に示します


パブリック フィールドパブリック フィールド
  名前 説明
パブリック フィールド UnspecifiedTypeSize 型の合計サイズ指定されていないことを表します
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ Assembly オーバーライドされます。 この型定義が含まれ動的アセンブリ取得します
パブリック プロパティ AssemblyQualifiedName オーバーライドされますアセンブリ表示名修飾されたこの型の完全名返します
パブリック プロパティ Attributes  Type関連付けられている属性取得します。(Type から継承されます。)
パブリック プロパティ BaseType オーバーライドされます。 この型の基本型取得します
パブリック プロパティ ContainsGenericParameters  現在の Type オブジェクト特定の型で置き換えられていない型パラメータ持っているどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ DeclaringMethod オーバーライドされます現在のジェネリック型パラメータ宣言したメソッド取得します
パブリック プロパティ DeclaringType オーバーライドされます。 この型を宣言した型を返します
パブリック プロパティ DefaultBinder  既定バインダへの参照取得します。このバインダは、InvokeMember によって呼び出される適切なメンバ選択するための内部規則実装ます。(Type から継承されます。)
パブリック プロパティ FullName オーバーライドされます。 この型の完全パス取得します
パブリック プロパティ GenericParameterAttributes オーバーライドされます現在のジェネリック型パラメータ共変性特殊な制約を示す値を取得します
パブリック プロパティ GenericParameterPosition オーバーライドされますパラメータ宣言したジェネリック型型パラメータ リスト内の型パラメータ位置取得します
パブリック プロパティ GUID オーバーライドされます。 この型の GUID取得します
パブリック プロパティ HasElementType  現在の Type別の型を包含または参照しているかどうか、つまり現在の Type配列ポインタ、または参照渡しかどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsAbstract  Type抽象型で、オーバーライドする必要があるかどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsAnsiClass  Type に、文字列書式属性として AnsiClass選択されているかどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsArray  Type配列かどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsAutoClass  Type に、文字列書式属性として AutoClass選択されているかどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsAutoLayout  Type に、クラスレイアウト属性として AutoLayout選択されているかどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsByRef  Type参照渡しかどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsClass  Typeクラスであり、値型インターフェイスでないかどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsCOMObject  TypeCOM オブジェクトかどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsContextful  Typeコンテキスト内で管理できるかどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsEnum  現在の Type列挙体であるどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsExplicitLayout  Type に、クラスレイアウト属性として ExplicitLayout選択されているかどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsGenericParameter オーバーライドされます現在の型がジェネリック型パラメータかどうかを示す値を取得します
パブリック プロパティ IsGenericType オーバーライドされます現在の型がジェネリック型かどうかを示す値を取得します
パブリック プロパティ IsGenericTypeDefinition オーバーライドされます現在の TypeBuilder が、他のジェネリック型構築できるジェネリック型の定義を表しているかどうかを示す値を取得します
パブリック プロパティ IsImport  Type が ComImportAttribute 属性持っているかどうかを示す (つまり、COM タイプ ライブラリからインポートされたかどうかを示す) 値を取得します。(Type から継承されます。)
パブリック プロパティ IsInterface  Typeインターフェイスであり、クラス値型でないかどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsLayoutSequential  Type に、クラスレイアウト属性として SequentialLayout選択されているかどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsMarshalByRef  Type参照渡しマーシャリングされるかどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsNested  現在の Type オブジェクトが、別の型の定義内に入れ子になっている定義で定義された型を表しているかどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsNestedAssembly  Type入れ子になっていて、それ自体属すアセンブリ内でだけ参照可能かどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsNestedFamANDAssem  Type入れ子になっていて、それ自体属すファミリアセンブリ両方属しているクラスだけから参照可能かどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsNestedFamily  Type入れ子になっていて、それ自体属すファミリ内でだけ参照可能かどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsNestedFamORAssem  Type入れ子になっていて、それ自体属すファミリまたはアセンブリいずれかに属しているクラスだけから参照可能かどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsNestedPrivate  Type入れ子になっていて、プライベートとして宣言されているかどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsNestedPublic  クラス入れ子になっていて、パブリックとして宣言されているかどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsNotPublic  Typeパブリックとして宣言されていないかどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsPointer  Typeポインタかどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsPrimitive  Typeプリミティブ型1 つかどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsPublic  Typeパブリックとして宣言されているかどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsSealed  Typesealed として宣言されているかどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsSerializable  Typeシリアル化できるかどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsSpecialName  Type の名前が特別な処理を必要とするかどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsUnicodeClass  Type に、文字列書式属性として UnicodeClass選択されているかどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsValueType  Type値型かどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ IsVisible  Typeアセンブリ外側コードからアクセスできるかどうかを示す値を取得します。(Type から継承されます。)
パブリック プロパティ MemberType  このメンバが型であるか、または入れ子にされた型であるかを示す MemberTypes 値を取得します。(Type から継承されます。)
パブリック プロパティ MetadataToken  メタデータ要素識別する値を取得します。(MemberInfo から継承されます。)
パブリック プロパティ Module オーバーライドされます。 この型の定義が含まれている動的モジュール取得します
パブリック プロパティ Name オーバーライドされます。 この型の name取得します
パブリック プロパティ Namespace オーバーライドされます。 この TypeBuilder定義した名前空間取得します
パブリック プロパティ PackingSize この型のパッキング サイズ取得します
パブリック プロパティ ReflectedType オーバーライドされます。 この型を取得するために使用した型を返します
パブリック プロパティ Size 型の合計サイズ取得します
パブリック プロパティ StructLayoutAttribute  現在の型のレイアウト説明する StructLayoutAttribute を取得します。(Type から継承されます。)
パブリック プロパティ TypeHandle オーバーライドされます動的モジュールではサポートされません。
パブリック プロパティ TypeInitializer  Typeクラス初期化子取得します。(Type から継承されます。)
パブリック プロパティ TypeToken この型の型トークン返します
パブリック プロパティ UnderlyingSystemType オーバーライドされます。 この TypeBuilder の基になるシステム型を返します
パブリック メソッドパブリック メソッド
  名前 説明
パブリック メソッド AddDeclarativeSecurity この型に宣言セキュリティ追加します
パブリック メソッド AddInterfaceImplementation この型で実装するインターフェイス追加します
パブリック メソッド CreateType このクラスType オブジェクト作成しますクラスフィールドメソッド定義した後、Type オブジェクト読み込むために、CreateType呼び出します。
パブリック メソッド DefineConstructor オーバーロードされます新しコンストラクタ動的型追加します
パブリック メソッド DefineDefaultConstructor 既定コンストラクタ定義します。ここで定義されコンストラクタは、親の既定コンストラクタ呼び出すだけです。
パブリック メソッド DefineEvent 指定した名前、属性、およびイベントの種類使用して新しイベントを型に追加します
パブリック メソッド DefineField オーバーロードされます新しフィールド動的型追加します
パブリック メソッド DefineGenericParameters 数と名前を指定して現在の型のジェネリック型パラメータ定義し制約設定するために使用できる GenericTypeParameterBuilder オブジェクト配列返します
パブリック メソッド DefineInitializedData 移植可能な実行可能 (PE) ファイルの .sdata セクション初期化済みデータ フィールド定義します
パブリック メソッド DefineMethod オーバーロードされますメソッドを型に追加します
パブリック メソッド DefineMethodOverride 指定したメソッド宣言実装するメソッド本体指定します
パブリック メソッド DefineNestedType オーバーロードされます入れ子にされた型定義します
パブリック メソッド DefinePInvokeMethod オーバーロードされますPInvoke メソッド定義します
パブリック メソッド DefineProperty オーバーロードされます新しプロパティを型に追加します
パブリック メソッド DefineTypeInitializer この型の初期化子定義します
パブリック メソッド DefineUninitializedData 移植可能な実行可能 (PE) ファイルの .sdata セクション初期化されていないデータ フィールド定義します
パブリック メソッド Equals  オーバーロードされます現在の Type の基になるシステム型が、指定した Object または Type の基になるシステム型と同じかどうか判断します。 (Type から継承されます。)
パブリック メソッド FindInterfaces  現在の Type によって実装または継承されているインターフェイスフィルタ適用済みリストを表す、Type オブジェクト配列返します。 (Type から継承されます。)
パブリック メソッド FindMembers  指定したメンバ型の MemberInfo オブジェクト配列フィルタ適用して返します。 (Type から継承されます。)
パブリック メソッド GetArrayRank  Array次元数を取得します。 (Type から継承されます。)
パブリック メソッド GetConstructor オーバーロードされます指定した基準一致するコンストラクタ返します
パブリック メソッド GetConstructors オーバーロードされます現在の TypeBuilder によって定義されコンストラクタ返します
パブリック メソッド GetCustomAttributes オーバーロードされますオーバーライドされます。 この型に対して定義されているカスタム属性返します
パブリック メソッド GetDefaultMembers  DefaultMemberAttribute が設定されている現在の Type定義されているメンバ検索します。 (Type から継承されます。)
パブリック メソッド GetElementType オーバーライドされます。 このメソッド呼び出すと、必ず NotSupportedException がスローさます。
パブリック メソッド GetEvent オーバーロードされます現在の TypeBuilder によって定義されイベント返します
パブリック メソッド GetEvents オーバーロードされますオーバーライドされます現在の TypeBuilder によって定義されイベント返します
パブリック メソッド GetField オーバーロードされます現在の TypeBuilder によって定義されフィールド返します
パブリック メソッド GetFields オーバーロードされます現在の TypeBuilder によって定義されフィールド返します
パブリック メソッド GetGenericArguments オーバーライドされますジェネリック型型引数、またはジェネリック型の定義の型パラメータを表す Type オブジェクト配列返します
パブリック メソッド GetGenericParameterConstraints  現在のジェネリック型パラメータの制約を表す Type オブジェクト返します。 (Type から継承されます。)
パブリック メソッド GetGenericTypeDefinition オーバーライドされます現在の型を取得できるジェネリック型の定義を表す Type オブジェクト返します
パブリック メソッド GetHashCode  このインスタンスハッシュ コード返します。 (Type から継承されます。)
パブリック メソッド GetInterface オーバーロードされます現在の TypeBuilder によって実装されたインターフェイス返します
パブリック メソッド GetInterfaceMap オーバーライドされます要求したインターフェイス対すインターフェイス割り当て返します
パブリック メソッド GetInterfaces オーバーライドされます。 この型と基本型実装されているすべてのインターフェイス配列返します
パブリック メソッド GetMember オーバーロードされます現在の TypeBuilder によって定義されメンバ返します
パブリック メソッド GetMembers オーバーロードされます現在の TypeBuilder によって定義されメンバ返します
パブリック メソッド GetMethod オーバーロードされます指定した基準一致するメソッド返します
パブリック メソッド GetMethods オーバーロードされます現在の TypeBuilder によって定義されメソッド返します
パブリック メソッド GetNestedType オーバーロードされます現在の TypeBuilder によって定義され入れ子にされた型返します
パブリック メソッド GetNestedTypes オーバーロードされます現在の TypeBuilder によって定義され入れ子にされた型返します
パブリック メソッド GetProperties オーバーロードされます現在の TypeBuilder によって定義されプロパティ返します
パブリック メソッド GetProperty  オーバーロードされます現在の Type特定のプロパティ取得します。 (Type から継承されます。)
パブリック メソッド GetType  オーバーロードされます指定された型を表す Type オブジェクト取得します。 (Type から継承されます。)
パブリック メソッド GetTypeArray  指定した配列内のオブジェクトの型を取得します。 (Type から継承されます。)
パブリック メソッド GetTypeCode  指定した Type の基になる型コード取得します。 (Type から継承されます。)
パブリック メソッド GetTypeFromCLSID  オーバーロードされます指定したクラス ID (CLSID) に関連付けられている型を取得します。 (Type から継承されます。)
パブリック メソッド GetTypeFromHandle  指定したハンドルによって参照される型を取得します。 (Type から継承されます。)
パブリック メソッド GetTypeFromProgID  オーバーロードされます指定したプログラム ID (ProgID) に関連付けられている型を取得します。 (Type から継承されます。)
パブリック メソッド GetTypeHandle  指定したオブジェクトTypeハンドル取得します。 (Type から継承されます。)
パブリック メソッド InvokeMember オーバーロードされます現在の TypeBuilder によって定義されメンバ呼び出します。
パブリック メソッド IsAssignableFrom オーバーライドされます指定した Typeインスタンス現在の Typeインスタンス代入できるかどうか判断します
パブリック メソッド IsCreated 現在の動的型作成されているかどうかを示す値を返します
パブリック メソッド IsDefined オーバーライドされますカスタム属性現在の型に適用されているかどうか判断します
パブリック メソッド IsInstanceOfType  指定したオブジェクト現在の Typeインスタンスかどうかを判断します。 (Type から継承されます。)
パブリック メソッド IsSubclassOf オーバーライドされます。 この型が指定した型から派生しているかどうか判断します
パブリック メソッド MakeArrayType オーバーロードされますオーバーライドされます現在の型の配列を表す Type オブジェクト返します
パブリック メソッド MakeByRefType オーバーライドされますref パラメータ (Visual Basic では ByRef) として渡され場合現在の型を表す Type オブジェクト返します
パブリック メソッド MakeGenericType オーバーライドされます現在のジェネリック型の定義の型パラメータを型の配列要素置き換えその結果である構築された型返します
パブリック メソッド MakePointerType オーバーライドされます現在の型へのアンマネージ ポインタの型を表す Type オブジェクト返します
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 (Object から継承されます。)
パブリック メソッド ReflectionOnlyGetType  大文字と小文字区別する検索実行し、型が見つからない場合例外スローするかどうか指定して指定した名前の Type取得します。型は実行ではなくリフレクションのためだけに読み込まれます。 (Type から継承されます。)
パブリック メソッド SetCustomAttribute オーバーロードされますカスタム属性設定します
パブリック メソッド SetParent 現在構築中の型の基本型設定します
パブリック メソッド ToString オーバーライドされます名前空間含まない型の名前を返します
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.Runtime.InteropServices._TypeBuilder.GetIDsOfNames 一連の名前を対応する一連のディスパッチ識別子割り当てます
インターフェイスの明示的な実装 System.Runtime.InteropServices._TypeBuilder.GetTypeInfo オブジェクト型情報取得しますその後は、インターフェイス型情報取得使用できます
インターフェイスの明示的な実装 System.Runtime.InteropServices._TypeBuilder.GetTypeInfoCount オブジェクト提供する型情報インターフェイスの数 (0 または 1) を取得します
インターフェイスの明示的な実装 System.Runtime.InteropServices._TypeBuilder.Invoke オブジェクト公開するプロパティおよびメソッドアクセスできるようにします。
参照参照

関連項目

TypeBuilder クラス
System.Reflection.Emit 名前空間

その他の技術情報

リフレクション出力による型の定義
方法 : リフレクション出力使用してジェネリック型定義する

_TypeBuilder インターフェイス

メモ : このインターフェイスは、.NET Framework version 2.0新しく追加されたものです。

System.Reflection.Emit.TypeBuilder クラスアンマネージ コード公開します

 

名前空間: System.Runtime.InteropServices
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<CLSCompliantAttribute(False)> _
<GuidAttribute("7E5678EE-48B3-3F83-B076-C58543498A58")>
 _
<InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
<ComVisibleAttribute(True)> _
Public Interface _TypeBuilder
[CLSCompliantAttribute(false)] 
[GuidAttribute("7E5678EE-48B3-3F83-B076-C58543498A58")] 
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] 
[ComVisibleAttribute(true)] 
public interface _TypeBuilder
[CLSCompliantAttribute(false)] 
[GuidAttribute(L"7E5678EE-48B3-3F83-B076-C58543498A58")] 
[InterfaceTypeAttribute(ComInterfaceType::InterfaceIsIUnknown)] 
[ComVisibleAttribute(true)] 
public interface class _TypeBuilder
/** @attribute CLSCompliantAttribute(false) */ 
/** @attribute GuidAttribute("7E5678EE-48B3-3F83-B076-C58543498A58") */
 
/** @attribute InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown) */ 
/** @attribute ComVisibleAttribute(true) */ 
public interface _TypeBuilder
CLSCompliantAttribute(false) 
GuidAttribute("7E5678EE-48B3-3F83-B076-C58543498A58") 
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown) 
ComVisibleAttribute(true) 
public interface _TypeBuilder
解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
_TypeBuilder メンバ
System.Runtime.InteropServices 名前空間

_TypeBuilder メソッド


_TypeBuilder メンバ




英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「TypeBuilder」の関連用語

TypeBuilderのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



TypeBuilderのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS