Export (0) Print
Expand All

EnumBuilder.GUID Property

Returns the GUID of this enum.

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

'Declaration
Public Overrides ReadOnly Property GUID As Guid

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.


Imports System
Imports System.Collections
Imports System.Threading
Imports System.Reflection
Imports System.Reflection.Emit

Public Class MyEnumBuilderSample
   Private Shared myAssemblyBuilder As AssemblyBuilder
   Private Shared myModuleBuilder As ModuleBuilder
   Private Shared myEnumBuilder As EnumBuilder


   Public Shared Sub Main()
      Try
         CreateCallee(Thread.GetDomain(), AssemblyBuilderAccess.Save)
         Dim myTypeArray As Type() = myModuleBuilder.GetTypes()
         Dim myType As Type
         For Each myType In  myTypeArray
            Console.WriteLine("Enum Builder defined in the module builder is: " + myType.Name)
         Next myType

         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 ex As NotSupportedException
         Console.WriteLine("The following is the exception is raised: " + ex.Message)
      Catch e As Exception
         Console.WriteLine("The following is the exception raised: " + e.Message)
      End Try
   End Sub 'Main


   Private Shared Sub CreateCallee(myAppDomain As AppDomain, access As AssemblyBuilderAccess)
      ' Create a name for the assembly.
      Dim myAssemblyName As 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, GetType(Int32))

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

      myEnumBuilder.CreateType()
   End Sub 'CreateCallee
End Class 'MyEnumBuilderSample


.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.

Community Additions

ADD
Show:
© 2014 Microsoft