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
- 継承
- 継承
- 属性
- 実装
例
次のコード例は、動的アセンブリを定義して使用する方法を示しています。 この例のアセンブリには、プライベート フィールドを持つ 1 つの型 ( 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 解説」を参照してください。
フィールド
| 名前 | 説明 |
|---|---|
| UnspecifiedTypeSize |
型の合計サイズが指定されていないことを表します。 |
プロパティ
| 名前 | 説明 |
|---|---|
| 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 |
型が byref に似た構造体であるかどうかを示す値を取得します。 |
| 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にComImportAttribute属性が適用されているかどうかを示す値を取得します。これは、COM タイプ ライブラリからインポートされたことを示します。 (継承元 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 |
クラスが入れ子にされ、パブリックとして宣言されているかどうかを示す値を取得します。 (継承元 Type) |
| IsNotPublic |
Typeがパブリックとして宣言されていないかどうかを示す値を取得します。 (継承元 Type) |
| IsPointer |
Typeがポインターであるかどうかを示す値を取得します。 (継承元 Type) |
| IsPrimitive |
Typeがプリミティブ型の 1 つであるかどうかを示す値を取得します。 (継承元 Type) |
| IsPublic |
Typeがパブリックとして宣言されているかどうかを示す値を取得します。 (継承元 Type) |
| IsSealed |
Typeがシール済みとして宣言されているかどうかを示す値を取得します。 (継承元 Type) |
| IsSecurityCritical |
現在の型がセキュリティ クリティカルかセキュリティ セーフ クリティカルかを示す値を取得します。そのため、重要な操作を実行できます。 |
| IsSecuritySafeCritical |
現在の型がセキュリティ セーフ クリティカルであるかどうかを示す値を取得します。つまり、重要な操作を実行でき、透過的なコードからアクセスできるかどうかです。 |
| IsSecurityTransparent |
現在の型が透過的であり、重要な操作を実行できないかどうかを示す値を取得します。 |
| IsSerializable |
Typeがバイナリ シリアル化可能かどうかを示す値を取得します。 (継承元 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 |
この |
メソッド
| 名前 | 説明 |
|---|---|
| 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) |
指定したとおり、このクラスに対して定義されたパブリック コンストラクターと非パブリック コンストラクターを表す 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() |
このメソッドを呼び出すと、常に NotSupportedExceptionがスローされます。 |
| GetEnumName(Object) |
現在の列挙型の指定した値を持つ定数の名前を返します。 (継承元 Type) |
| GetEnumNames() |
現在の列挙型のメンバーの名前を返します。 (継承元 Type) |
| GetEnumUnderlyingType() |
現在の列挙型の基になる型を返します。 (継承元 Type) |
| GetEnumValues() |
現在の列挙型の定数の値の配列を返します。 (継承元 Type) |
| GetEvent(String, BindingFlags) |
指定した名前のイベントを返します。 |
| GetEvent(String) |
指定したパブリック イベントを表す EventInfo オブジェクトを返します。 (継承元 Type) |
| GetEvents() |
この型によって宣言または継承されたパブリック イベントを返します。 |
| GetEvents(BindingFlags) |
この型で宣言されているパブリック イベントと非パブリック イベントを返します。 |
| GetField(String, BindingFlags) |
指定された名前で指定されたフィールドを返します。 |
| GetField(String) |
指定した名前のパブリック フィールドを検索します。 (継承元 Type) |
| GetField(Type, FieldInfo) |
ジェネリック型定義の指定したフィールドに対応する、指定した構築済みジェネリック型のフィールドを返します。 |
| GetFields() |
現在の Typeのすべてのパブリック フィールドを返します。 (継承元 Type) |
| GetFields(BindingFlags) |
この型で宣言されているパブリック フィールドとパブリックフィールド以外のフィールドを返します。 |
| 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) |
指定されたとおりに、この型によって宣言または継承されたすべてのパブリック メンバーと非パブリック メンバーを返します。 |
| GetMember(String) |
指定した名前のパブリック メンバーを検索します。 (継承元 Type) |
| GetMembers() |
現在の Typeのすべてのパブリック メンバーを返します。 (継承元 Type) |
| GetMembers(BindingFlags) |
この型によって宣言または継承されたパブリック メンバーと非パブリック メンバーのメンバーを返します。 |
| 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[]) |
指定したジェネリック パラメーター数、引数の型、および修飾子と一致するパラメーターを持つ、指定したパブリック メソッドを検索します。 (継承元 Type) |
| GetMethod(String, Int32, Type[]) |
指定したジェネリック パラメーターの数と引数の型と一致するパラメーターを持つ、指定したパブリック メソッドを検索します。 (継承元 Type) |
| GetMethod(String, Type[], ParameterModifier[]) |
指定した引数の型と修飾子に一致するパラメーターを持つ、指定したパブリック メソッドを検索します。 (継承元 Type) |
| GetMethod(String, Type[]) |
指定した引数の型と一致するパラメーターを持つ、指定したパブリック メソッドを検索します。 (継承元 Type) |
| GetMethod(String) |
指定した名前のパブリック メソッドを検索します。 (継承元 Type) |
| GetMethod(Type, MethodInfo) |
ジェネリック型定義の指定したメソッドに対応する、指定した構築済みジェネリック型のメソッドを返します。 |
| GetMethodImpl(String, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[]) |
派生クラスでオーバーライドされると、指定したバインディング制約と指定した呼び出し規則を使用して、指定した引数の型と修飾子と一致するパラメーターを持つ指定したメソッドを検索します。 (継承元 Type) |
| GetMethodImpl(String, Int32, BindingFlags, Binder, CallingConventions, Type[], ParameterModifier[]) |
派生クラスでオーバーライドされた場合、指定したバインディング制約と指定した呼び出し規則を使用して、指定したジェネリック パラメーター数、引数の型、および修飾子と一致するパラメーターを持つ、指定したメソッドを検索します。 (継承元 Type) |
| GetMethods() |
現在の Typeのすべてのパブリック メソッドを返します。 (継承元 Type) |
| GetMethods(BindingFlags) |
指定されたとおりに、この型によって宣言または継承されたすべてのパブリック メソッドと非パブリック メソッドを返します。 |
| GetNestedType(String, BindingFlags) |
この型で宣言されているパブリック型とパブリックでない入れ子になった型を返します。 |
| GetNestedType(String) |
指定した名前を持つパブリックの入れ子になった型を検索します。 (継承元 Type) |
| GetNestedTypes() |
現在の Typeに入れ子になったパブリック型を返します。 (継承元 Type) |
| GetNestedTypes(BindingFlags) |
この型によって宣言または継承される、パブリック型とパブリックでない入れ子になった型を返します。 |
| GetProperties() |
現在の Typeのすべてのパブリック プロパティを返します。 (継承元 Type) |
| GetProperties(BindingFlags) |
指定されたとおりに、この型によって宣言または継承されたすべてのパブリック プロパティと非パブリック プロパティを返します。 |
| GetProperty(String, BindingFlags, Binder, Type, Type[], ParameterModifier[]) |
指定したバインディング制約を使用して、指定した引数の型と修飾子と一致するパラメーターを持つ、指定したプロパティを検索します。 (継承元 Type) |
| GetProperty(String, BindingFlags) |
指定したバインド制約を使用して、指定したプロパティを検索します。 (継承元 Type) |
| GetProperty(String, Type, Type[], ParameterModifier[]) |
指定した引数の型と修飾子に一致するパラメーターを持つ、指定したパブリック プロパティを検索します。 (継承元 Type) |
| GetProperty(String, Type, Type[]) |
指定した引数の型と一致するパラメーターを持つ、指定したパブリック プロパティを検索します。 (継承元 Type) |
| GetProperty(String, Type) |
指定した名前と戻り値の型を持つパブリック プロパティを検索します。 (継承元 Type) |
| GetProperty(String, Type[]) |
指定した引数の型と一致するパラメーターを持つ、指定したパブリック プロパティを検索します。 (継承元 Type) |
| GetProperty(String) |
指定した名前のパブリック プロパティを検索します。 (継承元 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) |
2 つの COM 型が同じ ID を持ち、型の等価性の対象であるかどうかを判断します。 (継承元 Type) |
| IsInstanceOfType(Object) |
指定したオブジェクトが現在の Typeのインスタンスであるかどうかを判断します。 (継承元 Type) |
| IsMarshalByRefImpl() |
IsMarshalByRef プロパティを実装し、Typeが参照によってマーシャリングされるかどうかを判断します。 (継承元 Type) |
| IsPointerImpl() |
派生クラスでオーバーライドされると、 IsPointer プロパティを実装し、 Type がポインターであるかどうかを判断します。 (継承元 Type) |
| IsPrimitiveImpl() |
派生クラスでオーバーライドされると、 IsPrimitive プロパティを実装し、 Type がプリミティブ型の 1 つであるかどうかを判断します。 (継承元 Type) |
| IsSubclassOf(Type) |
この型が指定した型から派生しているかどうかを判断します。 |
| IsValueTypeImpl() |
IsValueType プロパティを実装し、Typeが値型(クラスまたはインターフェイスではない)であるかどうかを判断します。 (継承元 Type) |
| MakeArrayType() |
下限が 0 の現在の型の 1 次元配列を表す Type オブジェクトを返します。 |
| MakeArrayType(Int32) |
指定した次元数の現在の型の配列を表す Type オブジェクトを返します。 |
| MakeByRefType() |
|
| MakeGenericType(Type[]) |
型の配列の要素を現在のジェネリック型定義の型パラメーターに置き換え、結果として構築された型を返します。 |
| MakePointerType() |
現在の型へのアンマネージ ポインターの型を表す Type オブジェクトを返します。 |
| MemberwiseClone() |
現在の Objectの簡易コピーを作成します。 (継承元 Object) |
| SetCustomAttribute(ConstructorInfo, Byte[]) |
指定したカスタム属性 BLOB を使用してカスタム属性を設定します。 |
| SetCustomAttribute(CustomAttributeBuilder) |
カスタム属性ビルダーを使用してカスタム属性を設定します。 |
| SetParent(Type) |
現在構築中の型の基本型を設定します。 |
| ToString() |
名前空間を除く型の名前を返します。 |
明示的なインターフェイスの実装
拡張メソッド
| 名前 | 説明 |
|---|---|
| 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) |
指定した型のカスタム属性が、指定したメンバーに適用されるかどうかを示します。 |