AssemblyBuilder クラス

定義

動的アセンブリを定義し、表します。

public ref class AssemblyBuilder sealed : System::Reflection::Assembly
public ref class AssemblyBuilder abstract : System::Reflection::Assembly
public ref class AssemblyBuilder sealed : System::Reflection::Assembly, System::Runtime::InteropServices::_AssemblyBuilder
public sealed class AssemblyBuilder : System.Reflection.Assembly
public abstract class AssemblyBuilder : System.Reflection.Assembly
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
public sealed class AssemblyBuilder : System.Reflection.Assembly, System.Runtime.InteropServices._AssemblyBuilder
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class AssemblyBuilder : System.Reflection.Assembly, System.Runtime.InteropServices._AssemblyBuilder
type AssemblyBuilder = class
    inherit Assembly
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
type AssemblyBuilder = class
    inherit Assembly
    interface _AssemblyBuilder
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type AssemblyBuilder = class
    inherit Assembly
    interface _AssemblyBuilder
Public NotInheritable Class AssemblyBuilder
Inherits Assembly
Public MustInherit Class AssemblyBuilder
Inherits Assembly
Public NotInheritable Class AssemblyBuilder
Inherits Assembly
Implements _AssemblyBuilder
継承
AssemblyBuilder
属性
実装

次のコード例は、動的アセンブリを定義して使用する方法を示しています。 この例のアセンブリには、プライベート フィールドを MyDynamicType持つ 1 つの型、プライベート フィールドを取得および設定するプロパティ、プライベート フィールドを初期化するコンストラクター、およびユーザー指定の数値にプライベート フィールド値を乗算して結果を返すメソッドが含まれています。

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
 */
open System
open System.Threading
open System.Reflection
open System.Reflection.Emit

// 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;
    }
}
*)

let assemblyName = new AssemblyName("DynamicAssemblyExample")
let assemblyBuilder =
    AssemblyBuilder.DefineDynamicAssembly(
        assemblyName,
        AssemblyBuilderAccess.Run)

// The module name is usually the same as the assembly name.
let moduleBuilder =
    assemblyBuilder.DefineDynamicModule(assemblyName.Name)

let typeBuilder =
    moduleBuilder.DefineType(
        "MyDynamicType",
        TypeAttributes.Public)

// Add a private field of type int (Int32)
let fieldBuilderNumber =
    typeBuilder.DefineField(
        "m_number",
        typeof<int>,
        FieldAttributes.Private)

// Define a constructor1 that takes an integer argument and
// stores it in the private field.
let parameterTypes = [| typeof<int> |]
let ctor1 =
    typeBuilder.DefineConstructor(
        MethodAttributes.Public,
        CallingConventions.Standard,
        parameterTypes)

let 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,
                 typeof<obj>.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, fieldBuilderNumber)
ctor1IL.Emit(OpCodes.Ret)

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

let 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)
let propertyBuilderNumber =
    typeBuilder.DefineProperty(
        "Number",
        PropertyAttributes.HasDefault,
        typeof<int>,
        null)

// The property "set" and property "get" methods require a special
// set of attributes.
let 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)
let methodBuilderNumberGetAccessor =
    typeBuilder.DefineMethod(
        "get_number",
        getSetAttr,
        typeof<int>,
        Type.EmptyTypes)

let numberGetIL =
    methodBuilderNumberGetAccessor.GetILGenerator()

// For an instance property, argument zero ir 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, fieldBuilderNumber)
numberGetIL.Emit(OpCodes.Ret)

// Define the "set" accessor method for Number, which has no return
// type and takes one argument of type int (Int32).
let methodBuilderNumberSetAccessor =
    typeBuilder.DefineMethod(
        "set_number",
        getSetAttr,
        null,
        [| typeof<int> |])

let numberSetIL =
    methodBuilderNumberSetAccessor.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, fieldBuilderNumber)
numberSetIL.Emit(OpCodes.Ret)

// Last, map the "get" and "set" accessor methods to the
// PropertyBuilder. The property is now complete.
propertyBuilderNumber.SetGetMethod(methodBuilderNumberGetAccessor)
propertyBuilderNumber.SetSetMethod(methodBuilderNumberSetAccessor)

// 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.
let methodBuilder =
    typeBuilder.DefineMethod(
        "MyMethod",
        MethodAttributes.Public,
        typeof<int>,
        [| typeof<int> |])

let methodIL = methodBuilder.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.
methodIL.Emit(OpCodes.Ldarg_0)
methodIL.Emit(OpCodes.Ldfld, fieldBuilderNumber)
methodIL.Emit(OpCodes.Ldarg_1)
methodIL.Emit(OpCodes.Mul)
methodIL.Emit(OpCodes.Ret)

// Finish the type
let typ = typeBuilder.CreateType()

// Because AssemblyBuilderAccess includes Run, the code can be
// executed immediately. Start by getting reflection objects for
// the method and the property.
let methodInfo = typ.GetMethod("MyMethod")
let propertyInfo = typ.GetProperty("Number")

// Create an instance of MyDynamicType using the default
// constructor.
let obj1 = Activator.CreateInstance(typ)

// 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.
printfn "obj1.Number: %A" (propertyInfo.GetValue(obj1, null))
propertyInfo.SetValue(obj1, 127, null)
printfn "obj1.Number: %A" (propertyInfo.GetValue(obj1, null))

// Call MyMethod, pasing 22, and display the return value, 22
// times 127. Arguments must be passed as an array, even when
// there is only one.
let arguments: obj array = [| 22 |]
printfn "obj1.MyMethod(22): %A" (methodInfo.Invoke(obj1, 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.
let constructorArguments: obj array = [| 5280 |]
let obj2 = Activator.CreateInstance(typ, constructorArguments)
printfn "obj2.Number: %A" (propertyInfo.GetValue(obj2, null))

(* This code produces the following output:

obj1.Number: 42
obj1.Number: 127
obj1.MyMethod(22): 2794
obj1.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

注釈

この API の詳細については、「 AssemblyBuilder の補足 API 解説」を参照してください。

コンストラクター

AssemblyBuilder()

AssemblyBuilder クラスの新しいインスタンスを初期化します。

プロパティ

CodeBase
古い.

AssemblyName オブジェクトの中など、初めに指定されたアセンブリの場所を取得します。

CodeBase
古い.
古い.

たとえば AssemblyName オブジェクトで、初めに指定されたアセンブリの場所を取得します。

(継承元 Assembly)
CustomAttributes

このアセンブリのカスタム属性を含むコレクションを取得します。

(継承元 Assembly)
DefinedTypes

動的アセンブリを定義し、表します。

DefinedTypes

このアセンブリで定義されている型のコレクションを取得します。

(継承元 Assembly)
EntryPoint

このアセンブリのエントリ ポイントを返します。

EntryPoint

このアセンブリのエントリ ポイントを取得します。

(継承元 Assembly)
EscapedCodeBase
古い.
古い.

コードベースを表す URI を、エスケープ文字も含めて取得します。

(継承元 Assembly)
Evidence

このアセンブリの証拠を取得します。

Evidence

このアセンブリの証拠を取得します。

(継承元 Assembly)
ExportedTypes

アセンブリの外側で参照できる、このアセンブリ内で定義されているパブリック型のコレクションを取得します。

(継承元 Assembly)
FullName

現在の動的アセンブリの表示名を取得します。

FullName

アセンブリの表示名を取得します。

(継承元 Assembly)
GlobalAssemblyCache
古い.

アセンブリがグローバル アセンブリ キャッシュから読み込まれたかどうかを示す値を取得します。

GlobalAssemblyCache
古い.

アセンブリがグローバル アセンブリ キャッシュから読み込まれたかどうかを示す値を取得します (.NET Frameworkのみ)。

(継承元 Assembly)
HostContext

動的アセンブリが作成されるホスト コンテキストを取得します。

HostContext

アセンブリの読み込みに使用したホスト コンテキストを取得します。

(継承元 Assembly)
ImageRuntimeVersion

マニフェストを格納しているファイルに保存される、共通言語ランタイムのバージョンを取得します。

ImageRuntimeVersion

マニフェストを格納しているファイルに保存された共通言語ランタイム (CLR: common language runtime) のバージョンを表す文字列を取得します。

(継承元 Assembly)
IsCollectible

この動的アセンブリが収集可能 AssemblyLoadContextな に保持されているかどうかを示す値を取得します。

IsCollectible

このアセンブリが収集可能な AssemblyLoadContext に保持されているかどうかを示す値を取得します。

(継承元 Assembly)
IsDynamic

現在のアセンブリが動的なアセンブリであることを示す値を取得します。

IsDynamic

現在のアセンブリが、現在のプロセスでリフレクション出力を使用して動的に生成されたかどうかを示す値を取得します。

(継承元 Assembly)
IsFullyTrusted

現在のアセンブリが完全信頼で読み込まれたかどうかを示す値を取得します。

(継承元 Assembly)
Location

シャドウ コピーされたファイルではない場合は、マニフェストを格納している読み込み済みファイルの位置をコードベース形式で取得します。

Location

マニフェストを格納している読み込み済みファイルの完全パスまたは UNC 位置を取得します。

(継承元 Assembly)
ManifestModule

アセンブリのマニフェストを格納している現在の AssemblyBuilder のモジュールを取得します。

ManifestModule

現在のアセンブリのマニフェストを格納しているモジュールを取得します。

(継承元 Assembly)
Modules

動的アセンブリを定義し、表します。

Modules

このアセンブリ内のモジュールを含むコレクションを取得します。

(継承元 Assembly)
PermissionSet

現在の動的アセンブリの許可セットを取得します。

PermissionSet

現在のアセンブリの許可セットを取得します。

(継承元 Assembly)
ReflectionOnly

動的アセンブリがリフレクションのみのコンテキストにあるかどうかを示す値を取得します。

ReflectionOnly

このアセンブリがリフレクションのみのコンテキストに読み込まれたかどうかを示す Boolean 値を取得します。

(継承元 Assembly)
SecurityRuleSet

共通言語ランタイム (CLR: Common Language Runtime) によってこのアセンブリに適用されるセキュリティ規則のセットを示す値を取得します。

SecurityRuleSet

共通言語ランタイム (CLR: Common Language Runtime) によってこのアセンブリに適用されるセキュリティ規則のセットを示す値を取得します。

(継承元 Assembly)

メソッド

AddResourceFile(String, String)

このアセンブリに既存のリソース ファイルを追加します。

AddResourceFile(String, String, ResourceAttributes)

このアセンブリに既存のリソース ファイルを追加します。

CreateInstance(String)

大文字小文字を区別する検索を使用してこのアセンブリから指定された型を検索し、システム アクティベーターを使用してこの型のインスタンスを作成します。

(継承元 Assembly)
CreateInstance(String, Boolean)

オプションの大文字小文字を区別する検索を使用してこのアセンブリから指定された型を検索し、システム アクティベーターを使用してこの型のインスタンスを作成します。

(継承元 Assembly)
CreateInstance(String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])

オプションの大文字小文字を区別する検索を使用して、このアセンブリから指定された型を検索し、システム アクティベーターを使用してこの型のインスタンスを作成し、指定されたカルチャ設定、引数、バインディング属性、およびアクティベーション属性を設定します。

(継承元 Assembly)
DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess)

指定した名前とアクセス権がある動的アセンブリを定義します。

DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, IEnumerable<CustomAttributeBuilder>)

指定した名前、アクセス権、および属性がある新しいアセンブリを定義します。

DefineDynamicModule(String)

このアセンブリの中に、指定された一時動的モジュールを定義します。

DefineDynamicModule(String, Boolean)

このアセンブリ内に名前付き一時動的モジュールを定義し、シンボル情報を生成する必要があるかどうかを指定します。

DefineDynamicModule(String, String)

指定したファイルに保存される指定された名前を持つ、永続する動的モジュールを定義します。 シンボル情報は生成されません。

DefineDynamicModule(String, String, Boolean)

モジュール名、モジュールの保存先のファイル名、および既定のシンボルのライターを使用してシンボル情報を出力する必要があるかどうかを指定して、永続する動的モジュールを定義します。

DefineDynamicModuleCore(String)

派生クラスでオーバーライドされた場合、このアセンブリで動的モジュールを定義します。

DefinePersistedAssembly(AssemblyName, Assembly, IEnumerable<CustomAttributeBuilder>)

動的アセンブリを定義し、表します。

DefineResource(String, String, String)

既定のパブリック リソース属性で、このアセンブリのスタンドアロン マネージド リソースを定義します。

DefineResource(String, String, String, ResourceAttributes)

このアセンブリのスタンドアロン マネージド リソースを定義します。 属性には、マネージド リソースを指定できます。

DefineUnmanagedResource(Byte[])

このアセンブリのアンマネージ リソースをバイトの非透過 BLOB として定義します。

DefineUnmanagedResource(String)

リソース ファイルの名前が指定されたこのアセンブリのアンマネージ リソース ファイルを定義します。

DefineVersionInfoResource()

アセンブリの AssemblyName オブジェクトと、アセンブリのカスタム属性に指定された情報を使用して、アンマネージ バージョンの情報リソースを定義します。

DefineVersionInfoResource(String, String, String, String, String)

指定された仕様で、このアセンブリのアンマネージ バージョン情報リソースを定義します。

Equals(Object)

このインスタンスが、指定したオブジェクトと同一であるかどうかを示す値を返します。

Equals(Object)

このアセンブリと指定したオブジェクトが等しいかどうかを判断します。

(継承元 Assembly)
GetCustomAttributes(Boolean)

現在の AssemblyBuilder に適用されたカスタム属性をすべて返します。

GetCustomAttributes(Boolean)

このアセンブリのすべてのカスタム属性を取得します。

(継承元 Assembly)
GetCustomAttributes(Type, Boolean)

現在の AssemblyBuilder に適用されており、指定された属性の型から派生するすべてのカスタム属性を返します。

GetCustomAttributes(Type, Boolean)

型を指定して、このアセンブリのカスタム属性を取得します。

(継承元 Assembly)
GetCustomAttributesData()

現在の AssemblyBuilder に適用されている属性に関する情報を含む CustomAttributeData オブジェクトを返します。

GetCustomAttributesData()

現在の Assembly に適用されている属性に関する情報を、CustomAttributeData オブジェクトとして返します。

(継承元 Assembly)
GetDynamicModule(String)

指定された名前の動的モジュールを返します。

GetDynamicModuleCore(String)

派生クラスでオーバーライドされると、指定した名前の動的モジュールが返されます。

GetExportedTypes()

このアセンブリで定義されているエクスポートされた型を取得します。

GetExportedTypes()

アセンブリの外側で参照できる、このアセンブリ内で定義されているパブリック型を取得します。

(継承元 Assembly)
GetFile(String)

このアセンブリのマニフェストのファイル テーブル内の指定されたファイルの FileStream を取得します。

GetFile(String)

このアセンブリのマニフェストのファイル テーブル内の指定されたファイルの FileStream を取得します。

(継承元 Assembly)
GetFiles()

アセンブリ マニフェストのファイル テーブルのファイルを取得します。

(継承元 Assembly)
GetFiles(Boolean)

リソース モジュールを含めるかどうかを指定して、アセンブリ マニフェストのファイル テーブルのファイルを取得します。

GetFiles(Boolean)

リソース モジュールを含めるかどうかを指定して、アセンブリ マニフェストのファイル テーブルのファイルを取得します。

(継承元 Assembly)
GetForwardedTypes()

動的アセンブリを定義し、表します。

(継承元 Assembly)
GetHashCode()

このインスタンスのハッシュ コードを返します。

GetHashCode()

このインスタンスのハッシュ コードを返します。

(継承元 Assembly)
GetLoadedModules()

このアセンブリの一部であるすべての読み込み済みモジュールを取得します。

(継承元 Assembly)
GetLoadedModules(Boolean)

このアセンブリの一部であるすべての読み込み済みモジュールを返し、また必要に応じて、リソース モジュールを含めます。

GetLoadedModules(Boolean)

リソース モジュールを含めるかどうかを指定して、このアセンブリの一部であるすべての読み込み済みモジュールを取得します。

(継承元 Assembly)
GetManifestResourceInfo(String)

指定されたリソースが永続化された方法に関する情報を返します。

GetManifestResourceNames()

このアセンブリから、指定されたマニフェスト リソースを読み込みます。

GetManifestResourceStream(String)

このアセンブリから、指定されたマニフェスト リソースを読み込みます。

GetManifestResourceStream(Type, String)

このアセンブリから、指定された型の名前空間によってスコープが指定されている、指定されたマニフェスト リソースを読み込みます。

GetManifestResourceStream(Type, String)

このアセンブリから、指定された型の名前空間によってスコープが指定されている、指定されたマニフェスト リソースを読み込みます。

(継承元 Assembly)
GetModule(String)

このアセンブリから指定されたモジュールを取得します。

GetModule(String)

このアセンブリから指定されたモジュールを取得します。

(継承元 Assembly)
GetModules()

このアセンブリの一部であるすべてのモジュールを取得します。

(継承元 Assembly)
GetModules(Boolean)

このアセンブリの一部であるすべてのモジュールを取得し、また必要に応じて、リソース モジュールを含めます。

GetModules(Boolean)

リソース モジュールを含めるかどうかを指定して、このアセンブリの一部であるすべてのモジュールを取得します。

(継承元 Assembly)
GetName()

このアセンブリの AssemblyName を取得します。

(継承元 Assembly)
GetName(Boolean)

現在の動的アセンブリが作成された時に指定した AssemblyName を取得し、指定されたとおりにコード ベースを設定します。

GetName(Boolean)

このアセンブリの AssemblyName を取得し、copiedName の指定に従ってコードベースを設定します。

(継承元 Assembly)
GetObjectData(SerializationInfo, StreamingContext)
古い.

シリアル化情報と、このアセンブリの再インスタンス化に必要なすべてのデータを取得します。

(継承元 Assembly)
GetReferencedAssemblies()

この AssemblyBuilder で参照されるアセンブリの AssemblyName オブジェクトの不完全なリストを取得します。

GetReferencedAssemblies()

このアセンブリが参照するすべてのアセンブリの AssemblyName オブジェクトを取得します。

(継承元 Assembly)
GetSatelliteAssembly(CultureInfo)

指定されたカルチャ設定のサテライト アセンブリを取得します。

GetSatelliteAssembly(CultureInfo)

指定されたカルチャ設定のサテライト アセンブリを取得します。

(継承元 Assembly)
GetSatelliteAssembly(CultureInfo, Version)

指定されたバージョンの、指定されたカルチャ設定のサテライト アセンブリを取得します。

GetSatelliteAssembly(CultureInfo, Version)

指定されたバージョンの、指定されたカルチャ設定のサテライト アセンブリを取得します。

(継承元 Assembly)
GetType()

動的アセンブリを定義し、表します。

(継承元 Assembly)
GetType(String)

指定した名前の Type オブジェクトを、アセンブリ インスタンスから取得します。

(継承元 Assembly)
GetType(String, Boolean)

指定した名前の Type オブジェクトをアセンブリ インスタンスから取得し、型が見つからない場合は、オプションで例外をスローします。

(継承元 Assembly)
GetType(String, Boolean, Boolean)

現在の AssemblyBuilder で定義および作成された型から、指定された型を取得します。

GetType(String, Boolean, Boolean)

指定した名前の Type オブジェクトをアセンブリ インスタンスから取得します。オプションで、大文字と小文字の区別を無視したり、型が見つからない場合は例外をスローしたりできます。

(継承元 Assembly)
GetTypes()

このアセンブリで定義されているすべての型を取得します。

(継承元 Assembly)
IsDefined(Type, Boolean)

このメンバーに指定された属性の型の 1 つまたは複数のインスタンスが適用されるかどうかを示す値を返します。

IsDefined(Type, Boolean)

指定した属性がアセンブリに適用されているかどうかを示します。

(継承元 Assembly)
LoadModule(String, Byte[])

生成されたモジュールを含んだ COFF ベースのイメージ、またはリソース ファイルと共に、このアセンブリの内部モジュールを読み込みます。

(継承元 Assembly)
LoadModule(String, Byte[], Byte[])

生成されたモジュールを含んだ COFF ベースのイメージ、またはリソース ファイルと共に、このアセンブリの内部モジュールを読み込みます。 モジュールのシンボルを表す生バイトも読み込まれます。

(継承元 Assembly)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
Save(Stream)

動的アセンブリを定義し、表します。

Save(String)

ディスクにこの動的アセンブリを保存します。

Save(String, PortableExecutableKinds, ImageFileMachine)

ディスクにこの動的アセンブリを保存します。その際、アセンブリの実行可能ファイルのコードの性質とターゲット プラットフォームを指定します。

SaveCore(Stream)

動的アセンブリを定義し、表します。

SetCustomAttribute(ConstructorInfo, Byte[])

指定されたカスタム属性 blob を使用して、このアセンブリのカスタム属性を設定します。

SetCustomAttribute(CustomAttributeBuilder)

カスタム属性ビルダーを使用して、このアセンブリのカスタム属性を設定します。

SetCustomAttributeCore(ConstructorInfo, ReadOnlySpan<Byte>)

派生クラスでオーバーライドされた場合は、このアセンブリにカスタム属性を設定します。

SetEntryPoint(MethodInfo)

コンソール アプリケーションを開発していると仮定した場合、この動的アセンブリのエントリ ポイントを設定します。

SetEntryPoint(MethodInfo, PEFileKinds)

このアセンブリのエントリ ポイントを設定し、ビルド中の移植可能な実行可能 (PE ファイル) の型を定義します。

ToString()

アセンブリの完全名を返します。この名前は表示名とも呼ばれます。

(継承元 Assembly)

イベント

ModuleResolve

共通言語ランタイム クラス ローダーが、通常の方法で参照をアセンブリの内部モジュールに解決できないときに発生します。

(継承元 Assembly)

明示的なインターフェイスの実装

_Assembly.GetType()

現在のインスタンスの型を返します。

(継承元 Assembly)
_AssemblyBuilder.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

一連の名前を対応する一連のディスパッチ識別子に割り当てます。

_AssemblyBuilder.GetTypeInfo(UInt32, UInt32, IntPtr)

オブジェクトの型情報を取得します。この型情報を使用して、インターフェイスの型情報を取得できます。

_AssemblyBuilder.GetTypeInfoCount(UInt32)

オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。

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

オブジェクトによって公開されたプロパティおよびメソッドへのアクセスを提供します。

ICustomAttributeProvider.GetCustomAttributes(Boolean)

名前付きの属性を除く、このメンバーに定義されているすべてのカスタム属性の配列、またはカスタム属性がない場合は空の配列を返します。

(継承元 Assembly)
ICustomAttributeProvider.GetCustomAttributes(Type, Boolean)

型で識別された、このメンバーに定義されているカスタム属性の配列、または、この型のカスタム属性がない場合は空の配列を返します。

(継承元 Assembly)
ICustomAttributeProvider.IsDefined(Type, Boolean)

attributeType の 1 つ以上のインスタンスがこのメンバーで定義されているかどうかを示します。

(継承元 Assembly)

拡張メソッド

GetExportedTypes(Assembly)

動的アセンブリを定義し、表します。

GetModules(Assembly)

動的アセンブリを定義し、表します。

GetTypes(Assembly)

動的アセンブリを定義し、表します。

GetCustomAttribute(Assembly, Type)

指定されたアセンブリに適用される指定された型のカスタム属性を取得します。

GetCustomAttribute<T>(Assembly)

指定されたアセンブリに適用される指定された型のカスタム属性を取得します。

GetCustomAttributes(Assembly)

指定されたアセンブリに適用されるカスタム属性のコレクションを取得します。

GetCustomAttributes(Assembly, Type)

指定されたアセンブリに適用されている、指定された型のカスタム属性のコレクションを取得します。

GetCustomAttributes<T>(Assembly)

指定されたアセンブリに適用されている、指定された型のカスタム属性のコレクションを取得します。

IsDefined(Assembly, Type)

指定された型のカスタム属性が指定されたアセンブリに適用されているかどうかを示します。

TryGetRawMetadata(Assembly, Byte*, Int32)

で使用するために、アセンブリのメタデータ セクションを MetadataReader取得します。

適用対象

こちらもご覧ください