AssemblyBuilder Classe

Definizione

Definisce e rappresenta un assembly dinamico.

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
Ereditarietà
AssemblyBuilder
Attributi
Implementazioni

Esempio

Nell'esempio di codice seguente viene illustrato come definire e usare un assembly dinamico. L'assembly di esempio contiene un tipo, MyDynamicType, con un campo privato, una proprietà che ottiene e imposta il campo privato, i costruttori che inizializzano il campo privato e un metodo che moltiplica un numero fornito dall'utente in base al valore del campo privato e restituisce il risultato.

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

Commenti

Per altre informazioni su questa API, vedere Note sulle API supplementari per AssemblyBuilder.

Costruttori

AssemblyBuilder()

Inizializza una nuova istanza della classe AssemblyBuilder.

Proprietà

CodeBase
Obsoleti.

Ottiene la posizione dell'assembly come specificata in origine, ad esempio in un oggetto AssemblyName.

CodeBase
Obsoleti.
Obsoleti.

Ottiene il percorso dell'assembly come originariamente specificato, ad esempio in un oggetto AssemblyName.

(Ereditato da Assembly)
CustomAttributes

Ottiene una raccolta che contiene gli attributi personalizzati di questo assembly.

(Ereditato da Assembly)
DefinedTypes

Definisce e rappresenta un assembly dinamico.

DefinedTypes

Ottiene una raccolta dei tipi definiti in questo assembly.

(Ereditato da Assembly)
EntryPoint

Restituisce il punto di ingresso di questo assembly.

EntryPoint

Ottiene il punto di ingresso di questo assembly.

(Ereditato da Assembly)
EscapedCodeBase
Obsoleti.
Obsoleti.

Ottiene l'URI, inclusi i caratteri di escape, che rappresenta la codebase.

(Ereditato da Assembly)
Evidence

Ottiene l'evidenza per questo assembly.

Evidence

Ottiene l'evidenza per questo assembly.

(Ereditato da Assembly)
ExportedTypes

Ottiene una raccolta dei tipi pubblici definiti in questo assembly visibili all'esterno dell'assembly.

(Ereditato da Assembly)
FullName

Ottiene il nome visualizzato dell'assembly dinamico corrente.

FullName

Ottiene il nome visualizzato dell'assembly.

(Ereditato da Assembly)
GlobalAssemblyCache
Obsoleti.

Ottiene un valore che indica se l'assembly è stato caricato dalla Global Assembly Cache.

GlobalAssemblyCache
Obsoleti.

Ottiene un valore che indica se l'assembly è stato caricato dalla global assembly cache (solo.NET Framework).

(Ereditato da Assembly)
HostContext

Ottiene il contesto host in cui viene creato l'assembly dinamico.

HostContext

Ottiene il contesto host con cui l'assembly è stato caricato.

(Ereditato da Assembly)
ImageRuntimeVersion

Ottiene la versione di Common Language Runtime che verrà salvata nel file che contiene il manifesto.

ImageRuntimeVersion

Ottiene una stringa che rappresenta la versione di CLR (Common Language Runtime) salvata nel file che contiene il manifesto.

(Ereditato da Assembly)
IsCollectible

Ottiene un valore che indica se questo assembly dinamico viene mantenuto in un oggetto collectible AssemblyLoadContext.

IsCollectible

Ottiene un valore che indica se questo assembly viene mantenuto in un AssemblyLoadContext ritirabile.

(Ereditato da Assembly)
IsDynamic

Ottiene un valore che indica che l'assembly corrente è un assembly dinamico.

IsDynamic

Ottiene un valore che indica se l'assembly corrente è stato generato dinamicamente nel processo corrente tramite reflection emit.

(Ereditato da Assembly)
IsFullyTrusted

Ottiene un valore che indica se l'assembly corrente viene caricato con attendibilità totale.

(Ereditato da Assembly)
Location

Ottiene il percorso, in formato codebase, del file caricato che contiene il manifesto se non ne viene creata una copia shadow.

Location

Ottiene il percorso completo o il percorso UNC del file caricato che contiene il manifesto.

(Ereditato da Assembly)
ManifestModule

Ottiene il modulo nell'oggetto AssemblyBuilder corrente che contiene il manifesto dell'assembly.

ManifestModule

Ottiene il modulo contenente il manifesto per l'assembly corrente.

(Ereditato da Assembly)
Modules

Definisce e rappresenta un assembly dinamico.

Modules

Ottiene una raccolta contenente i moduli dell'assembly.

(Ereditato da Assembly)
PermissionSet

Ottiene l’insieme di autorizzazioni dell'assembly dinamico corrente.

PermissionSet

Ottiene il set di concessioni dell'assembly corrente.

(Ereditato da Assembly)
ReflectionOnly

Ottiene un valore che indica se l'assembly dinamico si trova nel contesto Reflection-Only.

ReflectionOnly

Ottiene un valore Boolean che indica se l'assembly è stato caricato nel contesto ReflectionOnly.

(Ereditato da Assembly)
SecurityRuleSet

Ottiene un valore che indica il set di regole di sicurezza applicato da Common Language Runtime (CLR) per questo assembly.

SecurityRuleSet

Ottiene un valore che indica il set di regole di sicurezza applicato da Common Language Runtime (CLR) per questo assembly.

(Ereditato da Assembly)

Metodi

AddResourceFile(String, String)

Aggiunge un file di risorse esistenti a questo assembly.

AddResourceFile(String, String, ResourceAttributes)

Aggiunge un file di risorse esistenti a questo assembly.

CreateInstance(String)

Individua il tipo specificato in questo assembly e ne crea un'istanza usando l'attivatore di sistema e consentendo la ricerca con distinzione tra maiuscole e minuscole.

(Ereditato da Assembly)
CreateInstance(String, Boolean)

Individua il tipo specificato in questo assembly e ne crea un'istanza usando l'attivatore di sistema e consentendo la ricerca con distinzione facoltativa tra maiuscole e minuscole.

(Ereditato da Assembly)
CreateInstance(String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])

Individua il tipo specificato in questo assembly e ne crea un'istanza usando l'attivatore di sistema, consentendo la ricerca con distinzione facoltativa tra maiuscole e minuscole e usando le impostazioni cultura, gli argomenti e gli attributi di attivazione e di binding specificati.

(Ereditato da Assembly)
DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess)

Definisce un assembly dinamico con il nome e la modalità di accesso specificati.

DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, IEnumerable<CustomAttributeBuilder>)

Definisce un nuovo assembly con il nome, i diritti di accesso e gli attributi specificati.

DefineDynamicModule(String)

Definisce un modulo dinamico temporaneo denominato in questo assembly.

DefineDynamicModule(String, Boolean)

Definisce un modulo dinamico temporaneo denominato nell'assembly e specifica se le informazioni sui simboli devono essere emesse.

DefineDynamicModule(String, String)

Definisce un modulo dinamico persistente con il nome specificato che sarà salvato nel file specificato. Non vengono emesse informazioni sui simboli.

DefineDynamicModule(String, String, Boolean)

Definisce un modulo dinamico persistente, specificando il nome del modulo, il nome del file in cui verrà salvato il modulo e se le informazioni sui simboli devono essere generate usando il writer di simboli predefinito.

DefineDynamicModuleCore(String)

Quando sottoposto a override in una classe derivata, definisce un modulo dinamico in questo assembly.

DefinePersistedAssembly(AssemblyName, Assembly, IEnumerable<CustomAttributeBuilder>)

Definisce e rappresenta un assembly dinamico.

DefineResource(String, String, String)

Definisce una risorsa gestita autonoma per questo assembly con l'attributo di risorsa pubblica predefinito.

DefineResource(String, String, String, ResourceAttributes)

Definisce una risorsa gestita autonoma per questo assembly. È possibile specificare gli attributi per la risorsa gestita.

DefineUnmanagedResource(Byte[])

Definisce una risorsa non gestita per questo assembly come BLOB opaco di byte.

DefineUnmanagedResource(String)

Definisce un file di risorse non gestite per l'assembly, dato il nome del file di risorse.

DefineVersionInfoResource()

Definisce una risorsa di informazioni di versione non gestita usando le informazioni specificate nell'oggetto AssemblyName dell'assembly e gli attributi personalizzati dell'assembly.

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

Definisce una risorsa di informazioni sulla versione non gestita per questo assembly insieme alle specifiche date.

Equals(Object)

Restituisce un valore che indica se questa istanza è uguale all'oggetto specificato.

Equals(Object)

Determina se questo assembly e l'oggetto specificato sono uguali.

(Ereditato da Assembly)
GetCustomAttributes(Boolean)

Restituisce tutti gli attributi personalizzati applicati all'oggetto AssemblyBuilder corrente.

GetCustomAttributes(Boolean)

Ottiene tutti gli attributi personalizzati per questo assembly.

(Ereditato da Assembly)
GetCustomAttributes(Type, Boolean)

Restituisce tutti gli attributi personalizzati applicati all'oggetto AssemblyBuilder corrente e che derivano da un tipo di attributo specificato.

GetCustomAttributes(Type, Boolean)

Ottiene gli attributi personalizzati per questo assembly, come specificato dal tipo.

(Ereditato da Assembly)
GetCustomAttributesData()

Restituisce gli oggetti CustomAttributeData che contengono informazioni sugli attributi applicati all'oggetto AssemblyBuilder corrente.

GetCustomAttributesData()

Restituisce informazioni sugli attributi applicati all'oggetto Assembly corrente, espresse sotto forma di oggetti CustomAttributeData.

(Ereditato da Assembly)
GetDynamicModule(String)

Restituisce il modulo dinamico con il nome specificato.

GetDynamicModuleCore(String)

Quando sottoposto a override in una classe derivata, restituisce il modulo dinamico con il nome specificato.

GetExportedTypes()

Ottiene i tipi esportati definiti in questo assembly.

GetExportedTypes()

Ottiene i tipi pubblici definiti nell'assembly visibili all'esterno dell'assembly.

(Ereditato da Assembly)
GetFile(String)

Ottiene un oggetto FileStream per il file specificato nella tabella file del manifesto dell'assembly.

GetFile(String)

Ottiene un oggetto FileStream per il file specificato nella tabella file del manifesto dell'assembly.

(Ereditato da Assembly)
GetFiles()

Ottiene i file della tabella file di un manifesto dell'assembly.

(Ereditato da Assembly)
GetFiles(Boolean)

Ottiene i file della tabella file di un manifesto dell'assembly, specificando se includere i moduli delle risorse.

GetFiles(Boolean)

Ottiene i file della tabella file di un manifesto dell'assembly, specificando se includere i moduli delle risorse.

(Ereditato da Assembly)
GetForwardedTypes()

Definisce e rappresenta un assembly dinamico.

(Ereditato da Assembly)
GetHashCode()

Restituisce il codice hash per l'istanza.

GetHashCode()

Restituisce il codice hash per l'istanza.

(Ereditato da Assembly)
GetLoadedModules()

Ottiene tutti i moduli caricati che fanno parte di questo assembly.

(Ereditato da Assembly)
GetLoadedModules(Boolean)

Restituisce tutti i moduli caricati che fanno parte di questo assembly e facoltativamente include moduli di risorse.

GetLoadedModules(Boolean)

Ottiene tutti i moduli caricati che fanno parte di questo assembly, specificando se includere i moduli delle risorse.

(Ereditato da Assembly)
GetManifestResourceInfo(String)

Restituisce informazioni sul modo in cui la risorsa specificata è stata resa persistente.

GetManifestResourceNames()

Carica la risorsa del manifesto specificata da questo assembly.

GetManifestResourceStream(String)

Carica la risorsa del manifesto specificata da questo assembly.

GetManifestResourceStream(Type, String)

Carica la risorsa del manifesto specificata, definita per l'ambito dallo spazio dei nomi del tipo specificato, da questo assembly.

GetManifestResourceStream(Type, String)

Carica la risorsa del manifesto specificata, definita per l'ambito dallo spazio dei nomi del tipo specificato, da questo assembly.

(Ereditato da Assembly)
GetModule(String)

Ottiene il modulo specificato in questo assembly.

GetModule(String)

Ottiene il modulo specificato in questo assembly.

(Ereditato da Assembly)
GetModules()

Ottiene tutti i moduli che fanno parte di questo assembly.

(Ereditato da Assembly)
GetModules(Boolean)

Ottiene tutti i moduli che fanno parte di questo assembly e facoltativamente include moduli di risorse.

GetModules(Boolean)

Ottiene tutti i moduli che fanno parte di questo assembly, specificando se includere i moduli delle risorse.

(Ereditato da Assembly)
GetName()

Ottiene un oggetto AssemblyName per questo assembly.

(Ereditato da Assembly)
GetName(Boolean)

Ottiene l'oggetto AssemblyName specificato durante la creazione dell'assembly dinamico corrente e imposta la codebase indicata.

GetName(Boolean)

Ottiene un oggetto AssemblyName per questo assembly, impostando la codebase come specificato da copiedName.

(Ereditato da Assembly)
GetObjectData(SerializationInfo, StreamingContext)
Obsoleti.

Ottiene le informazioni sulla serializzazione con tutti i dati necessari per creare una nuova istanza di questo assembly.

(Ereditato da Assembly)
GetReferencedAssemblies()

Ottiene un elenco incompleto di oggetti AssemblyName per gli assembly a cui fa riferimento AssemblyBuilder.

GetReferencedAssemblies()

Ottiene gli oggetti AssemblyName per tutti gli assembly a cui fa riferimento questo assembly.

(Ereditato da Assembly)
GetSatelliteAssembly(CultureInfo)

Ottiene l'assembly satellite per le impostazioni cultura specificate.

GetSatelliteAssembly(CultureInfo)

Ottiene l'assembly satellite per le impostazioni cultura specificate.

(Ereditato da Assembly)
GetSatelliteAssembly(CultureInfo, Version)

Ottiene la versione specificata dell'assembly satellite per le impostazioni cultura specificate.

GetSatelliteAssembly(CultureInfo, Version)

Ottiene la versione specificata dell'assembly satellite per le impostazioni cultura specificate.

(Ereditato da Assembly)
GetType()

Definisce e rappresenta un assembly dinamico.

(Ereditato da Assembly)
GetType(String)

Ottiene l'oggetto Type con il nome specificato nell'istanza dell'assembly.

(Ereditato da Assembly)
GetType(String, Boolean)

Ottiene l'oggetto Type con il nome specificato nell'istanza dell'assembly e facoltativamente genera un'eccezione se il tipo non viene trovato.

(Ereditato da Assembly)
GetType(String, Boolean, Boolean)

Ottiene il tipo specificato dai tipi che sono stati definiti e creati nella classe AssemblyBuilder corrente.

GetType(String, Boolean, Boolean)

Ottiene l'oggetto Type con il nome specificato nell'istanza dell'assembly, con la possibilità di ignorare la distinzione tra maiuscole e minuscole e di generare un'eccezione se il tipo non viene trovato.

(Ereditato da Assembly)
GetTypes()

Ottiene tutti i tipi definiti in questo assembly.

(Ereditato da Assembly)
IsDefined(Type, Boolean)

Restituisce un valore che indica se una o più istanze del tipo di attributo specificato viene applicata a questo membro.

IsDefined(Type, Boolean)

Indica se è stato applicato un attributo specificato all'assembly.

(Ereditato da Assembly)
LoadModule(String, Byte[])

Carica il modulo, interno all'assembly, con un'immagine in formato COFF (Common Object File Format) contenente un modulo generato o un file di risorse.

(Ereditato da Assembly)
LoadModule(String, Byte[], Byte[])

Carica il modulo, interno all'assembly, con un'immagine in formato COFF (Common Object File Format) contenente un modulo generato o un file di risorse. Vengono caricati anche i byte non elaborati che rappresentano i simboli per il modulo.

(Ereditato da Assembly)
MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.

(Ereditato da Object)
Save(Stream)

Definisce e rappresenta un assembly dinamico.

Save(String)

Salva l'assembly dinamico sul disco.

Save(String, PortableExecutableKinds, ImageFileMachine)

Salva l'assembly dinamico su disco, specificando la natura del codice nei file eseguibili dell'assembly e la piattaforma di destinazione.

SaveCore(Stream)

Definisce e rappresenta un assembly dinamico.

SetCustomAttribute(ConstructorInfo, Byte[])

Imposta un attributo personalizzato nell'assembly usando un BLOB di attributi personalizzati specificato.

SetCustomAttribute(CustomAttributeBuilder)

Impostare un attributo personalizzato nell'assembly usando un generatore di attributi personalizzati.

SetCustomAttributeCore(ConstructorInfo, ReadOnlySpan<Byte>)

Quando ne viene eseguito l'override in una classe derivata, imposta un attributo personalizzato su questo assembly.

SetEntryPoint(MethodInfo)

Imposta il punto di ingresso per questo assembly dinamico, presupponendo che si sta creando un'applicazione console.

SetEntryPoint(MethodInfo, PEFileKinds)

Imposta il punto di ingresso dell'assembly e definisce il tipo del file eseguibile di tipo PE in corso di compilazione.

ToString()

Restituisce il nome completo dell'assembly, noto anche come nome visualizzato.

(Ereditato da Assembly)

Eventi

ModuleResolve

Si verifica quando il caricatore della classe Common Language Runtime non è in grado di risolvere un riferimento a un modulo interno di un assembly in modo normale.

(Ereditato da Assembly)

Implementazioni dell'interfaccia esplicita

_Assembly.GetType()

Restituisce il tipo dell'istanza corrente.

(Ereditato da Assembly)
_AssemblyBuilder.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Esegue il mapping di un set di nomi a un set corrispondente di ID dispatch.

_AssemblyBuilder.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera le informazioni sul tipo relative a un oggetto che può quindi essere usato per ottenere informazioni sul tipo relative a un'interfaccia.

_AssemblyBuilder.GetTypeInfoCount(UInt32)

Recupera il numero delle interfacce di informazioni sul tipo fornite da un oggetto (0 o 1).

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

Fornisce l'accesso a proprietà e metodi esposti da un oggetto.

ICustomAttributeProvider.GetCustomAttributes(Boolean)

Restituisce una matrice di tutti gli attributi personalizzati definiti in questo membro, esclusi gli attributi denominati, oppure una matrice vuota se non sono presenti attributi personalizzati.

(Ereditato da Assembly)
ICustomAttributeProvider.GetCustomAttributes(Type, Boolean)

Restituisce una matrice di attributi personalizzati definiti in questo membro, identificati dal tipo o da una matrice vuota, se non sono presenti attributi personalizzati di quel tipo.

(Ereditato da Assembly)
ICustomAttributeProvider.IsDefined(Type, Boolean)

Indica se per questo membro sono definite una o più istanze di attributeType.

(Ereditato da Assembly)

Metodi di estensione

GetExportedTypes(Assembly)

Definisce e rappresenta un assembly dinamico.

GetModules(Assembly)

Definisce e rappresenta un assembly dinamico.

GetTypes(Assembly)

Definisce e rappresenta un assembly dinamico.

GetCustomAttribute(Assembly, Type)

Recupera una attributo personalizzato di un tipo specificato che viene applicato a un assembly specificato.

GetCustomAttribute<T>(Assembly)

Recupera una attributo personalizzato di un tipo specificato che viene applicato a un assembly specificato.

GetCustomAttributes(Assembly)

Recupera una raccolta di attributi personalizzati che vengono applicati a un assembly specificato.

GetCustomAttributes(Assembly, Type)

Recupera una raccolta di attributi personalizzati di un tipo specificato che vengono applicati a un assembly specificato.

GetCustomAttributes<T>(Assembly)

Recupera una raccolta di attributi personalizzati di un tipo specificato che vengono applicati a un assembly specificato.

IsDefined(Assembly, Type)

Indica se vengono applicati attributi personalizzati del tipo specificato a un assembly specificato.

TryGetRawMetadata(Assembly, Byte*, Int32)

Recupera la sezione dei metadati dell'assembly, da usare con MetadataReader.

Si applica a

Vedi anche