EnumBuilder 클래스
열거형을 설명하고 나타냅니다.
네임스페이스: System.Reflection.Emit
어셈블리: mscorlib(mscorlib.dll)
구문
‘선언
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.None)> _
Public NotInheritable Class EnumBuilder
Inherits Type
Implements _EnumBuilder
‘사용 방법
Dim instance As EnumBuilder
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType.None)]
public sealed class EnumBuilder : Type, _EnumBuilder
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType::None)]
public ref class EnumBuilder sealed : public Type, _EnumBuilder
/** @attribute ComVisibleAttribute(true) */
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.None) */
public final class EnumBuilder extends Type implements _EnumBuilder
ComVisibleAttribute(true)
ClassInterfaceAttribute(ClassInterfaceType.None)
public final class EnumBuilder extends Type implements _EnumBuilder
예제
다음 코드 예제에서는 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
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();
}
}
using namespace System;
using namespace System::Collections;
using namespace System::Threading;
using namespace System::Reflection;
using namespace System::Reflection::Emit;
public ref class MyEnumBuilderSample
{
private:
static AssemblyBuilder^ myAssemblyBuilder;
static ModuleBuilder^ myModuleBuilder;
static EnumBuilder^ myEnumBuilder;
public:
static void Main()
{
try
{
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 );
}
}
private:
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 );
myEnumBuilder->CreateType();
}
};
int main()
{
MyEnumBuilderSample::Main();
}
import System.*;
import System.Collections.*;
import System.Threading.*;
import System.Reflection.*;
import System.Reflection.Emit.*;
public class MyEnumBuilderSample
{
private static AssemblyBuilder myAssemblyBuilder;
private static ModuleBuilder myModuleBuilder;
private static EnumBuilder myEnumBuilder;
public static void main(String[] args)
{
try {
CreateCallee(System.Threading.Thread.GetDomain(),
AssemblyBuilderAccess.Save);
Type myTypeArray[] = myModuleBuilder.GetTypes();
Type myType = null;
for (int iCtr = 0; iCtr < myTypeArray.length;iCtr++ ) {
myType = myTypeArray[iCtr];
Console.WriteLine("Enum Builder defined in the module "
+ "builder is: " + myType.get_Name());
}
Console.WriteLine("Enum TypeToken is :"
+ myEnumBuilder.get_TypeToken().ToString());
Console.WriteLine("Enum UnderLyingField is :"
+ myEnumBuilder.get_UnderlyingField().ToString());
Console.WriteLine("Enum UnderLyingSystemType is :"
+ myEnumBuilder.get_UnderlyingSystemType().ToString());
Console.WriteLine("Enum GUID is :"
+ myEnumBuilder.get_GUID().ToString());
myAssemblyBuilder.Save("EmittedAssembly.dll");
}
catch (NotSupportedException ex) {
Console.WriteLine("The following is the exception is raised: "
+ ex.get_Message());
}
catch (System.Exception e) {
Console.WriteLine("The following is the exception raised: "
+ e.get_Message());
}
} //main
private static void CreateCallee(AppDomain myAppDomain,
AssemblyBuilderAccess access)
{
// Create a name for the assembly.
AssemblyName myAssemblyName = new AssemblyName();
myAssemblyName.set_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.class.ToType());
FieldBuilder myFieldBuilder1 = myEnumBuilder.DefineLiteral("FieldOne",
(Int32)1);
FieldBuilder myFieldBuilder2 = myEnumBuilder.DefineLiteral("FieldTwo",
(Int32)2);
myEnumBuilder.CreateType();
} //CreateCallee
} //MyEnumBuilderSample
상속 계층 구조
System.Object
System.Reflection.MemberInfo
System.Type
System.Reflection.Emit.EnumBuilder
스레드로부터의 안전성
이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.
플랫폼
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원