本文整理匯總了VB.NET中System.Reflection.Emit.ModuleBuilder.DefineEnum方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET ModuleBuilder.DefineEnum方法的具體用法?VB.NET ModuleBuilder.DefineEnum怎麽用?VB.NET ModuleBuilder.DefineEnum使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Reflection.Emit.ModuleBuilder
的用法示例。
在下文中一共展示了ModuleBuilder.DefineEnum方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Example
' 導入命名空間
Imports System.Reflection
Imports System.Reflection.Emit
Module Example
Sub Main()
' Get the current application domain for the current thread.
Dim currentDomain As AppDomain = AppDomain.CurrentDomain
' Create a dynamic assembly in the current application domain,
' and allow it to be executed and saved to disk.
Dim aName As AssemblyName = New AssemblyName("TempAssembly")
Dim ab As AssemblyBuilder = currentDomain.DefineDynamicAssembly( _
aName, AssemblyBuilderAccess.RunAndSave)
' Define a dynamic module in "TempAssembly" assembly. For a single-
' module assembly, the module has the same name as the assembly.
Dim mb As ModuleBuilder = _
ab.DefineDynamicModule(aName.Name, aName.Name & ".dll")
' Define a public enumeration with the name "Elevation" and an
' underlying type of Integer.
Dim eb As EnumBuilder = _
mb.DefineEnum("Elevation", TypeAttributes.Public, GetType(Integer))
' Define two members, "High" and "Low".
eb.DefineLiteral("Low", 0)
eb.DefineLiteral("High", 1)
' Create the type and save the assembly.
Dim finished As Type = eb.CreateType()
ab.Save(aName.Name & ".dll")
For Each o As Object In [Enum].GetValues(finished)
Console.WriteLine("{0}.{1} = {2}", finished, o, CInt(o))
Next
End Sub
End Module
輸出:
Elevation.Low = 0 Elevation.High = 1