TypeBuilder 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
런타임 동안 클래스의 새 인스턴스를 정의하고 만듭니다.
public ref class TypeBuilder sealed : Type, System::Runtime::InteropServices::_TypeBuilder
public ref class TypeBuilder sealed : System::Reflection::TypeInfo, System::Runtime::InteropServices::_TypeBuilder
public ref class TypeBuilder sealed : Type
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
public sealed class TypeBuilder : Type, System.Runtime.InteropServices._TypeBuilder
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class TypeBuilder : Type, System.Runtime.InteropServices._TypeBuilder
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class TypeBuilder : System.Reflection.TypeInfo, System.Runtime.InteropServices._TypeBuilder
public sealed class TypeBuilder : Type
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
type TypeBuilder = class
inherit Type
interface _TypeBuilder
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type TypeBuilder = class
inherit Type
interface _TypeBuilder
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type TypeBuilder = class
inherit TypeInfo
interface _TypeBuilder
type TypeBuilder = class
inherit Type
Public NotInheritable Class TypeBuilder
Inherits Type
Implements _TypeBuilder
Public NotInheritable Class TypeBuilder
Inherits TypeInfo
Implements _TypeBuilder
Public NotInheritable Class TypeBuilder
Inherits Type
- 상속
- 상속
- 특성
- 구현
예제
다음 코드 예제에서는 동적 어셈블리를 정의하고 사용하는 방법을 보여줍니다. 예제 어셈블리에는 프라이빗 필드가 MyDynamicType있는 형식, 프라이빗 필드를 가져오고 설정하는 속성, 프라이빗 필드를 초기화하는 생성자 및 사용자가 제공한 숫자를 개인 필드 값으로 곱하고 결과를 반환하는 메서드가 포함됩니다.
using System;
using System.Reflection;
using System.Reflection.Emit;
class DemoAssemblyBuilder
{
public static void Main()
{
// This code creates an assembly that contains one type,
// named "MyDynamicType", that has a private field, a property
// that gets and sets the private field, constructors that
// initialize the private field, and a method that multiplies
// a user-supplied number by the private field value and returns
// the result. In C# the type might look like this:
/*
public class MyDynamicType
{
private int m_number;
public MyDynamicType() : this(42) {}
public MyDynamicType(int initNumber)
{
m_number = initNumber;
}
public int Number
{
get { return m_number; }
set { m_number = value; }
}
public int MyMethod(int multiplier)
{
return m_number * multiplier;
}
}
*/
var aName = new AssemblyName("DynamicAssemblyExample");
AssemblyBuilder ab =
AssemblyBuilder.DefineDynamicAssembly(
aName,
AssemblyBuilderAccess.Run);
// The module name is usually the same as the assembly name.
ModuleBuilder mb = ab.DefineDynamicModule(aName.Name ?? "DynamicAssemblyExample");
TypeBuilder tb = mb.DefineType(
"MyDynamicType",
TypeAttributes.Public);
// Add a private field of type int (Int32).
FieldBuilder fbNumber = tb.DefineField(
"m_number",
typeof(int),
FieldAttributes.Private);
// Define a constructor that takes an integer argument and
// stores it in the private field.
Type[] parameterTypes = { typeof(int) };
ConstructorBuilder ctor1 = tb.DefineConstructor(
MethodAttributes.Public,
CallingConventions.Standard,
parameterTypes);
ILGenerator ctor1IL = ctor1.GetILGenerator();
// For a constructor, argument zero is a reference to the new
// instance. Push it on the stack before calling the base
// class constructor. Specify the default constructor of the
// base class (System.Object) by passing an empty array of
// types (Type.EmptyTypes) to GetConstructor.
ctor1IL.Emit(OpCodes.Ldarg_0);
ConstructorInfo? ci = typeof(object).GetConstructor(Type.EmptyTypes);
ctor1IL.Emit(OpCodes.Call, ci!);
// Push the instance on the stack before pushing the argument
// that is to be assigned to the private field m_number.
ctor1IL.Emit(OpCodes.Ldarg_0);
ctor1IL.Emit(OpCodes.Ldarg_1);
ctor1IL.Emit(OpCodes.Stfld, fbNumber);
ctor1IL.Emit(OpCodes.Ret);
// Define a default constructor that supplies a default value
// for the private field. For parameter types, pass the empty
// array of types or pass null.
ConstructorBuilder ctor0 = tb.DefineConstructor(
MethodAttributes.Public,
CallingConventions.Standard,
Type.EmptyTypes);
ILGenerator ctor0IL = ctor0.GetILGenerator();
// For a constructor, argument zero is a reference to the new
// instance. Push it on the stack before pushing the default
// value on the stack, then call constructor ctor1.
ctor0IL.Emit(OpCodes.Ldarg_0);
ctor0IL.Emit(OpCodes.Ldc_I4_S, 42);
ctor0IL.Emit(OpCodes.Call, ctor1);
ctor0IL.Emit(OpCodes.Ret);
// Define a property named Number that gets and sets the private
// field.
//
// The last argument of DefineProperty is null, because the
// property has no parameters. (If you don't specify null, you must
// specify an array of Type objects. For a parameterless property,
// use the built-in array with no elements: Type.EmptyTypes)
PropertyBuilder pbNumber = tb.DefineProperty(
"Number",
PropertyAttributes.HasDefault,
typeof(int),
null);
// The property "set" and property "get" methods require a special
// set of attributes.
MethodAttributes getSetAttr = MethodAttributes.Public |
MethodAttributes.SpecialName | MethodAttributes.HideBySig;
// Define the "get" accessor method for Number. The method returns
// an integer and has no arguments. (Note that null could be
// used instead of Types.EmptyTypes)
MethodBuilder mbNumberGetAccessor = tb.DefineMethod(
"get_Number",
getSetAttr,
typeof(int),
Type.EmptyTypes);
ILGenerator numberGetIL = mbNumberGetAccessor.GetILGenerator();
// For an instance property, argument zero is the instance. Load the
// instance, then load the private field and return, leaving the
// field value on the stack.
numberGetIL.Emit(OpCodes.Ldarg_0);
numberGetIL.Emit(OpCodes.Ldfld, fbNumber);
numberGetIL.Emit(OpCodes.Ret);
// Define the "set" accessor method for Number, which has no return
// type and takes one argument of type int (Int32).
MethodBuilder mbNumberSetAccessor = tb.DefineMethod(
"set_Number",
getSetAttr,
null,
new Type[] { typeof(int) });
ILGenerator numberSetIL = mbNumberSetAccessor.GetILGenerator();
// Load the instance and then the numeric argument, then store the
// argument in the field.
numberSetIL.Emit(OpCodes.Ldarg_0);
numberSetIL.Emit(OpCodes.Ldarg_1);
numberSetIL.Emit(OpCodes.Stfld, fbNumber);
numberSetIL.Emit(OpCodes.Ret);
// Last, map the "get" and "set" accessor methods to the
// PropertyBuilder. The property is now complete.
pbNumber.SetGetMethod(mbNumberGetAccessor);
pbNumber.SetSetMethod(mbNumberSetAccessor);
// Define a method that accepts an integer argument and returns
// the product of that integer and the private field m_number. This
// time, the array of parameter types is created on the fly.
MethodBuilder meth = tb.DefineMethod(
"MyMethod",
MethodAttributes.Public,
typeof(int),
new Type[] { typeof(int) });
ILGenerator methIL = meth.GetILGenerator();
// To retrieve the private instance field, load the instance it
// belongs to (argument zero). After loading the field, load the
// argument one and then multiply. Return from the method with
// the return value (the product of the two numbers) on the
// execution stack.
methIL.Emit(OpCodes.Ldarg_0);
methIL.Emit(OpCodes.Ldfld, fbNumber);
methIL.Emit(OpCodes.Ldarg_1);
methIL.Emit(OpCodes.Mul);
methIL.Emit(OpCodes.Ret);
// Finish the type.
Type? t = tb.CreateType();
// Because AssemblyBuilderAccess includes Run, the code can be
// executed immediately. Start by getting reflection objects for
// the method and the property.
MethodInfo? mi = t?.GetMethod("MyMethod");
PropertyInfo? pi = t?.GetProperty("Number");
// Create an instance of MyDynamicType using the default
// constructor.
object? o1 = null;
if (t is not null)
o1 = Activator.CreateInstance(t);
// Display the value of the property, then change it to 127 and
// display it again. Use null to indicate that the property
// has no index.
Console.WriteLine("o1.Number: {0}", pi?.GetValue(o1, null));
pi?.SetValue(o1, 127, null);
Console.WriteLine("o1.Number: {0}", pi?.GetValue(o1, null));
// Call MyMethod, passing 22, and display the return value, 22
// times 127. Arguments must be passed as an array, even when
// there is only one.
object[] arguments = { 22 };
Console.WriteLine("o1.MyMethod(22): {0}",
mi?.Invoke(o1, arguments));
// Create an instance of MyDynamicType using the constructor
// that specifies m_Number. The constructor is identified by
// matching the types in the argument array. In this case,
// the argument array is created on the fly. Display the
// property value.
object? o2 = null;
if (t is not null)
o2 = Activator.CreateInstance(t, new object[] { 5280 });
Console.WriteLine("o2.Number: {0}", pi?.GetValue(o2, null));
}
}
/* This code produces the following output:
o1.Number: 42
o1.Number: 127
o1.MyMethod(22): 2794
o2.Number: 5280
*/
Imports System.Reflection
Imports System.Reflection.Emit
Class DemoAssemblyBuilder
Public Shared Sub Main()
' This code creates an assembly that contains one type,
' named "MyDynamicType", that has a private field, a property
' that gets and sets the private field, constructors that
' initialize the private field, and a method that multiplies
' a user-supplied number by the private field value and returns
' the result. The code might look like this in Visual Basic:
'
'Public Class MyDynamicType
' Private m_number As Integer
'
' Public Sub New()
' Me.New(42)
' End Sub
'
' Public Sub New(ByVal initNumber As Integer)
' m_number = initNumber
' End Sub
'
' Public Property Number As Integer
' Get
' Return m_number
' End Get
' Set
' m_Number = Value
' End Set
' End Property
'
' Public Function MyMethod(ByVal multiplier As Integer) As Integer
' Return m_Number * multiplier
' End Function
'End Class
Dim aName As New AssemblyName("DynamicAssemblyExample")
Dim ab As AssemblyBuilder = _
AssemblyBuilder.DefineDynamicAssembly( _
aName, _
AssemblyBuilderAccess.Run)
' The module name is usually the same as the assembly name.
Dim mb As ModuleBuilder = ab.DefineDynamicModule( _
aName.Name)
Dim tb As TypeBuilder = _
mb.DefineType("MyDynamicType", TypeAttributes.Public)
' Add a private field of type Integer (Int32).
Dim fbNumber As FieldBuilder = tb.DefineField( _
"m_number", _
GetType(Integer), _
FieldAttributes.Private)
' Define a constructor that takes an integer argument and
' stores it in the private field.
Dim parameterTypes() As Type = { GetType(Integer) }
Dim ctor1 As ConstructorBuilder = _
tb.DefineConstructor( _
MethodAttributes.Public, _
CallingConventions.Standard, _
parameterTypes)
Dim ctor1IL As ILGenerator = ctor1.GetILGenerator()
' For a constructor, argument zero is a reference to the new
' instance. Push it on the stack before calling the base
' class constructor. Specify the default constructor of the
' base class (System.Object) by passing an empty array of
' types (Type.EmptyTypes) to GetConstructor.
ctor1IL.Emit(OpCodes.Ldarg_0)
ctor1IL.Emit(OpCodes.Call, _
GetType(Object).GetConstructor(Type.EmptyTypes))
' Push the instance on the stack before pushing the argument
' that is to be assigned to the private field m_number.
ctor1IL.Emit(OpCodes.Ldarg_0)
ctor1IL.Emit(OpCodes.Ldarg_1)
ctor1IL.Emit(OpCodes.Stfld, fbNumber)
ctor1IL.Emit(OpCodes.Ret)
' Define a default constructor that supplies a default value
' for the private field. For parameter types, pass the empty
' array of types or pass Nothing.
Dim ctor0 As ConstructorBuilder = tb.DefineConstructor( _
MethodAttributes.Public, _
CallingConventions.Standard, _
Type.EmptyTypes)
Dim ctor0IL As ILGenerator = ctor0.GetILGenerator()
' For a constructor, argument zero is a reference to the new
' instance. Push it on the stack before pushing the default
' value on the stack, then call constructor ctor1.
ctor0IL.Emit(OpCodes.Ldarg_0)
ctor0IL.Emit(OpCodes.Ldc_I4_S, 42)
ctor0IL.Emit(OpCodes.Call, ctor1)
ctor0IL.Emit(OpCodes.Ret)
' Define a property named Number that gets and sets the private
' field.
'
' The last argument of DefineProperty is Nothing, because the
' property has no parameters. (If you don't specify Nothing, you must
' specify an array of Type objects. For a parameterless property,
' use the built-in array with no elements: Type.EmptyTypes)
Dim pbNumber As PropertyBuilder = tb.DefineProperty( _
"Number", _
PropertyAttributes.HasDefault, _
GetType(Integer), _
Nothing)
' The property Set and property Get methods require a special
' set of attributes.
Dim getSetAttr As MethodAttributes = _
MethodAttributes.Public Or MethodAttributes.SpecialName _
Or MethodAttributes.HideBySig
' Define the "get" accessor method for Number. The method returns
' an integer and has no arguments. (Note that Nothing could be
' used instead of Types.EmptyTypes)
Dim mbNumberGetAccessor As MethodBuilder = tb.DefineMethod( _
"get_Number", _
getSetAttr, _
GetType(Integer), _
Type.EmptyTypes)
Dim numberGetIL As ILGenerator = mbNumberGetAccessor.GetILGenerator()
' For an instance property, argument zero is the instance. Load the
' instance, then load the private field and return, leaving the
' field value on the stack.
numberGetIL.Emit(OpCodes.Ldarg_0)
numberGetIL.Emit(OpCodes.Ldfld, fbNumber)
numberGetIL.Emit(OpCodes.Ret)
' Define the "set" accessor method for Number, which has no return
' type and takes one argument of type Integer (Int32).
Dim mbNumberSetAccessor As MethodBuilder = _
tb.DefineMethod( _
"set_Number", _
getSetAttr, _
Nothing, _
New Type() { GetType(Integer) })
Dim numberSetIL As ILGenerator = mbNumberSetAccessor.GetILGenerator()
' Load the instance and then the numeric argument, then store the
' argument in the field.
numberSetIL.Emit(OpCodes.Ldarg_0)
numberSetIL.Emit(OpCodes.Ldarg_1)
numberSetIL.Emit(OpCodes.Stfld, fbNumber)
numberSetIL.Emit(OpCodes.Ret)
' Last, map the "get" and "set" accessor methods to the
' PropertyBuilder. The property is now complete.
pbNumber.SetGetMethod(mbNumberGetAccessor)
pbNumber.SetSetMethod(mbNumberSetAccessor)
' Define a method that accepts an integer argument and returns
' the product of that integer and the private field m_number. This
' time, the array of parameter types is created on the fly.
Dim meth As MethodBuilder = tb.DefineMethod( _
"MyMethod", _
MethodAttributes.Public, _
GetType(Integer), _
New Type() { GetType(Integer) })
Dim methIL As ILGenerator = meth.GetILGenerator()
' To retrieve the private instance field, load the instance it
' belongs to (argument zero). After loading the field, load the
' argument one and then multiply. Return from the method with
' the return value (the product of the two numbers) on the
' execution stack.
methIL.Emit(OpCodes.Ldarg_0)
methIL.Emit(OpCodes.Ldfld, fbNumber)
methIL.Emit(OpCodes.Ldarg_1)
methIL.Emit(OpCodes.Mul)
methIL.Emit(OpCodes.Ret)
' Finish the type.
Dim t As Type = tb.CreateType()
' Because AssemblyBuilderAccess includes Run, the code can be
' executed immediately. Start by getting reflection objects for
' the method and the property.
Dim mi As MethodInfo = t.GetMethod("MyMethod")
Dim pi As PropertyInfo = t.GetProperty("Number")
' Create an instance of MyDynamicType using the default
' constructor.
Dim o1 As Object = Activator.CreateInstance(t)
' Display the value of the property, then change it to 127 and
' display it again. Use Nothing to indicate that the property
' has no index.
Console.WriteLine("o1.Number: {0}", pi.GetValue(o1, Nothing))
pi.SetValue(o1, 127, Nothing)
Console.WriteLine("o1.Number: {0}", pi.GetValue(o1, Nothing))
' Call MyMethod, passing 22, and display the return value, 22
' times 127. Arguments must be passed as an array, even when
' there is only one.
Dim arguments() As Object = { 22 }
Console.WriteLine("o1.MyMethod(22): {0}", _
mi.Invoke(o1, arguments))
' Create an instance of MyDynamicType using the constructor
' that specifies m_Number. The constructor is identified by
' matching the types in the argument array. In this case,
' the argument array is created on the fly. Display the
' property value.
Dim o2 As Object = Activator.CreateInstance(t, _
New Object() { 5280 })
Console.WriteLine("o2.Number: {0}", pi.GetValue(o2, Nothing))
End Sub
End Class
' This code produces the following output:
'
'o1.Number: 42
'o1.Number: 127
'o1.MyMethod(22): 2794
'o2.Number: 5280
다음 코드 샘플에서는 .를 사용하여 TypeBuilder형식을 동적으로 빌드하는 방법을 보여 줍니다.
using System;
using System.Threading;
using System.Reflection;
using System.Reflection.Emit;
class TestILGenerator
{
public static Type DynamicDotProductGen()
{
Type ivType = null;
Type[] ctorParams = new Type[] { typeof(int),
typeof(int),
typeof(int)};
AppDomain myDomain = Thread.GetDomain();
AssemblyName myAsmName = new AssemblyName();
myAsmName.Name = "IntVectorAsm";
AssemblyBuilder myAsmBuilder = myDomain.DefineDynamicAssembly(
myAsmName,
AssemblyBuilderAccess.RunAndSave);
ModuleBuilder IntVectorModule = myAsmBuilder.DefineDynamicModule("IntVectorModule",
"Vector.dll");
TypeBuilder ivTypeBld = IntVectorModule.DefineType("IntVector",
TypeAttributes.Public);
FieldBuilder xField = ivTypeBld.DefineField("x", typeof(int),
FieldAttributes.Private);
FieldBuilder yField = ivTypeBld.DefineField("y", typeof(int),
FieldAttributes.Private);
FieldBuilder zField = ivTypeBld.DefineField("z", typeof(int),
FieldAttributes.Private);
Type objType = Type.GetType("System.Object");
ConstructorInfo objCtor = objType.GetConstructor(new Type[0]);
ConstructorBuilder ivCtor = ivTypeBld.DefineConstructor(
MethodAttributes.Public,
CallingConventions.Standard,
ctorParams);
ILGenerator ctorIL = ivCtor.GetILGenerator();
ctorIL.Emit(OpCodes.Ldarg_0);
ctorIL.Emit(OpCodes.Call, objCtor);
ctorIL.Emit(OpCodes.Ldarg_0);
ctorIL.Emit(OpCodes.Ldarg_1);
ctorIL.Emit(OpCodes.Stfld, xField);
ctorIL.Emit(OpCodes.Ldarg_0);
ctorIL.Emit(OpCodes.Ldarg_2);
ctorIL.Emit(OpCodes.Stfld, yField);
ctorIL.Emit(OpCodes.Ldarg_0);
ctorIL.Emit(OpCodes.Ldarg_3);
ctorIL.Emit(OpCodes.Stfld, zField);
ctorIL.Emit(OpCodes.Ret);
// This method will find the dot product of the stored vector
// with another.
Type[] dpParams = new Type[] { ivTypeBld };
// Here, you create a MethodBuilder containing the
// name, the attributes (public, static, private, and so on),
// the return type (int, in this case), and a array of Type
// indicating the type of each parameter. Since the sole parameter
// is a IntVector, the very class you're creating, you will
// pass in the TypeBuilder (which is derived from Type) instead of
// a Type object for IntVector, avoiding an exception.
// -- This method would be declared in C# as:
// public int DotProduct(IntVector aVector)
MethodBuilder dotProductMthd = ivTypeBld.DefineMethod(
"DotProduct",
MethodAttributes.Public,
typeof(int),
dpParams);
// A ILGenerator can now be spawned, attached to the MethodBuilder.
ILGenerator mthdIL = dotProductMthd.GetILGenerator();
// Here's the body of our function, in MSIL form. We're going to find the
// "dot product" of the current vector instance with the passed vector
// instance. For reference purposes, the equation is:
// (x1 * x2) + (y1 * y2) + (z1 * z2) = the dot product
// First, you'll load the reference to the current instance "this"
// stored in argument 0 (ldarg.0) onto the stack. Ldfld, the subsequent
// instruction, will pop the reference off the stack and look up the
// field "x", specified by the FieldInfo token "xField".
mthdIL.Emit(OpCodes.Ldarg_0);
mthdIL.Emit(OpCodes.Ldfld, xField);
// That completed, the value stored at field "x" is now atop the stack.
// Now, you'll do the same for the object reference we passed as a
// parameter, stored in argument 1 (ldarg.1). After Ldfld executed,
// you'll have the value stored in field "x" for the passed instance
// atop the stack.
mthdIL.Emit(OpCodes.Ldarg_1);
mthdIL.Emit(OpCodes.Ldfld, xField);
// There will now be two values atop the stack - the "x" value for the
// current vector instance, and the "x" value for the passed instance.
// You'll now multiply them, and push the result onto the evaluation stack.
mthdIL.Emit(OpCodes.Mul_Ovf_Un);
// Now, repeat this for the "y" fields of both vectors.
mthdIL.Emit(OpCodes.Ldarg_0);
mthdIL.Emit(OpCodes.Ldfld, yField);
mthdIL.Emit(OpCodes.Ldarg_1);
mthdIL.Emit(OpCodes.Ldfld, yField);
mthdIL.Emit(OpCodes.Mul_Ovf_Un);
// At this time, the results of both multiplications should be atop
// the stack. You'll now add them and push the result onto the stack.
mthdIL.Emit(OpCodes.Add_Ovf_Un);
// Multiply both "z" field and push the result onto the stack.
mthdIL.Emit(OpCodes.Ldarg_0);
mthdIL.Emit(OpCodes.Ldfld, zField);
mthdIL.Emit(OpCodes.Ldarg_1);
mthdIL.Emit(OpCodes.Ldfld, zField);
mthdIL.Emit(OpCodes.Mul_Ovf_Un);
// Finally, add the result of multiplying the "z" fields with the
// result of the earlier addition, and push the result - the dot product -
// onto the stack.
mthdIL.Emit(OpCodes.Add_Ovf_Un);
// The "ret" opcode will pop the last value from the stack and return it
// to the calling method. You're all done!
mthdIL.Emit(OpCodes.Ret);
ivType = ivTypeBld.CreateType();
return ivType;
}
public static void Main() {
Type IVType = null;
object aVector1 = null;
object aVector2 = null;
Type[] aVtypes = new Type[] {typeof(int), typeof(int), typeof(int)};
object[] aVargs1 = new object[] {10, 10, 10};
object[] aVargs2 = new object[] {20, 20, 20};
// Call the method to build our dynamic class.
IVType = DynamicDotProductGen();
Console.WriteLine("---");
ConstructorInfo myDTctor = IVType.GetConstructor(aVtypes);
aVector1 = myDTctor.Invoke(aVargs1);
aVector2 = myDTctor.Invoke(aVargs2);
object[] passMe = new object[1];
passMe[0] = (object)aVector2;
Console.WriteLine("(10, 10, 10) . (20, 20, 20) = {0}",
IVType.InvokeMember("DotProduct",
BindingFlags.InvokeMethod,
null,
aVector1,
passMe));
// +++ OUTPUT +++
// ---
// (10, 10, 10) . (20, 20, 20) = 600
}
}
Imports System.Threading
Imports System.Reflection
Imports System.Reflection.Emit
_
Class TestILGenerator
Public Shared Function DynamicDotProductGen() As Type
Dim ivType As Type = Nothing
Dim ctorParams() As Type = {GetType(Integer), GetType(Integer), GetType(Integer)}
Dim myDomain As AppDomain = Thread.GetDomain()
Dim myAsmName As New AssemblyName()
myAsmName.Name = "IntVectorAsm"
Dim myAsmBuilder As AssemblyBuilder = myDomain.DefineDynamicAssembly( _
myAsmName, _
AssemblyBuilderAccess.RunAndSave)
Dim IntVectorModule As ModuleBuilder = myAsmBuilder.DefineDynamicModule( _
"IntVectorModule", _
"Vector.dll")
Dim ivTypeBld As TypeBuilder = IntVectorModule.DefineType("IntVector", TypeAttributes.Public)
Dim xField As FieldBuilder = ivTypeBld.DefineField("x", _
GetType(Integer), _
FieldAttributes.Private)
Dim yField As FieldBuilder = ivTypeBld.DefineField("y", _
GetType(Integer), _
FieldAttributes.Private)
Dim zField As FieldBuilder = ivTypeBld.DefineField("z", _
GetType(Integer), _
FieldAttributes.Private)
Dim objType As Type = Type.GetType("System.Object")
Dim objCtor As ConstructorInfo = objType.GetConstructor(New Type() {})
Dim ivCtor As ConstructorBuilder = ivTypeBld.DefineConstructor( _
MethodAttributes.Public, _
CallingConventions.Standard, _
ctorParams)
Dim ctorIL As ILGenerator = ivCtor.GetILGenerator()
ctorIL.Emit(OpCodes.Ldarg_0)
ctorIL.Emit(OpCodes.Call, objCtor)
ctorIL.Emit(OpCodes.Ldarg_0)
ctorIL.Emit(OpCodes.Ldarg_1)
ctorIL.Emit(OpCodes.Stfld, xField)
ctorIL.Emit(OpCodes.Ldarg_0)
ctorIL.Emit(OpCodes.Ldarg_2)
ctorIL.Emit(OpCodes.Stfld, yField)
ctorIL.Emit(OpCodes.Ldarg_0)
ctorIL.Emit(OpCodes.Ldarg_3)
ctorIL.Emit(OpCodes.Stfld, zField)
ctorIL.Emit(OpCodes.Ret)
' Now, you'll construct the method find the dot product of two vectors. First,
' let's define the parameters that will be accepted by the method. In this case,
' it's an IntVector itself!
Dim dpParams() As Type = {ivTypeBld}
' Here, you create a MethodBuilder containing the
' name, the attributes (public, static, private, and so on),
' the return type (int, in this case), and a array of Type
' indicating the type of each parameter. Since the sole parameter
' is a IntVector, the very class you're creating, you will
' pass in the TypeBuilder (which is derived from Type) instead of
' a Type object for IntVector, avoiding an exception.
' -- This method would be declared in VB.NET as:
' Public Function DotProduct(IntVector aVector) As Integer
Dim dotProductMthd As MethodBuilder = ivTypeBld.DefineMethod("DotProduct", _
MethodAttributes.Public, GetType(Integer), _
dpParams)
' A ILGenerator can now be spawned, attached to the MethodBuilder.
Dim mthdIL As ILGenerator = dotProductMthd.GetILGenerator()
' Here's the body of our function, in MSIL form. We're going to find the
' "dot product" of the current vector instance with the passed vector
' instance. For reference purposes, the equation is:
' (x1 * x2) + (y1 * y2) + (z1 * z2) = the dot product
' First, you'll load the reference to the current instance "this"
' stored in argument 0 (ldarg.0) onto the stack. Ldfld, the subsequent
' instruction, will pop the reference off the stack and look up the
' field "x", specified by the FieldInfo token "xField".
mthdIL.Emit(OpCodes.Ldarg_0)
mthdIL.Emit(OpCodes.Ldfld, xField)
' That completed, the value stored at field "x" is now atop the stack.
' Now, you'll do the same for the object reference we passed as a
' parameter, stored in argument 1 (ldarg.1). After Ldfld executed,
' you'll have the value stored in field "x" for the passed instance
' atop the stack.
mthdIL.Emit(OpCodes.Ldarg_1)
mthdIL.Emit(OpCodes.Ldfld, xField)
' There will now be two values atop the stack - the "x" value for the
' current vector instance, and the "x" value for the passed instance.
' You'll now multiply them, and push the result onto the evaluation stack.
mthdIL.Emit(OpCodes.Mul_Ovf_Un)
' Now, repeat this for the "y" fields of both vectors.
mthdIL.Emit(OpCodes.Ldarg_0)
mthdIL.Emit(OpCodes.Ldfld, yField)
mthdIL.Emit(OpCodes.Ldarg_1)
mthdIL.Emit(OpCodes.Ldfld, yField)
mthdIL.Emit(OpCodes.Mul_Ovf_Un)
' At this time, the results of both multiplications should be atop
' the stack. You'll now add them and push the result onto the stack.
mthdIL.Emit(OpCodes.Add_Ovf_Un)
' Multiply both "z" field and push the result onto the stack.
mthdIL.Emit(OpCodes.Ldarg_0)
mthdIL.Emit(OpCodes.Ldfld, zField)
mthdIL.Emit(OpCodes.Ldarg_1)
mthdIL.Emit(OpCodes.Ldfld, zField)
mthdIL.Emit(OpCodes.Mul_Ovf_Un)
' Finally, add the result of multiplying the "z" fields with the
' result of the earlier addition, and push the result - the dot product -
' onto the stack.
mthdIL.Emit(OpCodes.Add_Ovf_Un)
' The "ret" opcode will pop the last value from the stack and return it
' to the calling method. You're all done!
mthdIL.Emit(OpCodes.Ret)
ivType = ivTypeBld.CreateType()
Return ivType
End Function 'DynamicDotProductGen
Public Shared Sub Main()
Dim IVType As Type = Nothing
Dim aVector1 As Object = Nothing
Dim aVector2 As Object = Nothing
Dim aVtypes() As Type = {GetType(Integer), GetType(Integer), GetType(Integer)}
Dim aVargs1() As Object = {10, 10, 10}
Dim aVargs2() As Object = {20, 20, 20}
' Call the method to build our dynamic class.
IVType = DynamicDotProductGen()
Dim myDTctor As ConstructorInfo = IVType.GetConstructor(aVtypes)
aVector1 = myDTctor.Invoke(aVargs1)
aVector2 = myDTctor.Invoke(aVargs2)
Console.WriteLine("---")
Dim passMe(0) As Object
passMe(0) = CType(aVector2, Object)
Console.WriteLine("(10, 10, 10) . (20, 20, 20) = {0}", _
IVType.InvokeMember("DotProduct", BindingFlags.InvokeMethod, _
Nothing, aVector1, passMe))
End Sub
End Class
' +++ OUTPUT +++
' ---
' (10, 10, 10) . (20, 20, 20) = 600
설명
이 API에 대한 자세한 내용은 TypeBuilder에 대한 추가 API 비고를 참조하세요.
필드
| Name | Description |
|---|---|
| UnspecifiedTypeSize |
형식의 총 크기를 지정하지 않음을 나타냅니다. |
속성
| Name | Description |
|---|---|
| Assembly |
이 형식 정의를 포함하는 동적 어셈블리를 검색합니다. |
| AssemblyQualifiedName |
어셈블리의 표시 이름으로 정규화된 이 형식의 전체 이름을 반환합니다. |
| Attributes |
Type연결된 특성을 가져옵니다. (다음에서 상속됨 Type) |
| BaseType |
이 형식의 기본 형식을 검색합니다. |
| ContainsGenericParameters |
현재 Type 개체에 특정 형식으로 대체되지 않은 형식 매개 변수가 있는지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| CustomAttributes |
이 멤버의 사용자 지정 특성을 포함하는 컬렉션을 가져옵니다. (다음에서 상속됨 MemberInfo) |
| DeclaredConstructors |
현재 형식으로 선언된 생성자의 컬렉션을 가져옵니다. (다음에서 상속됨 TypeInfo) |
| DeclaredEvents |
현재 형식으로 정의된 이벤트의 컬렉션을 가져옵니다. (다음에서 상속됨 TypeInfo) |
| DeclaredFields |
현재 형식으로 정의된 필드의 컬렉션을 가져옵니다. (다음에서 상속됨 TypeInfo) |
| DeclaredMembers |
현재 형식으로 정의된 멤버의 컬렉션을 가져옵니다. (다음에서 상속됨 TypeInfo) |
| DeclaredMethods |
현재 형식으로 정의된 메서드의 컬렉션을 가져옵니다. (다음에서 상속됨 TypeInfo) |
| DeclaredNestedTypes |
현재 형식으로 정의된 중첩 형식의 컬렉션을 가져옵니다. (다음에서 상속됨 TypeInfo) |
| DeclaredProperties |
현재 형식으로 정의된 속성의 컬렉션을 가져옵니다. (다음에서 상속됨 TypeInfo) |
| DeclaringMethod |
현재 제네릭 형식 매개 변수를 선언한 메서드를 가져옵니다. |
| DeclaringType |
이 형식을 선언한 형식을 반환합니다. |
| FullName |
이 형식의 전체 경로를 검색합니다. |
| GenericParameterAttributes |
현재 제네릭 형식 매개 변수의 공변성 및 특수 제약 조건을 나타내는 값을 가져옵니다. |
| GenericParameterPosition |
매개 변수를 선언한 제네릭 형식의 형식 매개 변수 목록에서 형식 매개 변수의 위치를 가져옵니다. |
| GenericTypeArguments |
이 형식에 대한 제네릭 형식 인수의 배열을 가져옵니다. (다음에서 상속됨 Type) |
| GenericTypeParameters |
현재 인스턴스의 제네릭 형식 매개 변수 배열을 가져옵니다. (다음에서 상속됨 TypeInfo) |
| GUID |
이 형식의 GUID를 검색합니다. |
| HasElementType |
현재 Type 다른 형식을 포함하거나 참조하는지 여부를 나타내는 값을 가져옵니다. 즉, 현재 Type 배열, 포인터 또는 참조로 전달되는지 여부입니다. (다음에서 상속됨 Type) |
| ImplementedInterfaces |
현재 형식으로 구현된 인터페이스의 컬렉션을 가져옵니다. (다음에서 상속됨 TypeInfo) |
| IsAbstract |
Type 추상이며 재정의해야 하는지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsAnsiClass |
|
| IsArray |
형식이 배열인지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsAutoClass |
|
| IsAutoLayout |
현재 형식의 필드가 공용 언어 런타임에 의해 자동으로 배치되는지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsByRef |
Type 참조로 전달되는지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsByRefLike |
형식이 바이레프와 유사한 구조체인지 여부를 나타내는 값을 가져옵니다. |
| IsClass |
Type 클래스인지 대리자인지 여부를 나타내는 값을 가져옵니다. 즉, 값 형식이나 인터페이스가 아닙니다. (다음에서 상속됨 Type) |
| IsCOMObject |
Type COM 개체인지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsConstructedGenericType |
이 개체가 생성된 제네릭 형식을 나타내는지 여부를 나타내는 값을 가져옵니다. |
| IsContextful |
Type 컨텍스트에서 호스트할 수 있는지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsEnum |
현재 Type 열거형을 나타내는지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsExplicitLayout |
현재 형식의 필드가 명시적으로 지정된 오프셋에 배치되는지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsGenericMethodParameter |
현재 Type 제네릭 메서드 정의에서 형식 매개 변수를 나타내는지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsGenericParameter |
현재 형식이 제네릭 형식 매개 변수인지 여부를 나타내는 값을 가져옵니다. |
| IsGenericType |
현재 형식이 제네릭 형식인지 여부를 나타내는 값을 가져옵니다. |
| IsGenericTypeDefinition |
현재 TypeBuilder 가 다른 제네릭 형식을 생성할 수 있는 제네릭 형식 정의를 나타내는지 여부를 나타내는 값을 가져옵니다. |
| IsGenericTypeParameter |
현재 Type 제네릭 형식 정의의 형식 매개 변수를 나타내는지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsImport |
Type COM 형식 라이브러리에서 가져온 ComImportAttribute 특성이 적용되었는지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsInterface |
Type 인터페이스인지 여부를 나타내는 값을 가져옵니다. 즉, 클래스 또는 값 형식이 아닙니다. (다음에서 상속됨 Type) |
| IsLayoutSequential |
현재 형식의 필드가 정의되거나 메타데이터로 내보내는 순서대로 순차적으로 배치되는지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsMarshalByRef |
Type 참조로 마샬링되는지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsNested |
현재 Type 개체가 정의가 다른 형식의 정의 내에 중첩된 형식을 나타내는지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsNestedAssembly |
Type 중첩되어 자체 어셈블리 내에서만 표시되는지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsNestedFamANDAssem |
Type 중첩되어 자체 패밀리 및 자체 어셈블리에 속하는 클래스에만 표시되는지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsNestedFamily |
Type 중첩되고 자체 패밀리 내에서만 표시되는지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsNestedFamORAssem |
Type 중첩되어 자체 패밀리 또는 자체 어셈블리에 속하는 클래스에만 표시되는지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsNestedPrivate |
Type 중첩되고 프라이빗으로 선언되었는지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsNestedPublic |
클래스가 중첩되고 public으로 선언되었는지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsNotPublic |
Type public으로 선언되지 않았는지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsPointer |
Type 포인터인지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsPrimitive |
Type 기본 형식 중 하나인지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsPublic |
Type public으로 선언되었는지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsSealed |
Type sealed로 선언되었는지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsSecurityCritical |
현재 형식이 보안에 중요하거나 보안이 안전한지 여부를 나타내는 값을 가져오므로 중요한 작업을 수행할 수 있습니다. |
| IsSecuritySafeCritical |
현재 형식이 보안에 중요한지 여부를 나타내는 값을 가져옵니다. 즉, 중요한 작업을 수행할 수 있고 투명 코드로 액세스할 수 있는지 여부입니다. |
| IsSecurityTransparent |
현재 형식이 투명하여 중요한 작업을 수행할 수 없는지 여부를 나타내는 값을 가져옵니다. |
| IsSerializable |
Type 이진 serialize 가능 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsSignatureType |
형식이 서명 형식인지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsSpecialName |
형식에 특수 처리가 필요한 이름이 있는지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsSZArray |
런타임 동안 클래스의 새 인스턴스를 정의하고 만듭니다. |
| IsTypeDefinition |
런타임 동안 클래스의 새 인스턴스를 정의하고 만듭니다. |
| IsUnicodeClass |
|
| IsValueType |
Type 값 형식인지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| IsVariableBoundArray |
런타임 동안 클래스의 새 인스턴스를 정의하고 만듭니다. |
| IsVisible |
어셈블리 외부의 코드에서 Type 액세스할 수 있는지 여부를 나타내는 값을 가져옵니다. (다음에서 상속됨 Type) |
| MemberType |
이 멤버가 형식 또는 중첩 형식임을 나타내는 MemberTypes 값을 가져옵니다. (다음에서 상속됨 Type) |
| MetadataToken |
메타데이터 요소를 식별하는 값을 가져옵니다. (다음에서 상속됨 MemberInfo) |
| Module |
이 형식 정의를 포함하는 동적 모듈을 검색합니다. |
| Name |
이 형식의 이름을 검색합니다. |
| Namespace |
정의된 네임스페이 |
| PackingSize |
이 형식의 압축 크기를 검색합니다. |
| ReflectedType |
이 형식을 가져오는 데 사용된 형식을 반환합니다. |
| Size |
형식의 총 크기를 검색합니다. |
| StructLayoutAttribute |
현재 형식의 레이아웃을 설명하는 StructLayoutAttribute 가져옵니다. (다음에서 상속됨 Type) |
| TypeHandle |
동적 모듈에서는 지원되지 않습니다. |
| TypeInitializer |
형식의 이니셜라이저를 가져옵니다. (다음에서 상속됨 Type) |
| TypeToken |
이 형식의 형식 토큰을 반환합니다. |
| UnderlyingSystemType |
이 |
메서드
| Name | Description |
|---|---|
| AddDeclarativeSecurity(SecurityAction, PermissionSet) |
이 형식에 선언적 보안을 추가합니다. |
| AddInterfaceImplementation(Type) |
이 형식이 구현하는 인터페이스를 추가합니다. |
| AsType() |
현재 형식을 Type 개체로 반환합니다. (다음에서 상속됨 TypeInfo) |
| CreateType() |
클래스에 Type 대한 개체를 만듭니다. 클래스 |
| CreateTypeInfo() |
이 형식을 TypeInfo 나타내는 개체를 가져옵니다. |
| DefineConstructor(MethodAttributes, CallingConventions, Type[], Type[][], Type[][]) |
지정된 특성, 서명 및 사용자 지정 한정자를 사용하여 형식에 새 생성자를 추가합니다. |
| DefineConstructor(MethodAttributes, CallingConventions, Type[]) |
지정된 특성 및 시그니처를 사용하여 형식에 새 생성자를 추가합니다. |
| DefineDefaultConstructor(MethodAttributes) |
매개 변수가 없는 생성자를 정의합니다. 여기에 정의된 생성자는 단순히 부모의 매개 변수 없는 생성자를 호출합니다. |
| DefineEvent(String, EventAttributes, Type) |
지정된 이름, 특성 및 이벤트 형식을 사용하여 형식에 새 이벤트를 추가합니다. |
| DefineField(String, Type, FieldAttributes) |
지정된 이름, 특성 및 필드 형식을 사용하여 형식에 새 필드를 추가합니다. |
| DefineField(String, Type, Type[], Type[], FieldAttributes) |
지정된 이름, 특성, 필드 형식 및 사용자 지정 한정자를 사용하여 형식에 새 필드를 추가합니다. |
| DefineGenericParameters(String[]) |
현재 형식의 제네릭 형식 매개 변수를 정의하고 해당 번호와 이름을 지정하고 제약 조건을 설정하는 데 사용할 수 있는 개체 배열 GenericTypeParameterBuilder 을 반환합니다. |
| DefineInitializedData(String, Byte[], FieldAttributes) |
PE(이식 가능한 실행 파일) 파일의 .sdata 섹션에서 초기화된 데이터 필드를 정의합니다. |
| DefineMethod(String, MethodAttributes, CallingConventions, Type, Type[], Type[], Type[], Type[][], Type[][]) |
지정된 이름, 메서드 특성, 호출 규칙, 메서드 서명 및 사용자 지정 한정자를 사용하여 형식에 새 메서드를 추가합니다. |
| DefineMethod(String, MethodAttributes, CallingConventions, Type, Type[]) |
지정된 이름, 메서드 특성, 호출 규칙 및 메서드 시그니처를 사용하여 형식에 새 메서드를 추가합니다. |
| DefineMethod(String, MethodAttributes, CallingConventions) |
지정된 이름, 메서드 특성 및 호출 규칙을 사용하여 형식에 새 메서드를 추가합니다. |
| DefineMethod(String, MethodAttributes, Type, Type[]) |
지정된 이름, 메서드 특성 및 메서드 시그니처를 사용하여 형식에 새 메서드를 추가합니다. |
| DefineMethod(String, MethodAttributes) |
지정된 이름 및 메서드 특성을 사용하여 형식에 새 메서드를 추가합니다. |
| DefineMethodOverride(MethodInfo, MethodInfo) |
지정된 메서드 선언을 구현하는 지정된 메서드 본문을 지정하며, 잠재적으로 다른 이름을 사용합니다. |
| DefineNestedType(String, TypeAttributes, Type, Int32) |
이름, 특성, 형식의 총 크기 및 확장되는 형식을 지정하여 중첩된 형식을 정의합니다. |
| DefineNestedType(String, TypeAttributes, Type, PackingSize, Int32) |
이름, 특성, 크기 및 확장되는 형식을 지정하여 중첩된 형식을 정의합니다. |
| DefineNestedType(String, TypeAttributes, Type, PackingSize) |
이름, 특성, 확장되는 형식 및 압축 크기가 지정된 중첩된 형식을 정의합니다. |
| DefineNestedType(String, TypeAttributes, Type, Type[]) |
이름, 특성, 확장되는 형식 및 구현하는 인터페이스를 지정하여 중첩된 형식을 정의합니다. |
| DefineNestedType(String, TypeAttributes, Type) |
이름, 특성 및 확장되는 형식을 지정하여 중첩된 형식을 정의합니다. |
| DefineNestedType(String, TypeAttributes) |
이름과 특성이 지정된 중첩 형식을 정의합니다. |
| DefineNestedType(String) |
이름이 지정된 중첩된 형식을 정의합니다. |
| DefinePInvokeMethod(String, String, MethodAttributes, CallingConventions, Type, Type[], CallingConvention, CharSet) |
|
| DefinePInvokeMethod(String, String, String, MethodAttributes, CallingConventions, Type, Type[], CallingConvention, CharSet) |
|
| DefinePInvokeMethod(String, String, String, MethodAttributes, CallingConventions, Type, Type[], Type[], Type[], Type[][], Type[][], CallingConvention, CharSet) |
|
| DefineProperty(String, PropertyAttributes, CallingConventions, Type, Type[], Type[], Type[], Type[][], Type[][]) |
지정된 이름, 호출 규칙, 속성 서명 및 사용자 지정 한정자를 사용하여 형식에 새 속성을 추가합니다. |
| DefineProperty(String, PropertyAttributes, CallingConventions, Type, Type[]) |
지정된 이름, 특성, 호출 규칙 및 속성 서명을 사용하여 형식에 새 속성을 추가합니다. |
| DefineProperty(String, PropertyAttributes, Type, Type[], Type[], Type[], Type[][], Type[][]) |
지정된 이름, 속성 서명 및 사용자 지정 한정자를 사용하여 형식에 새 속성을 추가합니다. |
| DefineProperty(String, PropertyAttributes, Type, Type[]) |
지정된 이름 및 속성 서명을 사용하여 형식에 새 속성을 추가합니다. |
| DefineTypeInitializer() |
이 형식의 이니셜라이저를 정의합니다. |
| DefineUninitializedData(String, Int32, FieldAttributes) |
PE(이식 가능한 실행 파일) 파일의 섹션에서 초기화되지 않은 데이터 필드를 |
| Equals(Object) |
현재 Type 개체의 기본 시스템 형식이 지정된 Object기본 시스템 형식과 같은지 확인합니다. (다음에서 상속됨 Type) |
| Equals(Type) |
현재 Type 기본 시스템 형식이 지정된 Type기본 시스템 형식과 같은지 확인합니다. (다음에서 상속됨 Type) |
| FindInterfaces(TypeFilter, Object) |
현재 Type구현되거나 상속된 필터링된 인터페이스 목록을 나타내는 Type 개체의 배열을 반환합니다. (다음에서 상속됨 Type) |
| FindMembers(MemberTypes, BindingFlags, MemberFilter, Object) |
지정된 멤버 형식의 MemberInfo 개체의 필터링된 배열을 반환합니다. (다음에서 상속됨 Type) |
| GetArrayRank() |
배열의 차원 수를 가져옵니다. (다음에서 상속됨 Type) |
| GetAttributeFlagsImpl() |
파생 클래스에서 재정의되는 경우 Attributes 속성을 구현하고 Type연결된 특성을 나타내는 열거형 값의 비트 조합을 가져옵니다. (다음에서 상속됨 Type) |
| GetConstructor(BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[]) |
지정된 바인딩 제약 조건 및 지정된 호출 규칙을 사용하여 매개 변수가 지정된 인수 형식 및 한정자와 일치하는 생성자를 검색합니다. (다음에서 상속됨 Type) |
| GetConstructor(BindingFlags, Binder, Type[], ParameterModifier[]) |
지정된 바인딩 제약 조건을 사용하여 매개 변수가 지정된 인수 형식 및 한정자와 일치하는 생성자를 검색합니다. (다음에서 상속됨 Type) |
| GetConstructor(Type, ConstructorInfo) |
제네릭 형식 정의의 지정된 생성자에 해당하는 지정된 생성된 제네릭 형식의 생성자를 반환합니다. |
| GetConstructor(Type[]) |
매개 변수가 지정된 배열의 형식과 일치하는 공용 인스턴스 생성자를 검색합니다. (다음에서 상속됨 Type) |
| GetConstructorImpl(BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[]) |
파생 클래스에서 재정의되는 경우 지정된 바인딩 제약 조건 및 지정된 호출 규칙을 사용하여 매개 변수가 지정된 인수 형식 및 한정자와 일치하는 생성자를 검색합니다. (다음에서 상속됨 Type) |
| GetConstructors() |
현재 Type대해 정의된 모든 공용 생성자를 반환합니다. (다음에서 상속됨 Type) |
| GetConstructors(BindingFlags) |
지정된 대로 이 클래스에 대해 정의된 public 및 non-public 생성자를 나타내는 개체의 배열 ConstructorInfo 을 반환합니다. |
| GetCustomAttributes(Boolean) |
이 형식에 대해 정의된 모든 사용자 지정 특성을 반환합니다. |
| GetCustomAttributes(Type, Boolean) |
지정된 형식에 할당할 수 있는 현재 형식의 모든 사용자 지정 특성을 반환합니다. |
| GetCustomAttributesData() |
대상 멤버에 적용된 특성에 대한 데이터를 나타내는 개체 목록을 CustomAttributeData 반환합니다. (다음에서 상속됨 MemberInfo) |
| GetDeclaredEvent(String) |
현재 형식으로 선언된 지정된 이벤트를 나타내는 개체를 반환합니다. (다음에서 상속됨 TypeInfo) |
| GetDeclaredField(String) |
현재 형식으로 선언된 지정된 필드를 나타내는 개체를 반환합니다. (다음에서 상속됨 TypeInfo) |
| GetDeclaredMethod(String) |
현재 형식으로 선언된 지정된 메서드를 나타내는 개체를 반환합니다. (다음에서 상속됨 TypeInfo) |
| GetDeclaredMethods(String) |
지정된 이름과 일치하는 현재 형식에 선언된 모든 메서드가 포함된 컬렉션을 반환합니다. (다음에서 상속됨 TypeInfo) |
| GetDeclaredNestedType(String) |
현재 형식으로 선언된 지정된 중첩 형식을 나타내는 개체를 반환합니다. (다음에서 상속됨 TypeInfo) |
| GetDeclaredProperty(String) |
현재 형식으로 선언된 지정된 속성을 나타내는 개체를 반환합니다. (다음에서 상속됨 TypeInfo) |
| GetDefaultMembers() |
Type 설정된 현재 DefaultMemberAttribute 대해 정의된 멤버를 검색합니다. (다음에서 상속됨 Type) |
| GetElementType() |
이 메서드를 호출하면 항상 throw됩니다.NotSupportedException |
| GetEnumName(Object) |
현재 열거형 형식에 대해 지정된 값이 있는 상수의 이름을 반환합니다. (다음에서 상속됨 Type) |
| GetEnumNames() |
현재 열거형 형식의 멤버 이름을 반환합니다. (다음에서 상속됨 Type) |
| GetEnumUnderlyingType() |
현재 열거형 형식의 기본 형식을 반환합니다. (다음에서 상속됨 Type) |
| GetEnumValues() |
현재 열거형 형식의 상수 값 배열을 반환합니다. (다음에서 상속됨 Type) |
| GetEvent(String, BindingFlags) |
지정된 이름의 이벤트를 반환합니다. |
| GetEvent(String) |
지정된 공용 이벤트를 나타내는 EventInfo 개체를 반환합니다. (다음에서 상속됨 Type) |
| GetEvents() |
이 형식에 의해 선언되거나 상속된 공용 이벤트를 반환합니다. |
| GetEvents(BindingFlags) |
이 형식으로 선언된 public 및 non-public 이벤트를 반환합니다. |
| GetField(String, BindingFlags) |
지정된 이름으로 지정된 필드를 반환합니다. |
| GetField(String) |
지정된 이름의 공용 필드를 검색합니다. (다음에서 상속됨 Type) |
| GetField(Type, FieldInfo) |
제네릭 형식 정의의 지정된 필드에 해당하는 지정된 생성된 제네릭 형식의 필드를 반환합니다. |
| GetFields() |
현재 Type모든 공용 필드를 반환합니다. (다음에서 상속됨 Type) |
| GetFields(BindingFlags) |
이 형식으로 선언된 public 및 non-public 필드를 반환합니다. |
| GetGenericArguments() |
제네릭 형식의 Type 형식 인수 또는 제네릭 형식 정의의 형식 매개 변수를 나타내는 개체의 배열을 반환합니다. |
| GetGenericParameterConstraints() |
현재 제네릭 형식 매개 변수의 제약 조건을 나타내는 Type 개체의 배열을 반환합니다. (다음에서 상속됨 Type) |
| GetGenericTypeDefinition() |
현재 형식을 Type 가져올 수 있는 제네릭 형식 정의를 나타내는 개체를 반환합니다. |
| GetHashCode() |
이 인스턴스의 해시 코드를 반환합니다. (다음에서 상속됨 Type) |
| GetInterface(String, Boolean) |
지정된 인터페이스 이름과 일치하는 정규화된 이름을 사용하여 이 클래스에 의해 구현된 인터페이스를 직접 또는 간접적으로 반환합니다. |
| GetInterface(String) |
지정된 이름의 인터페이스를 검색합니다. (다음에서 상속됨 Type) |
| GetInterfaceMap(Type) |
요청된 인터페이스에 대한 인터페이스 매핑을 반환합니다. |
| GetInterfaces() |
이 형식에 구현된 모든 인터페이스와 해당 기본 형식의 배열을 반환합니다. |
| GetMember(String, BindingFlags) |
지정된 바인딩 제약 조건을 사용하여 지정된 멤버를 검색합니다. (다음에서 상속됨 Type) |
| GetMember(String, MemberTypes, BindingFlags) |
지정된 대로 이 형식에 의해 선언되거나 상속된 모든 public 및 non-public 멤버를 반환합니다. |
| GetMember(String) |
지정된 이름의 공용 멤버를 검색합니다. (다음에서 상속됨 Type) |
| GetMembers() |
현재 Type모든 공용 멤버를 반환합니다. (다음에서 상속됨 Type) |
| GetMembers(BindingFlags) |
이 형식에 의해 선언되거나 상속된 public 및 public이 아닌 멤버에 대한 멤버를 반환합니다. |
| GetMethod(String, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[]) |
지정된 바인딩 제약 조건 및 지정된 호출 규칙을 사용하여 매개 변수가 지정된 인수 형식 및 한정자와 일치하는 지정된 메서드를 검색합니다. (다음에서 상속됨 Type) |
| GetMethod(String, BindingFlags, Binder, Type[], ParameterModifier[]) |
지정된 바인딩 제약 조건을 사용하여 매개 변수가 지정된 인수 형식 및 한정자와 일치하는 지정된 메서드를 검색합니다. (다음에서 상속됨 Type) |
| GetMethod(String, BindingFlags) |
지정된 바인딩 제약 조건을 사용하여 지정된 메서드를 검색합니다. (다음에서 상속됨 Type) |
| GetMethod(String, Int32, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[]) |
지정된 바인딩 제약 조건 및 지정된 호출 규칙을 사용하여 매개 변수가 지정된 제네릭 매개 변수 수, 인수 형식 및 한정자와 일치하는 지정된 메서드를 검색합니다. (다음에서 상속됨 Type) |
| GetMethod(String, Int32, BindingFlags, Binder, Type[], ParameterModifier[]) |
지정된 바인딩 제약 조건을 사용하여 매개 변수가 지정된 제네릭 매개 변수 수, 인수 형식 및 한정자와 일치하는 지정된 메서드를 검색합니다. (다음에서 상속됨 Type) |
| GetMethod(String, Int32, Type[], ParameterModifier[]) |
매개 변수가 지정된 제네릭 매개 변수 수, 인수 형식 및 한정자와 일치하는 지정된 public 메서드를 검색합니다. (다음에서 상속됨 Type) |
| GetMethod(String, Int32, Type[]) |
매개 변수가 지정된 제네릭 매개 변수 수 및 인수 형식과 일치하는 지정된 public 메서드를 검색합니다. (다음에서 상속됨 Type) |
| GetMethod(String, Type[], ParameterModifier[]) |
매개 변수가 지정된 인수 형식 및 한정자와 일치하는 지정된 public 메서드를 검색합니다. (다음에서 상속됨 Type) |
| GetMethod(String, Type[]) |
매개 변수가 지정된 인수 형식과 일치하는 지정된 public 메서드를 검색합니다. (다음에서 상속됨 Type) |
| GetMethod(String) |
지정된 이름의 public 메서드를 검색합니다. (다음에서 상속됨 Type) |
| GetMethod(Type, MethodInfo) |
제네릭 형식 정의의 지정된 메서드에 해당하는 지정된 생성된 제네릭 형식의 메서드를 반환합니다. |
| GetMethodImpl(String, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[]) |
파생 클래스에서 재정의되는 경우 지정된 바인딩 제약 조건 및 지정된 호출 규칙을 사용하여 매개 변수가 지정된 인수 형식 및 한정자와 일치하는 지정된 메서드를 검색합니다. (다음에서 상속됨 Type) |
| GetMethodImpl(String, Int32, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[]) |
파생 클래스에서 재정의되는 경우 지정된 바인딩 제약 조건 및 지정된 호출 규칙을 사용하여 매개 변수가 지정된 제네릭 매개 변수 수, 인수 형식 및 한정자와 일치하는 지정된 메서드를 검색합니다. (다음에서 상속됨 Type) |
| GetMethods() |
현재 Type모든 public 메서드를 반환합니다. (다음에서 상속됨 Type) |
| GetMethods(BindingFlags) |
지정된 대로 이 형식에 의해 선언되거나 상속된 모든 public 및 non-public 메서드를 반환합니다. |
| GetNestedType(String, BindingFlags) |
이 형식으로 선언된 public 및 비공용 중첩 형식을 반환합니다. |
| GetNestedType(String) |
지정된 이름의 공용 중첩 형식을 검색합니다. (다음에서 상속됨 Type) |
| GetNestedTypes() |
현재 Type중첩된 public 형식을 반환합니다. (다음에서 상속됨 Type) |
| GetNestedTypes(BindingFlags) |
이 형식에 의해 선언되거나 상속되는 public 및 비공용 중첩 형식을 반환합니다. |
| GetProperties() |
현재 Type모든 public 속성을 반환합니다. (다음에서 상속됨 Type) |
| GetProperties(BindingFlags) |
지정된 대로 이 형식에 의해 선언되거나 상속된 모든 public 및 non-public 속성을 반환합니다. |
| GetProperty(String, BindingFlags, Binder, Type, Type[], ParameterModifier[]) |
지정된 바인딩 제약 조건을 사용하여 매개 변수가 지정된 인수 형식 및 한정자와 일치하는 지정된 속성을 검색합니다. (다음에서 상속됨 Type) |
| GetProperty(String, BindingFlags) |
지정된 바인딩 제약 조건을 사용하여 지정된 속성을 검색합니다. (다음에서 상속됨 Type) |
| GetProperty(String, Type, Type[], ParameterModifier[]) |
매개 변수가 지정된 인수 형식 및 한정자와 일치하는 지정된 public 속성을 검색합니다. (다음에서 상속됨 Type) |
| GetProperty(String, Type, Type[]) |
매개 변수가 지정된 인수 형식과 일치하는 지정된 public 속성을 검색합니다. (다음에서 상속됨 Type) |
| GetProperty(String, Type) |
지정된 이름과 반환 형식을 사용하여 public 속성을 검색합니다. (다음에서 상속됨 Type) |
| GetProperty(String, Type[]) |
매개 변수가 지정된 인수 형식과 일치하는 지정된 public 속성을 검색합니다. (다음에서 상속됨 Type) |
| GetProperty(String) |
지정된 이름의 public 속성을 검색합니다. (다음에서 상속됨 Type) |
| GetPropertyImpl(String, BindingFlags, Binder, Type, Type[], ParameterModifier[]) |
파생 클래스에서 재정의되는 경우 지정된 바인딩 제약 조건을 사용하여 매개 변수가 지정된 인수 형식 및 한정자와 일치하는 지정된 속성을 검색합니다. (다음에서 상속됨 Type) |
| GetType() |
현재 Type가져옵니다. (다음에서 상속됨 Type) |
| GetTypeCodeImpl() |
이 Type 인스턴스의 기본 형식 코드를 반환합니다. (다음에서 상속됨 Type) |
| HasElementTypeImpl() |
파생 클래스에서 재정의되는 경우 HasElementType 속성을 구현하고 현재 Type 다른 형식을 포함하거나 참조하는지 여부를 결정합니다. 즉, 현재 Type 배열, 포인터 또는 참조로 전달되는지 여부입니다. (다음에서 상속됨 Type) |
| HasSameMetadataDefinitionAs(MemberInfo) |
런타임 동안 클래스의 새 인스턴스를 정의하고 만듭니다. (다음에서 상속됨 MemberInfo) |
| InvokeMember(String, BindingFlags, Binder, Object, Object[], CultureInfo) |
지정된 바인딩 제약 조건을 사용하고 지정된 인수 목록 및 문화권과 일치하는 지정된 멤버를 호출합니다. (다음에서 상속됨 Type) |
| InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[]) |
지정된 멤버를 호출합니다. 호출할 메서드에 액세스할 수 있어야 하며 지정된 바인더 및 호출 특성의 제약 조건 하에서 지정된 인수 목록과 가장 구체적인 일치 항목을 제공해야 합니다. |
| InvokeMember(String, BindingFlags, Binder, Object, Object[]) |
지정된 바인딩 제약 조건을 사용하고 지정된 인수 목록과 일치하여 지정된 멤버를 호출합니다. (다음에서 상속됨 Type) |
| IsArrayImpl() |
파생 클래스에서 재정의되는 경우 IsArray 속성을 구현하고 Type 배열인지 여부를 확인합니다. (다음에서 상속됨 Type) |
| IsAssignableFrom(Type) |
지정된 Type 개체를 이 개체에 할당할 수 있는지 여부를 나타내는 값을 가져옵니다. |
| IsAssignableFrom(TypeInfo) |
지정된 TypeInfo 개체를 이 개체에 할당할 수 있는지 여부를 나타내는 값을 가져옵니다. |
| IsByRefImpl() |
파생 클래스에서 재정의되는 경우 IsByRef 속성을 구현하고 Type 참조로 전달되는지 여부를 결정합니다. (다음에서 상속됨 Type) |
| IsCOMObjectImpl() |
파생 클래스에서 재정의되는 경우 IsCOMObject 속성을 구현하고 Type COM 개체인지 여부를 확인합니다. (다음에서 상속됨 Type) |
| IsContextfulImpl() |
IsContextful 속성을 구현하고 Type 컨텍스트에서 호스트할 수 있는지 여부를 결정합니다. (다음에서 상속됨 Type) |
| IsCreated() |
현재 동적 형식이 만들어졌는지 여부를 나타내는 값을 반환합니다. |
| IsDefined(Type, Boolean) |
사용자 지정 특성이 현재 형식에 적용되는지 여부를 결정합니다. |
| IsEnumDefined(Object) |
지정된 값이 현재 열거형 형식에 있는지 여부를 나타내는 값을 반환합니다. (다음에서 상속됨 Type) |
| IsEquivalentTo(Type) |
두 COM 형식의 ID가 같고 형식 동등성에 적합한지 여부를 결정합니다. (다음에서 상속됨 Type) |
| IsInstanceOfType(Object) |
지정된 개체가 현재 Type인스턴스인지 여부를 확인합니다. (다음에서 상속됨 Type) |
| IsMarshalByRefImpl() |
IsMarshalByRef 속성을 구현하고 Type 참조로 마샬링되는지 여부를 결정합니다. (다음에서 상속됨 Type) |
| IsPointerImpl() |
파생 클래스에서 재정의되는 경우 IsPointer 속성을 구현하고 Type 포인터인지 여부를 확인합니다. (다음에서 상속됨 Type) |
| IsPrimitiveImpl() |
파생 클래스에서 재정의되는 경우 IsPrimitive 속성을 구현하고 Type 기본 형식 중 하나인지 여부를 확인합니다. (다음에서 상속됨 Type) |
| IsSubclassOf(Type) |
이 형식이 지정된 형식에서 파생되는지 여부를 확인합니다. |
| IsValueTypeImpl() |
IsValueType 속성을 구현하고 Type 값 형식인지 여부를 확인합니다. 즉, 클래스 또는 인터페이스가 아닙니다. (다음에서 상속됨 Type) |
| MakeArrayType() |
Type 하한이 0인 현재 형식의 1차원 배열을 나타내는 개체를 반환합니다. |
| MakeArrayType(Int32) |
Type 지정된 차원 수를 사용하여 현재 형식의 배열을 나타내는 개체를 반환합니다. |
| MakeByRefType() |
|
| MakeGenericType(Type[]) |
현재 제네릭 형식 정의의 형식 매개 변수에 대한 형식 배열의 요소를 대체하고 생성된 결과 형식을 반환합니다. |
| MakePointerType() |
현재 형식에 Type 대한 관리되지 않는 포인터의 형식을 나타내는 개체를 반환합니다. |
| MemberwiseClone() |
현재 Object단순 복사본을 만듭니다. (다음에서 상속됨 Object) |
| SetCustomAttribute(ConstructorInfo, Byte[]) |
지정된 사용자 지정 특성 Blob을 사용하여 사용자 지정 특성을 설정합니다. |
| SetCustomAttribute(CustomAttributeBuilder) |
사용자 지정 특성 작성기를 사용하여 사용자 지정 특성을 설정합니다. |
| SetParent(Type) |
현재 생성 중인 형식의 기본 형식을 설정합니다. |
| ToString() |
네임스페이스를 제외한 형식의 이름을 반환합니다. |
명시적 인터페이스 구현
확장명 메서드
| Name | Description |
|---|---|
| GetCustomAttribute(MemberInfo, Type, Boolean) |
지정된 멤버에 적용되는 지정된 형식의 사용자 지정 특성을 검색하고 필요에 따라 해당 멤버의 상위 항목을 검사합니다. |
| GetCustomAttribute(MemberInfo, Type) |
지정된 멤버에 적용되는 지정된 형식의 사용자 지정 특성을 검색합니다. |
| GetCustomAttribute<T>(MemberInfo, Boolean) |
지정된 멤버에 적용되는 지정된 형식의 사용자 지정 특성을 검색하고 필요에 따라 해당 멤버의 상위 항목을 검사합니다. |
| GetCustomAttribute<T>(MemberInfo) |
지정된 멤버에 적용되는 지정된 형식의 사용자 지정 특성을 검색합니다. |
| GetCustomAttributes(MemberInfo, Boolean) |
지정된 멤버에 적용되는 사용자 지정 특성의 컬렉션을 검색하고 필요에 따라 해당 멤버의 상위 항목을 검사합니다. |
| GetCustomAttributes(MemberInfo, Type, Boolean) |
지정된 멤버에 적용되는 지정된 형식의 사용자 지정 특성 컬렉션을 검색하고 필요에 따라 해당 멤버의 상위 항목을 검사합니다. |
| GetCustomAttributes(MemberInfo, Type) |
지정된 멤버에 적용되는 지정된 형식의 사용자 지정 특성 컬렉션을 검색합니다. |
| GetCustomAttributes(MemberInfo) |
지정된 멤버에 적용되는 사용자 지정 특성의 컬렉션을 검색합니다. |
| GetCustomAttributes<T>(MemberInfo, Boolean) |
지정된 멤버에 적용되는 지정된 형식의 사용자 지정 특성 컬렉션을 검색하고 필요에 따라 해당 멤버의 상위 항목을 검사합니다. |
| GetCustomAttributes<T>(MemberInfo) |
지정된 멤버에 적용되는 지정된 형식의 사용자 지정 특성 컬렉션을 검색합니다. |
| GetRuntimeEvent(Type, String) |
지정된 이벤트를 나타내는 개체를 검색합니다. |
| GetRuntimeEvents(Type) |
지정된 형식에 정의된 모든 이벤트를 나타내는 컬렉션을 검색합니다. |
| GetRuntimeField(Type, String) |
지정된 필드를 나타내는 개체를 검색합니다. |
| GetRuntimeFields(Type) |
지정된 형식에 정의된 모든 필드를 나타내는 컬렉션을 검색합니다. |
| GetRuntimeInterfaceMap(TypeInfo, Type) |
지정된 형식 및 지정된 인터페이스에 대한 인터페이스 매핑을 반환합니다. |
| GetRuntimeMethod(Type, String, Type[]) |
지정된 메서드를 나타내는 개체를 검색합니다. |
| GetRuntimeMethods(Type) |
지정된 형식에 정의된 모든 메서드를 나타내는 컬렉션을 검색합니다. |
| GetRuntimeProperties(Type) |
지정된 형식에 정의된 모든 속성을 나타내는 컬렉션을 검색합니다. |
| GetRuntimeProperty(Type, String) |
지정된 속성을 나타내는 개체를 검색합니다. |
| GetTypeInfo(Type) |
지정된 형식의 TypeInfo 표현을 반환합니다. |
| IsDefined(MemberInfo, Type, Boolean) |
지정된 형식의 사용자 지정 특성이 지정된 멤버에 적용되는지 여부와 필요에 따라 상위 항목에 적용되는지 여부를 나타냅니다. |
| IsDefined(MemberInfo, Type) |
지정된 형식의 사용자 지정 특성이 지정된 멤버에 적용되는지 여부를 나타냅니다. |