AssemblyBuilder Klasa

Definicja

Definiuje i reprezentuje zestaw dynamiczny.

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
Dziedziczenie
AssemblyBuilder
Atrybuty
Implementuje

Przykłady

Poniższy przykład kodu przedstawia sposób definiowania i używania zestawu dynamicznego. Przykładowy zestaw zawiera jeden typ, MyDynamicType, który ma pole prywatne, właściwość, która pobiera i ustawia pole prywatne, konstruktory, które inicjują pole prywatne, oraz metodę, która mnoży liczbę dostarczaną przez użytkownika przez wartość pola prywatnego i zwraca wynik.

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

Uwagi

Aby uzyskać więcej informacji na temat tego interfejsu API, zobacz Dodatkowe uwagi dotyczące interfejsu API dla elementu AssemblyBuilder.

Konstruktory

AssemblyBuilder()

Inicjuje nowe wystąpienie klasy AssemblyBuilder.

Właściwości

CodeBase
Przestarzałe.

Pobiera lokalizację zestawu, jak określono pierwotnie (na przykład w AssemblyName obiekcie).

CodeBase
Przestarzałe.
Przestarzałe.

Pobiera lokalizację zestawu, jak określono pierwotnie, na przykład w AssemblyName obiekcie.

(Odziedziczone po Assembly)
CustomAttributes

Pobiera kolekcję zawierającą atrybuty niestandardowe tego zestawu.

(Odziedziczone po Assembly)
DefinedTypes

Definiuje i reprezentuje zestaw dynamiczny.

DefinedTypes

Pobiera kolekcję typów zdefiniowanych w tym zestawie.

(Odziedziczone po Assembly)
EntryPoint

Zwraca punkt wejścia tego zestawu.

EntryPoint

Pobiera punkt wejścia tego zestawu.

(Odziedziczone po Assembly)
EscapedCodeBase
Przestarzałe.
Przestarzałe.

Pobiera identyfikator URI, w tym znaki ucieczki, które reprezentują bazę kodu.

(Odziedziczone po Assembly)
Evidence

Pobiera dowody na ten zestaw.

Evidence

Pobiera dowody na ten zestaw.

(Odziedziczone po Assembly)
ExportedTypes

Pobiera kolekcję typów publicznych zdefiniowanych w tym zestawie, które są widoczne poza zestawem.

(Odziedziczone po Assembly)
FullName

Pobiera nazwę wyświetlaną bieżącego zestawu dynamicznego.

FullName

Pobiera nazwę wyświetlaną zestawu.

(Odziedziczone po Assembly)
GlobalAssemblyCache
Przestarzałe.

Pobiera wartość wskazującą, czy zestaw został załadowany z globalnej pamięci podręcznej zestawów.

GlobalAssemblyCache
Przestarzałe.

Pobiera wartość wskazującą, czy zestaw został załadowany z globalnej pamięci podręcznej zestawów (tylko .NET Framework).

(Odziedziczone po Assembly)
HostContext

Pobiera kontekst hosta, w którym tworzony jest zestaw dynamiczny.

HostContext

Pobiera kontekst hosta, z którym został załadowany zestaw.

(Odziedziczone po Assembly)
ImageRuntimeVersion

Pobiera wersję środowiska uruchomieniowego języka wspólnego, która zostanie zapisana w pliku zawierającym manifest.

ImageRuntimeVersion

Pobiera ciąg reprezentujący wersję środowiska uruchomieniowego języka wspólnego (CLR) zapisany w pliku zawierającym manifest.

(Odziedziczone po Assembly)
IsCollectible

Pobiera wartość wskazującą, czy ten zestaw dynamiczny jest przechowywany w zbieralnym AssemblyLoadContextobiekcie .

IsCollectible

Pobiera wartość wskazującą, czy ten zestaw jest przechowywany w kolekcji .AssemblyLoadContext

(Odziedziczone po Assembly)
IsDynamic

Pobiera wartość wskazującą, że bieżący zestaw jest zestawem dynamicznym.

IsDynamic

Pobiera wartość wskazującą, czy bieżący zestaw został wygenerowany dynamicznie w bieżącym procesie przy użyciu emisji odbicia.

(Odziedziczone po Assembly)
IsFullyTrusted

Pobiera wartość wskazującą, czy bieżący zestaw jest ładowany z pełnym zaufaniem.

(Odziedziczone po Assembly)
Location

Pobiera lokalizację w formacie bazy kodu załadowanego pliku zawierającego manifest, jeśli nie jest kopiowany w tle.

Location

Pobiera pełną ścieżkę lub lokalizację UNC załadowanego pliku zawierającego manifest.

(Odziedziczone po Assembly)
ManifestModule

Pobiera moduł w bieżącym AssemblyBuilder , który zawiera manifest zestawu.

ManifestModule

Pobiera moduł zawierający manifest bieżącego zestawu.

(Odziedziczone po Assembly)
Modules

Definiuje i reprezentuje zestaw dynamiczny.

Modules

Pobiera kolekcję zawierającą moduły w tym zestawie.

(Odziedziczone po Assembly)
PermissionSet

Pobiera zestaw dotacji bieżącego zestawu dynamicznego.

PermissionSet

Pobiera zestaw dotacji bieżącego zestawu.

(Odziedziczone po Assembly)
ReflectionOnly

Pobiera wartość wskazującą, czy zestaw dynamiczny znajduje się w kontekście tylko odbicia.

ReflectionOnly

Pobiera wartość wskazującą, Boolean czy ten zestaw został załadowany do kontekstu tylko odbicia.

(Odziedziczone po Assembly)
SecurityRuleSet

Pobiera wartość wskazującą, który zestaw reguł zabezpieczeń wymusza środowisko uruchomieniowe języka wspólnego (CLR) dla tego zestawu.

SecurityRuleSet

Pobiera wartość wskazującą, który zestaw reguł zabezpieczeń wymusza środowisko uruchomieniowe języka wspólnego (CLR) dla tego zestawu.

(Odziedziczone po Assembly)

Metody

AddResourceFile(String, String)

Dodaje istniejący plik zasobów do tego zestawu.

AddResourceFile(String, String, ResourceAttributes)

Dodaje istniejący plik zasobów do tego zestawu.

CreateInstance(String)

Lokalizuje określony typ z tego zestawu i tworzy wystąpienie przy użyciu aktywatora systemu przy użyciu funkcji wyszukiwania uwzględniającego wielkość liter.

(Odziedziczone po Assembly)
CreateInstance(String, Boolean)

Lokalizuje określony typ z tego zestawu i tworzy wystąpienie przy użyciu aktywatora systemu z opcjonalnym wyszukiwaniem uwzględniającym wielkość liter.

(Odziedziczone po Assembly)
CreateInstance(String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])

Lokalizuje określony typ z tego zestawu i tworzy wystąpienie przy użyciu aktywatora systemu, z opcjonalnym wyszukiwaniem z uwzględnieniem wielkości liter oraz o określonej kulturze, argumentach i powiązaniach i atrybutach aktywacji.

(Odziedziczone po Assembly)
DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess)

Definiuje zestaw dynamiczny, który ma określoną nazwę i prawa dostępu.

DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, IEnumerable<CustomAttributeBuilder>)

Definiuje nowy zestaw, który ma określoną nazwę, prawa dostępu i atrybuty.

DefineDynamicModule(String)

Definiuje nazwany moduł dynamiczny przejściowy w tym zestawie.

DefineDynamicModule(String, Boolean)

Definiuje nazwany moduł dynamiczny przejściowy w tym zestawie i określa, czy informacje o symbolach powinny być emitowane.

DefineDynamicModule(String, String)

Definiuje trwały moduł dynamiczny o podanej nazwie, która zostanie zapisana w określonym pliku. Nie są emitowane żadne informacje o symbolach.

DefineDynamicModule(String, String, Boolean)

Definiuje trwały moduł dynamiczny, określając nazwę modułu, nazwę pliku, do którego zostanie zapisany moduł, oraz określa, czy informacje o symbolach powinny być emitowane przy użyciu domyślnego modułu zapisywania symboli.

DefineDynamicModuleCore(String)

Po zastąpieniu w klasie pochodnej definiuje moduł dynamiczny w tym zestawie.

DefinePersistedAssembly(AssemblyName, Assembly, IEnumerable<CustomAttributeBuilder>)

Definiuje i reprezentuje zestaw dynamiczny.

DefineResource(String, String, String)

Definiuje autonomiczny zasób zarządzany dla tego zestawu z domyślnym atrybutem zasobu publicznego.

DefineResource(String, String, String, ResourceAttributes)

Definiuje autonomiczny zasób zarządzany dla tego zestawu. Atrybuty można określić dla zasobu zarządzanego.

DefineUnmanagedResource(Byte[])

Definiuje niezarządzany zasób dla tego zestawu jako nieprzezroczysty obiekt blob bajtów.

DefineUnmanagedResource(String)

Definiuje niezarządzany plik zasobów dla tego zestawu pod nazwą pliku zasobu.

DefineVersionInfoResource()

Definiuje niezarządzany zasób informacji o wersji przy użyciu informacji określonych w obiekcie AssemblyName zestawu i atrybutów niestandardowych zestawu.

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

Definiuje niezarządzany zasób informacji o wersji dla tego zestawu z podanymi specyfikacjami.

Equals(Object)

Zwraca wartość wskazującą, czy to wystąpienie jest równe określonemu obiektowi.

Equals(Object)

Określa, czy ten zestaw i określony obiekt są równe.

(Odziedziczone po Assembly)
GetCustomAttributes(Boolean)

Zwraca wszystkie atrybuty niestandardowe, które zostały zastosowane do bieżącego AssemblyBuilderelementu .

GetCustomAttributes(Boolean)

Pobiera wszystkie atrybuty niestandardowe dla tego zestawu.

(Odziedziczone po Assembly)
GetCustomAttributes(Type, Boolean)

Zwraca wszystkie atrybuty niestandardowe, które zostały zastosowane do bieżącego AssemblyBuilderelementu i pochodzą z określonego typu atrybutu.

GetCustomAttributes(Type, Boolean)

Pobiera atrybuty niestandardowe dla tego zestawu zgodnie z typem.

(Odziedziczone po Assembly)
GetCustomAttributesData()

Zwraca CustomAttributeData obiekty zawierające informacje o atrybutach, które zostały zastosowane do bieżącego AssemblyBuilderelementu .

GetCustomAttributesData()

Zwraca informacje o atrybutach, które zostały zastosowane do bieżącej Assemblywartości , wyrażonej jako CustomAttributeData obiekty.

(Odziedziczone po Assembly)
GetDynamicModule(String)

Zwraca moduł dynamiczny o określonej nazwie.

GetDynamicModuleCore(String)

Po przesłonięciu w klasie pochodnej zwraca moduł dynamiczny o określonej nazwie.

GetExportedTypes()

Pobiera wyeksportowane typy zdefiniowane w tym zestawie.

GetExportedTypes()

Pobiera typy publiczne zdefiniowane w tym zestawie, które są widoczne poza zestawem.

(Odziedziczone po Assembly)
GetFile(String)

Pobiera element FileStream dla określonego pliku w tabeli plików manifestu tego zestawu.

GetFile(String)

Pobiera element FileStream dla określonego pliku w tabeli plików manifestu tego zestawu.

(Odziedziczone po Assembly)
GetFiles()

Pobiera pliki w tabeli plików manifestu zestawu.

(Odziedziczone po Assembly)
GetFiles(Boolean)

Pobiera pliki w tabeli plików manifestu zestawu, określając, czy mają być uwzględniane moduły zasobów.

GetFiles(Boolean)

Pobiera pliki w tabeli plików manifestu zestawu, określając, czy należy uwzględnić moduły zasobów.

(Odziedziczone po Assembly)
GetForwardedTypes()

Definiuje i reprezentuje zestaw dynamiczny.

(Odziedziczone po Assembly)
GetHashCode()

Zwraca wartość skrótu dla tego wystąpienia.

GetHashCode()

Zwraca wartość skrótu dla tego wystąpienia.

(Odziedziczone po Assembly)
GetLoadedModules()

Pobiera wszystkie załadowane moduły, które są częścią tego zestawu.

(Odziedziczone po Assembly)
GetLoadedModules(Boolean)

Zwraca wszystkie załadowane moduły, które są częścią tego zestawu, i opcjonalnie zawiera moduły zasobów.

GetLoadedModules(Boolean)

Pobiera wszystkie załadowane moduły, które są częścią tego zestawu, określając, czy należy uwzględnić moduły zasobów.

(Odziedziczone po Assembly)
GetManifestResourceInfo(String)

Zwraca informacje o tym, jak dany zasób został utrwalone.

GetManifestResourceNames()

Ładuje określony zasób manifestu z tego zestawu.

GetManifestResourceStream(String)

Ładuje określony zasób manifestu z tego zestawu.

GetManifestResourceStream(Type, String)

Ładuje określony zasób manifestu, o zakresie według przestrzeni nazw określonego typu, z tego zestawu.

GetManifestResourceStream(Type, String)

Ładuje określony zasób manifestu o określonym zakresie według przestrzeni nazw określonego typu z tego zestawu.

(Odziedziczone po Assembly)
GetModule(String)

Pobiera określony moduł w tym zestawie.

GetModule(String)

Pobiera określony moduł w tym zestawie.

(Odziedziczone po Assembly)
GetModules()

Pobiera wszystkie moduły, które są częścią tego zestawu.

(Odziedziczone po Assembly)
GetModules(Boolean)

Pobiera wszystkie moduły będące częścią tego zestawu i opcjonalnie obejmuje moduły zasobów.

GetModules(Boolean)

Pobiera wszystkie moduły, które są częścią tego zestawu, określając, czy należy uwzględnić moduły zasobów.

(Odziedziczone po Assembly)
GetName()

Pobiera element AssemblyName dla tego zestawu.

(Odziedziczone po Assembly)
GetName(Boolean)

Pobiera element AssemblyName określony podczas tworzenia bieżącego zestawu dynamicznego i ustawia bazę kodu zgodnie z określonymi ustawieniami.

GetName(Boolean)

Pobiera element AssemblyName dla tego zestawu, ustawiając bazę kodu zgodnie z wartością copiedName.

(Odziedziczone po Assembly)
GetObjectData(SerializationInfo, StreamingContext)
Przestarzałe.

Pobiera informacje o serializacji ze wszystkimi danymi potrzebnymi do przywrócenia tego zestawu.

(Odziedziczone po Assembly)
GetReferencedAssemblies()

Pobiera niekompletną listę AssemblyName obiektów dla zestawów, do których odwołuje się ten AssemblyBuilderelement .

GetReferencedAssemblies()

AssemblyName Pobiera obiekty dla wszystkich zestawów, do których odwołuje się ten zestaw.

(Odziedziczone po Assembly)
GetSatelliteAssembly(CultureInfo)

Pobiera zestaw satelickich dla określonej kultury.

GetSatelliteAssembly(CultureInfo)

Pobiera zestaw satelitarny dla określonej kultury.

(Odziedziczone po Assembly)
GetSatelliteAssembly(CultureInfo, Version)

Pobiera określoną wersję zestawu satelitarnego dla określonej kultury.

GetSatelliteAssembly(CultureInfo, Version)

Pobiera określoną wersję zestawu satelitarnego dla określonej kultury.

(Odziedziczone po Assembly)
GetType()

Definiuje i reprezentuje zestaw dynamiczny.

(Odziedziczone po Assembly)
GetType(String)

Type Pobiera obiekt o określonej nazwie w wystąpieniu zestawu.

(Odziedziczone po Assembly)
GetType(String, Boolean)

Type Pobiera obiekt o określonej nazwie w wystąpieniu zestawu i opcjonalnie zgłasza wyjątek, jeśli typ nie zostanie znaleziony.

(Odziedziczone po Assembly)
GetType(String, Boolean, Boolean)

Pobiera określony typ z typów, które zostały zdefiniowane i utworzone w bieżącym AssemblyBuilderobiekcie .

GetType(String, Boolean, Boolean)

Type Pobiera obiekt o określonej nazwie w wystąpieniu zestawu, z opcjami ignorowania przypadku i zgłaszania wyjątku, jeśli typ nie zostanie znaleziony.

(Odziedziczone po Assembly)
GetTypes()

Pobiera wszystkie typy zdefiniowane w tym zestawie.

(Odziedziczone po Assembly)
IsDefined(Type, Boolean)

Zwraca wartość wskazującą, czy do tego elementu członkowskiego zastosowano co najmniej jedno wystąpienie określonego typu atrybutu.

IsDefined(Type, Boolean)

Wskazuje, czy określony atrybut został zastosowany do zestawu.

(Odziedziczone po Assembly)
LoadModule(String, Byte[])

Ładuje moduł wewnętrzny do tego zestawu z obrazem opartym na wspólnym formacie pliku obiektów (COFF) zawierającym emitowany moduł lub plik zasobu.

(Odziedziczone po Assembly)
LoadModule(String, Byte[], Byte[])

Ładuje moduł wewnętrzny do tego zestawu z obrazem opartym na wspólnym formacie pliku obiektów (COFF) zawierającym emitowany moduł lub plik zasobu. Załadowano również nieprzetworzone bajty reprezentujące symbole modułu.

(Odziedziczone po Assembly)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
Save(Stream)

Definiuje i reprezentuje zestaw dynamiczny.

Save(String)

Zapisuje ten zestaw dynamiczny na dysku.

Save(String, PortableExecutableKinds, ImageFileMachine)

Zapisuje ten zestaw dynamiczny na dysku, określając charakter kodu w plikach wykonywalnych zestawu i platformie docelowej.

SaveCore(Stream)

Definiuje i reprezentuje zestaw dynamiczny.

SetCustomAttribute(ConstructorInfo, Byte[])

Ustaw atrybut niestandardowy w tym zestawie przy użyciu określonego obiektu blob atrybutu niestandardowego.

SetCustomAttribute(CustomAttributeBuilder)

Ustaw atrybut niestandardowy w tym zestawie przy użyciu konstruktora atrybutów niestandardowych.

SetCustomAttributeCore(ConstructorInfo, ReadOnlySpan<Byte>)

Po zastąpieniu w klasie pochodnej ustawia atrybut niestandardowy dla tego zestawu.

SetEntryPoint(MethodInfo)

Ustawia punkt wejścia dla tego zestawu dynamicznego, przy założeniu, że tworzona jest aplikacja konsolowa.

SetEntryPoint(MethodInfo, PEFileKinds)

Ustawia punkt wejścia dla tego zestawu i definiuje typ tworzonego przenośnego pliku wykonywalnego (pliku PE).

ToString()

Zwraca pełną nazwę zestawu, znaną również jako nazwę wyświetlaną.

(Odziedziczone po Assembly)

Zdarzenia

ModuleResolve

Występuje, gdy moduł ładujący klasy środowiska uruchomieniowego języka wspólnego nie może rozpoznać odwołania do wewnętrznego modułu zestawu za pomocą normalnych środków.

(Odziedziczone po Assembly)

Jawne implementacje interfejsu

_Assembly.GetType()

Zwraca typ bieżącego wystąpienia.

(Odziedziczone po Assembly)
_AssemblyBuilder.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Zestaw nazw jest mapowany na odpowiedni zestaw identyfikatorów wysyłania.

_AssemblyBuilder.GetTypeInfo(UInt32, UInt32, IntPtr)

Pobiera informacje o typie dla obiektu, których następnie można użyć do uzyskania informacji o typie interfejsu.

_AssemblyBuilder.GetTypeInfoCount(UInt32)

Pobiera informację o liczbie typów interfejsów, jakie zawiera obiekt (0 lub 1).

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

Umożliwia dostęp do właściwości i metod udostępnianych przez obiekt.

ICustomAttributeProvider.GetCustomAttributes(Boolean)

Zwraca tablicę wszystkich atrybutów niestandardowych zdefiniowanych w tym elemencie członkowskim, z wyłączeniem nazwanych atrybutów lub pustej tablicy, jeśli nie ma atrybutów niestandardowych.

(Odziedziczone po Assembly)
ICustomAttributeProvider.GetCustomAttributes(Type, Boolean)

Zwraca tablicę atrybutów niestandardowych zdefiniowanych na tym elemencie członkowskim, identyfikowaną przez typ lub pustą tablicę, jeśli nie ma atrybutów niestandardowych tego typu.

(Odziedziczone po Assembly)
ICustomAttributeProvider.IsDefined(Type, Boolean)

Wskazuje, czy na tym elemencie członkowskim zdefiniowano jedno lub więcej wystąpień attributeType .

(Odziedziczone po Assembly)

Metody rozszerzania

GetExportedTypes(Assembly)

Definiuje i reprezentuje zestaw dynamiczny.

GetModules(Assembly)

Definiuje i reprezentuje zestaw dynamiczny.

GetTypes(Assembly)

Definiuje i reprezentuje zestaw dynamiczny.

GetCustomAttribute(Assembly, Type)

Pobiera atrybut niestandardowy określonego typu, który jest stosowany do określonego zestawu.

GetCustomAttribute<T>(Assembly)

Pobiera atrybut niestandardowy określonego typu, który jest stosowany do określonego zestawu.

GetCustomAttributes(Assembly)

Pobiera kolekcję atrybutów niestandardowych, które są stosowane do określonego zestawu.

GetCustomAttributes(Assembly, Type)

Pobiera kolekcję atrybutów niestandardowych określonego typu, które są stosowane do określonego zestawu.

GetCustomAttributes<T>(Assembly)

Pobiera kolekcję atrybutów niestandardowych określonego typu, które są stosowane do określonego zestawu.

IsDefined(Assembly, Type)

Wskazuje, czy atrybuty niestandardowe określonego typu są stosowane do określonego zestawu.

TryGetRawMetadata(Assembly, Byte*, Int32)

Pobiera sekcję metadanych zestawu do użycia z MetadataReaderprogramem .

Dotyczy

Zobacz też