Export (0) Print
Expand All

EnumBuilder.GUID Property

Returns the GUID of this enum.

Namespace:  System.Reflection.Emit
Assembly:  mscorlib (in mscorlib.dll)

public override Guid GUID { get; }

Property Value

Type: System.Guid
Read-only. The GUID of this enum.

Implements

_Type.GUID

ExceptionCondition
NotSupportedException

This method is not currently supported in types that are not complete.

The following code sample demonstrates the use of the GUID property to reference the associated Guid of the current 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("Enum TypeToken is :" +  
                                       myEnumBuilder.TypeToken.ToString());
         Console.WriteLine("Enum UnderLyingField is :" +  
                                    myEnumBuilder.UnderlyingField.ToString());
         Console.WriteLine("Enum UnderLyingSystemType is :" +  
                              myEnumBuilder.UnderlyingSystemType.ToString());
         Console.WriteLine("Enum GUID is :" + myEnumBuilder.GUID.ToString());
         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();
   }
}

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft