This documentation is archived and is not being maintained.

EnumBuilder::GUID Property

Returns the GUID of this enum.

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

virtual property Guid GUID {
	Guid get () override;

Property Value

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




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 namespace System;
using namespace System::Collections;
using namespace System::Threading;
using namespace System::Reflection;
using namespace System::Reflection::Emit;
public ref class MyEnumBuilderSample
   static AssemblyBuilder^ myAssemblyBuilder;
   static ModuleBuilder^ myModuleBuilder;
   static EnumBuilder^ myEnumBuilder;

   static void Main()
         CreateCallee( Thread::GetDomain(), AssemblyBuilderAccess::Save );
         array<Type^>^myTypeArray = myModuleBuilder->GetTypes();
         IEnumerator^ myEnum = myTypeArray->GetEnumerator();
         while ( myEnum->MoveNext() )
            Type^ myType = safe_cast<Type^>(myEnum->Current);
            Console::WriteLine( "Enum Builder defined in the module builder is: {0}", myType->Name );
         Console::WriteLine( "Enum TypeToken is :{0}", myEnumBuilder->TypeToken );
         Console::WriteLine( "Enum UnderLyingField is :{0}", myEnumBuilder->UnderlyingField );
         Console::WriteLine( "Enum UnderLyingSystemType is :{0}", myEnumBuilder->UnderlyingSystemType );
         Console::WriteLine( "Enum GUID is :{0}", myEnumBuilder->GUID );
         myAssemblyBuilder->Save( "EmittedAssembly.dll" );
      catch ( NotSupportedException^ ex ) 
         Console::WriteLine( "The following is the exception is raised: {0}", ex->Message );
      catch ( Exception^ e ) 
         Console::WriteLine( "The following is the exception raised: {0}", e->Message );

   static void CreateCallee( AppDomain^ myAppDomain, AssemblyBuilderAccess /*access*/ )
      // Create a name for the assembly.
      AssemblyName^ myAssemblyName = gcnew 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, Int32::typeid );
      FieldBuilder^ myFieldBuilder1 = myEnumBuilder->DefineLiteral( "FieldOne", 1 );
      FieldBuilder^ myFieldBuilder2 = myEnumBuilder->DefineLiteral( "FieldTwo", 2 );

int main()

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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