EnumBuilder.Assembly Propriedade

Definição

Recupera o assembly dinâmico que contém essa definição enum.

public override System.Reflection.Assembly Assembly { get; }

Valor da propriedade

Somente leitura. O assembly dinâmico que contém essa definição de enumeração.

Exemplos

O exemplo de código a seguir demonstra o uso da Assembly propriedade para referenciar o assembly pai do atual EnumBuilder.

using System;
using System.Collections;
using System.Threading;
using System.Reflection;
using System.Reflection.Emit;

public class MyEnumBuilderSample
{
   static AssemblyBuilder myAssemblyBuilder;
   static ModuleBuilder myModuleBuilder;
   static EnumBuilder myEnumBuilder;

   public static void Main()
   {
      try
      {
         CreateCallee(Thread.GetDomain(), AssemblyBuilderAccess.Save);
         Type[] myTypeArray = myModuleBuilder.GetTypes();
         foreach(Type myType in myTypeArray)
         {
            Console.WriteLine("Enum Builder defined in the module builder is: "
               + myType.Name);
         }

         Console.WriteLine("Properties of EnumBuilder : ");
         Console.WriteLine("Enum Assembly is :" +  myEnumBuilder.Assembly.ToString());
         Console.WriteLine("Enum AssemblyQualifiedName is :" +
                                 myEnumBuilder.AssemblyQualifiedName.ToString());
         Console.WriteLine("Enum Module is :" +  myEnumBuilder.Module.ToString());
         Console.WriteLine("Enum Name is :" +  myEnumBuilder.Name.ToString());
         Console.WriteLine("Enum NameSpace is :" +  myEnumBuilder.Namespace);
         myAssemblyBuilder.Save("EmittedAssembly.dll");
      }
      catch(NotSupportedException ex)
      {
         Console.WriteLine("The following is the exception is raised: " + ex.Message);
      }
      catch(Exception e)
      {
         Console.WriteLine("The following is the exception raised: " + e.Message);
      }
   }

   private static void CreateCallee(AppDomain myAppDomain, AssemblyBuilderAccess access)
   {
      // Create a name for the assembly.
      AssemblyName myAssemblyName = new AssemblyName();
      myAssemblyName.Name = "EmittedAssembly";

      // Create the dynamic assembly.
      myAssemblyBuilder = myAppDomain.DefineDynamicAssembly(myAssemblyName,
                                             AssemblyBuilderAccess.Save);

      // Create a dynamic module.
      myModuleBuilder = myAssemblyBuilder.DefineDynamicModule("EmittedModule",
                                                         "EmittedModule.mod");

      // Create a dynamic Enum.
      myEnumBuilder = myModuleBuilder.DefineEnum("MyNamespace.MyEnum",
                                 TypeAttributes.Public, typeof(Int32));

      FieldBuilder myFieldBuilder1 = myEnumBuilder.DefineLiteral("FieldOne", 1);
      FieldBuilder myFieldBuilder2 = myEnumBuilder.DefineLiteral("FieldTwo", 2);

      myEnumBuilder.CreateType();
   }
}

Aplica-se a