DynamicMethodとは? わかりやすく解説

DynamicMethod クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

動的メソッドを定義および表現します。このクラス継承できません。

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<ComVisibleAttribute(True)> _
Public NotInheritable Class
 DynamicMethod
    Inherits MethodInfo
Dim instance As DynamicMethod
[ComVisibleAttribute(true)] 
public sealed class DynamicMethod : MethodInfo
[ComVisibleAttribute(true)] 
public ref class DynamicMethod sealed : public
 MethodInfo
/** @attribute ComVisibleAttribute(true) */ 
public final class DynamicMethod extends MethodInfo
ComVisibleAttribute(true) 
public final class DynamicMethod extends
 MethodInfo
解説解説

DynamicMethod クラス使用すると、実行時メソッド生成し実行できますメソッド格納するために、動的アセンブリ動的型生成する要はありません。動的メソッドは、少量コード生成し実行するための最も効率的な方法です。

動的メソッドは、モジュールまたは型に論理的に関連付けられます。動的メソッドモジュール関連付けられている場合、そのモジュールに対して実質的にグローバルです。十分なアクセス許可があれば、動的メソッドジャスト イン タイム (JIT: Just-In-Time) の参照範囲チェックスキップし、そのモジュール内で宣言されている型のプライベート データアクセスできます開発者がそのモジュール作成したかどうかに関係なく、動的メソッドはどのモジュールにでも関連付けることができます

動的メソッドが型に関連付けられている場合、その型のプライベート メンバアクセスできます動的メソッドが同じモジュール内で宣言されている他の型のプライベート データアクセスない場合は、JIT参照範囲チェックスキップする要はありません。動的メソッドは、どの型にも関連付けることができます

モジュールまたはモジュール内の型に関連付けられた動的メソッドについて、JIT参照範囲チェックを行う場合およびスキップする場合に、動的メソッドアクセス可能なモジュール内の型のメンバ次の表に示します

動的メソッドは、関連付けられているモジュール、または関連付けられている型を格納するモジュールアクセス許可持ちます

動的メソッドとそのパラメータには、名前を付ける必要はありませんが、名前を指定するデバッグを行う際に役立ちます動的メソッドまたはそのパラメータでは、カスタム属性サポートされていません。

動的メソッドstatic メソッド (Visual Basic では Shared メソッド) ですが、.NET Framework Version 2.0導入されているデリゲート バインディング緩やかな規則では、動的メソッドオブジェクトバインドすることが許可されています。たがって、そのデリゲート インスタンス使用して動的メソッド呼び出した場合インスタンス メソッド同様に機能します。この例については、CreateDelegate(Type,Object) メソッド オーバーロード説明してます。

使用例使用例

2 つパラメータ使用する動的メソッド作成するコード例次に示します。この例では、コンソール1 つ目のパラメータ出力する簡単な関数本体出力し2 つ目のパラメータメソッド戻り値として使用してます。この例では、デリゲート作成することによってメソッド完了しさまざまなパラメータを持つデリゲート呼び出し最後に Invoke メソッド使用して動的メソッド呼び出します。

Imports System
Imports System.Reflection
Imports System.Reflection.Emit
Imports Microsoft.VisualBasic
Imports System.Globalization

Public Class Test
    ' Declare a delegate type that can be used to execute the completed
    ' dynamic method. 
    Private Delegate Function
 HelloDelegate(ByVal msg As String,
 _
        ByVal ret As Integer)
 As Integer

    Public Shared Sub Main()
        ' Create an array that specifies the types of the parameters
        ' of the dynamic method. This dynamic method has a String
        ' parameter and an Integer parameter.
        Dim helloArgs() As Type = {GetType(String),
 GetType(Integer)}

        ' Create a dynamic method with the name "Hello", a
 return type
        ' of Integer, and two parameters whose types are specified by
        ' the array helloArgs. Create the method in the module that
        ' defines the String class.
        Dim hello As New
 DynamicMethod("Hello", _
            GetType(Integer), _
            helloArgs, _
            GetType(String).Module)

        ' Create an array that specifies the parameter types of the
        ' overload of Console.WriteLine to be used in Hello.
        Dim writeStringArgs() As Type = {GetType(String)}
        ' Get the overload of Console.WriteLine that has one
        ' String parameter.
        Dim writeString As MethodInfo = GetType(Console).
 _
            GetMethod("WriteLine", writeStringArgs)
 

        ' Get an ILGenerator and emit a body for the dynamic method
,
        ' using a stream size larger than the IL that will be
        ' emitted.
        Dim il As ILGenerator = hello.GetILGenerator(256)
        ' Load the first argument, which is a string, onto the stack.
        il.Emit(OpCodes.Ldarg_0)
        ' Call the overload of Console.WriteLine that prints a string.
        il.EmitCall(OpCodes.Call, writeString, Nothing)
        ' The Hello method returns the value of the second argument;
        ' to do this, load the onto the stack and return.
        il.Emit(OpCodes.Ldarg_1)
        il.Emit(OpCodes.Ret)

        ' Display MethodAttributes for the dynamic method, set when
 
        ' the dynamic method was created.
        Console.WriteLine(vbCrLf & "Method Attributes: {0}",
 _
            hello.Attributes)

        ' Display the calling convention of the dynamic method, set
 when the 
        ' dynamic method was created.
        Console.WriteLine(vbCrLf & "Calling convention: {0}",
 _ 
            hello.CallingConvention)

        ' Display the declaring type, which is always Nothing for dynamic
        ' methods.
        If hello.DeclaringType Is Nothing
 Then
            Console.WriteLine(vbCrLf & "DeclaringType is always
 Nothing for dynamic methods.")
        Else
            Console.WriteLine("DeclaringType: {0}",
 hello.DeclaringType)
        End If

        ' Display the default value for InitLocals.
        If hello.InitLocals Then
            Console.Write(vbCrLf & "This method contains verifiable
 code.")
        Else
            Console.Write(vbCrLf & "This method contains unverifiable
 code.")
        End If
        Console.WriteLine(" (InitLocals = {0})", hello.InitLocals)

        ' Display the module specified when the dynamic method was created.
        Console.WriteLine(vbCrLf & "Module: {0}",
 hello.Module)

        ' Display the name specified when the dynamic method was created.
        ' Note that the name can be blank.
        Console.WriteLine(vbCrLf & "Name: {0}",
 hello.Name)

        ' For dynamic methods, the reflected type is always Nothing.
        If hello.ReflectedType Is Nothing
 Then
            Console.WriteLine(vbCrLf & "ReflectedType is Nothing.")
        Else
            Console.WriteLine(vbCrLf & "ReflectedType: {0}",
 _
                hello.ReflectedType)
        End If

        If hello.ReturnParameter Is Nothing
 Then
            Console.WriteLine(vbCrLf & "Method has no return
 parameter.")
        Else
            Console.WriteLine(vbCrLf & "Return parameter:
 {0}", _
                hello.ReturnParameter)
        End If

        ' If the method has no return type, ReturnType is System.Void.
        Console.WriteLine(vbCrLf & "Return type: {0}",
 hello.ReturnType)           

        ' ReturnTypeCustomAttributes returns an ICustomeAttributeProvider
        ' that can be used to enumerate the custom attributes of the
        ' return value. At present, there is no way to set such custom
        ' attributes, so the list is empty.
        If hello.ReturnType Is GetType(System.Void)
 Then
            Console.WriteLine("The method has no return type.")
        Else
            Dim caProvider As ICustomAttributeProvider
 = _
                hello.ReturnTypeCustomAttributes
            Dim returnAttributes() As Object
 = _
                caProvider.GetCustomAttributes(True)
            If returnAttributes.Length = 0 Then
                Console.WriteLine(vbCrLf _
                    & "The return type has no custom attributes.")
            Else
                Console.WriteLine(vbCrLf _
                    & "The return type has the following custom
 attributes:")
                For Each attr As
 Object In returnAttributes
                    Console.WriteLine(vbTab & attr.ToString())
                Next attr
            End If
        End If

        Console.WriteLine(vbCrLf & "ToString: "
 & hello.ToString())

        ' Add parameter information to the dynamic method. (This is
 not
        ' necessary, but can be useful for debugging.) For each parameter
,
        ' identified by position, supply the parameter attributes and
 a 
        ' parameter name.
        Dim parameter1 As ParameterBuilder
 = hello.DefineParameter( _
             1, ParameterAttributes.In, "message")
        Dim parameter2 As ParameterBuilder
 = hello.DefineParameter( _
             2, ParameterAttributes.In, "valueToReturn")

        ' Display parameter information.
        Dim parameters() As ParameterInfo =
 hello.GetParameters()
        Console.WriteLine(vbCrLf & "Parameters: name, type,
 ParameterAttributes")
        For Each p As ParameterInfo
 In parameters
            Console.WriteLine(vbTab & "{0}, {1}, {2}",
 _ 
                p.Name, p.ParameterType, p.Attributes)
        Next p

        ' Create a delegate that represents the dynamic method. This
        ' action completes the method, and any further attempts to
        ' change the method will cause an exception.
    Dim hi As HelloDelegate = _
            CType(hello.CreateDelegate(GetType(HelloDelegate)),
 HelloDelegate)

        ' Use the delegate to execute the dynamic method.
        Console.WriteLine(vbCrLf & "Use the delegate to execute
 the dynamic method:")
        Dim retval As Integer
 = hi(vbCrLf & "Hello, World!", 42)
        Console.WriteLine("Invoking delegate hi(""Hello,
 World!"", 42) returned: " _
            & retval & ".")

        ' Execute it again, with different arguments.
        retval = hi(vbCrLf & "Hi, Mom!", 5280)
        Console.WriteLine("Invoking delegate hi(""Hi,
 Mom!"", 5280) returned: " _
            & retval & ".")

        Console.WriteLine(vbCrLf & "Use the Invoke method
 to execute the dynamic method:")
        ' Create an array of arguments to use with the Invoke method.
        Dim invokeArgs() As Object
 = {vbCrLf & "Hello, World!", 42}
        ' Invoke the dynamic method using the arguments. This is much
        ' slower than using the delegate, because you must create an
        ' array to contain the arguments, and value-type arguments
        ' must be boxed.
        Dim objRet As Object
 = hello.Invoke(Nothing, _
            BindingFlags.ExactBinding, Nothing, invokeArgs, _
            New CultureInfo("en-us"))
        Console.WriteLine("hello.Invoke returned: {0}",
 objRet)
    End Sub
End Class

' This code example produces the following output:
'
'Method Attributes: PrivateScope, Public, Static
'
'Calling convention: Standard
'
'DeclaringType is always Nothing for dynamic methods.
'
'This method contains verifiable code. (InitLocals = True)
'
'Module: CommonLanguageRuntimeLibrary
'
'Name: Hello
'
'ReflectedType is Nothing.
'
'Method has no return parameter.
'
'Return type: System.Int32
'
'The return type has no custom attributes.
'
'ToString: Int32 Hello(System.String, Int32)
'
'Parameters: name, type, ParameterAttributes
'        message, System.String, In
'        valueToReturn, System.Int32, In
'
'Use the delegate to execute the dynamic method:
'
'Hello, World!
'Invoking delegate hi("Hello, World!", 42) returned: 42.
'
'Hi, Mom!
'Invoking delegate hi("Hi, Mom!", 5280) returned: 5280.
'
'Use the Invoke method to execute the dynamic method:
'
'Hello, World!
'hello.Invoke returned: 42
using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Globalization;

public class Test
{
    // Declare a delegate type that can be used to execute the completed
    // dynamic method. 
    private delegate int HelloDelegate(string
 msg, int ret);

    public static void Main()
    {
        // Create an array that specifies the types of the parameters
        // of the dynamic method. This dynamic method has a String
        // parameter and an Integer parameter.
        Type[] helloArgs = {typeof(string), typeof(int)};

        // Create a dynamic method with the name "Hello",
 a return type
        // of Integer, and two parameters whose types are specified
 by
        // the array helloArgs. Create the method in the module that
        // defines the String class.
        DynamicMethod hello = new DynamicMethod("Hello",
 
            typeof(int), 
            helloArgs, 
            typeof(string).Module);

        // Create an array that specifies the parameter types of the
        // overload of Console.WriteLine to be used in Hello.
        Type[] writeStringArgs = {typeof(string)};
        // Get the overload of Console.WriteLine that has one
        // String parameter.
        MethodInfo writeString = typeof(Console).GetMethod("WriteLine",
 
            writeStringArgs);

        // Get an ILGenerator and emit a body for the dynamic method
,
        // using a stream size larger than the IL that will be
        // emitted.
        ILGenerator il = hello.GetILGenerator(256);
        // Load the first argument, which is a string, onto the stack.
        il.Emit(OpCodes.Ldarg_0);
        // Call the overload of Console.WriteLine that prints a string.
        il.EmitCall(OpCodes.Call, writeString, null);
        // The Hello method returns the value of the second argument;
        // to do this, load the onto the stack and return.
        il.Emit(OpCodes.Ldarg_1);
        il.Emit(OpCodes.Ret);

        // Display MethodAttributes for the dynamic method, set when
 
        // the dynamic method was created.
        Console.WriteLine("\r\nMethod Attributes: {0}", hello.Attributes);

        // Display the calling convention of the dynamic method, set
 when the 
        // dynamic method was created.
        Console.WriteLine("\r\nCalling convention: {0}", hello.CallingConvention);

        // Display the declaring type, which is always null for dynamic
        // methods.
        if (hello.DeclaringType==null)
        {
            Console.WriteLine("\r\nDeclaringType is always null
 for dynamic methods.");
        }
        else
        {
            Console.WriteLine("DeclaringType: {0}", hello.DeclaringType);
        }

        // Display the default value for InitLocals.
        if (hello.InitLocals)
        {
            Console.Write("\r\nThis method contains verifiable code.");
        }
        else
        {
            Console.Write("\r\nThis method contains unverifiable code.");
        }
        Console.WriteLine(" (InitLocals = {0})", hello.InitLocals);

        // Display the module specified when the dynamic method was
 created.
        Console.WriteLine("\r\nModule: {0}", hello.Module);

        // Display the name specified when the dynamic method was created.
        // Note that the name can be blank.
        Console.WriteLine("\r\nName: {0}", hello.Name);

        // For dynamic methods, the reflected type is always null.
        if (hello.ReflectedType==null)
        {
            Console.WriteLine("\r\nReflectedType is null.");
        }
        else
        {
            Console.WriteLine("\r\nReflectedType: {0}", hello.ReflectedType);
        }

        if (hello.ReturnParameter==null)
        {
            Console.WriteLine("\r\nMethod has no return parameter.");
        }
        else
        {
            Console.WriteLine("\r\nReturn parameter: {0}", hello.ReturnParameter);
        }

        // If the method has no return type, ReturnType is System.Void.
        Console.WriteLine("\r\nReturn type: {0}", hello.ReturnType);

        // ReturnTypeCustomAttributes returns an ICustomeAttributeProvider
        // that can be used to enumerate the custom attributes of the
        // return value. At present, there is no way to set such custom
        // attributes, so the list is empty.
        if (hello.ReturnType == typeof(void))
        {
            Console.WriteLine("The method has no return type.");
        }
        else
        {
            ICustomAttributeProvider caProvider = hello.ReturnTypeCustomAttributes;
            object[] returnAttributes = caProvider.GetCustomAttributes(true);
            if (returnAttributes.Length==0)
            {
                Console.WriteLine("\r\nThe return type has
 no custom attributes.");
            }
            else
            {
                Console.WriteLine("\r\nThe return type has
 the following custom attributes:");
                foreach( object attr in returnAttributes
 )
                {
                    Console.WriteLine("\t{0}", attr.ToString());
                }
            }
        }

        Console.WriteLine("\r\nToString: {0}", hello.ToString());

        // Add parameter information to the dynamic method. (This is
 not
        // necessary, but can be useful for debugging.) For each parameter
,
        // identified by position, supply the parameter attributes and
 a 
        // parameter name.
        ParameterBuilder parameter1 = hello.DefineParameter(
            1, 
            ParameterAttributes.In, 
            "message"
        );
        ParameterBuilder parameter2 = hello.DefineParameter(
            2, 
            ParameterAttributes.In, 
            "valueToReturn"
        );

        // Display parameter information.
        ParameterInfo[] parameters = hello.GetParameters();
        Console.WriteLine("\r\nParameters: name, type, ParameterAttributes");
        foreach( ParameterInfo p in parameters
 )
        {
            Console.WriteLine("\t{0}, {1}, {2}", 
                p.Name, p.ParameterType, p.Attributes);
        }

        // Create a delegate that represents the dynamic method. This
        // action completes the method, and any further attempts to
        // change the method will cause an exception.
        HelloDelegate hi = 
            (HelloDelegate) hello.CreateDelegate(typeof(HelloDelegate));

        // Use the delegate to execute the dynamic method.
        Console.WriteLine("\r\nUse the delegate to execute the dynamic method:");
        int retval = hi("\r\nHello, World!", 42);
        Console.WriteLine("Invoking delegate hi(\"Hello, World!\",
 42) returned: " + retval);

        // Execute it again, with different arguments.
        retval = hi("\r\nHi, Mom!", 5280);
        Console.WriteLine("Invoking delegate hi(\"Hi, Mom!\", 5280)
 returned: " + retval);

        Console.WriteLine("\r\nUse the Invoke method to execute the dynamic
 method:");
        // Create an array of arguments to use with the Invoke method.
        object[] invokeArgs = {"\r\nHello, World!", 42};
        // Invoke the dynamic method using the arguments. This is much
        // slower than using the delegate, because you must create an
        // array to contain the arguments, and value-type arguments
        // must be boxed.
        object objRet = hello.Invoke(null, BindingFlags.ExactBinding,
 null, invokeArgs, new CultureInfo("en-us"));
        Console.WriteLine("hello.Invoke returned: " + objRet);
    }
}

/* This code example produces the following output:

Method Attributes: PrivateScope, Public, Static

Calling convention: Standard

DeclaringType is always null for dynamic methods.

This method contains verifiable code. (InitLocals = True)

Module: CommonLanguageRuntimeLibrary

Name: Hello

ReflectedType is null.

Method has no return parameter.

Return type: System.Int32

The return type has no custom attributes.

ToString: Int32 Hello(System.String, Int32)

Parameters: name, type, ParameterAttributes
        message, System.String, In
        valueToReturn, System.Int32, In

Use the delegate to execute the dynamic method:

Hello, World!
Invoking delegate hi("Hello, World!", 42) returned: 42

Hi, Mom!
Invoking delegate hi("Hi, Mom!", 5280) returned: 5280

Use the Invoke method to execute the dynamic method:

Hello, World!
hello.Invoke returned: 42
 */
継承階層継承階層
System.Object
   System.Reflection.MemberInfo
     System.Reflection.MethodBase
       System.Reflection.MethodInfo
        System.Reflection.Emit.DynamicMethod
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DynamicMethod コンストラクタ (String, MethodAttributes, CallingConventions, Type, Type[], Module, Boolean)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

メソッド名、属性呼び出し規約戻り値の型、パラメータの型、モジュール指定し、さらにモジュール内のすべての型のメンバに対して JIT (Just-In-Time) の参照範囲チェックスキップする必要があるかどうか指定してモジュールに対してグローバルな動的メソッド作成します

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    name As String, _
    attributes As MethodAttributes, _
    callingConvention As CallingConventions, _
    returnType As Type, _
    parameterTypes As Type(), _
    m As Module, _
    skipVisibility As Boolean _
)
Dim name As String
Dim attributes As MethodAttributes
Dim callingConvention As CallingConventions
Dim returnType As Type
Dim parameterTypes As Type()
Dim m As Module
Dim skipVisibility As Boolean

Dim instance As New DynamicMethod(name,
 attributes, callingConvention, returnType, parameterTypes, m, skipVisibility)
public DynamicMethod (
    string name,
    MethodAttributes attributes,
    CallingConventions callingConvention,
    Type returnType,
    Type[] parameterTypes,
    Module m,
    bool skipVisibility
)
public:
DynamicMethod (
    String^ name, 
    MethodAttributes attributes, 
    CallingConventions callingConvention, 
    Type^ returnType, 
    array<Type^>^ parameterTypes, 
    Module^ m, 
    bool skipVisibility
)
public DynamicMethod (
    String name, 
    MethodAttributes attributes, 
    CallingConventions callingConvention, 
    Type returnType, 
    Type[] parameterTypes, 
    Module m, 
    boolean skipVisibility
)
public function DynamicMethod (
    name : String, 
    attributes : MethodAttributes, 
    callingConvention : CallingConventions, 
    returnType : Type, 
    parameterTypes : Type[], 
    m : Module, 
    skipVisibility : boolean
)

パラメータ

name

動的メソッドの名前。長さ 0 の文字列でもかまいませんが、null 参照 (Visual Basic では Nothing) にはできません。

attributes

動的メソッド属性指定する MethodAttributes 値のビットごとの組み合わせ許可される組み合わせは、PublicStatic組み合わせだけです。

callingConvention

動的メソッド呼び出し規約Standard にする必要があります

returnType

動的メソッド戻り値の型を指定する Type オブジェクトメソッド戻り値の型がない場合null 参照 (Visual Basic では Nothing)。

parameterTypes

動的メソッドパラメータの型を指定する Type オブジェクト配列メソッドパラメータない場合null 参照 (Visual Basic では Nothing)。

m

動的メソッド論理的に関連付けるモジュールを表す Module

skipVisibility

すべてのモジュール内のすべての型のメンバに対して JIT参照範囲チェックスキップする場合trueそれ以外場合false

例外例外
例外種類条件

ArgumentException

parameterTypes要素null 参照 (Visual Basic では Nothing) または Void です。

ArgumentNullException

namenull 参照 (Visual Basic では Nothing) です。

または

m null 参照 (Visual Basic では Nothing) です。

NotSupportedException

attributesPublicStatic 以外のフラグ組み合わせです。

または

callingConventionStandard ではありません。

または

returnType は Type.IsByRef で true返される型です。

解説解説
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DynamicMethod コンストラクタ (String, MethodAttributes, CallingConventions, Type, Type[], Type, Boolean)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

メソッド名、属性呼び出し規約戻り値の型、パラメータの型、動的メソッド論理的に関連付ける型を指定し、さらにモジュール内の他の型のメンバに対して JIT (Just-In-Time) の参照範囲チェックスキップする必要があるかどうか指定して動的メソッド作成します

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    name As String, _
    attributes As MethodAttributes, _
    callingConvention As CallingConventions, _
    returnType As Type, _
    parameterTypes As Type(), _
    owner As Type, _
    skipVisibility As Boolean _
)
Dim name As String
Dim attributes As MethodAttributes
Dim callingConvention As CallingConventions
Dim returnType As Type
Dim parameterTypes As Type()
Dim owner As Type
Dim skipVisibility As Boolean

Dim instance As New DynamicMethod(name,
 attributes, callingConvention, returnType, parameterTypes, owner, skipVisibility)
public DynamicMethod (
    string name,
    MethodAttributes attributes,
    CallingConventions callingConvention,
    Type returnType,
    Type[] parameterTypes,
    Type owner,
    bool skipVisibility
)
public:
DynamicMethod (
    String^ name, 
    MethodAttributes attributes, 
    CallingConventions callingConvention, 
    Type^ returnType, 
    array<Type^>^ parameterTypes, 
    Type^ owner, 
    bool skipVisibility
)
public DynamicMethod (
    String name, 
    MethodAttributes attributes, 
    CallingConventions callingConvention, 
    Type returnType, 
    Type[] parameterTypes, 
    Type owner, 
    boolean skipVisibility
)
public function DynamicMethod (
    name : String, 
    attributes : MethodAttributes, 
    callingConvention : CallingConventions, 
    returnType : Type, 
    parameterTypes : Type[], 
    owner : Type, 
    skipVisibility : boolean
)

パラメータ

name

動的メソッドの名前。長さ 0 の文字列でもかまいませんが、null 参照 (Visual Basic では Nothing) にはできません。

attributes

動的メソッド属性指定する MethodAttributes 値のビットごとの組み合わせ許可される組み合わせは、PublicStatic組み合わせだけです。

callingConvention

動的メソッド呼び出し規約Standard にする必要があります

returnType

動的メソッド戻り値の型を指定する Type オブジェクトメソッド戻り値の型がない場合null 参照 (Visual Basic では Nothing)。

parameterTypes

動的メソッドパラメータの型を指定する Type オブジェクト配列メソッドパラメータない場合null 参照 (Visual Basic では Nothing)。

owner

動的メソッド論理的に関連付ける Type動的メソッドはこの型のすべてのメンバアクセスできます

skipVisibility

すべてのモジュール内のすべての型のすべてのメンバに対して JIT参照範囲チェックスキップする場合trueそれ以外場合false

例外例外
例外種類条件

ArgumentException

parameterTypes要素null 参照 (Visual Basic では Nothing) または Void です。

または

ownerインターフェイス配列オープン ジェネリック型ジェネリック型またはジェネリック メソッド型パラメータです。

ArgumentNullException

namenull 参照 (Visual Basic では Nothing) です。

または

owner null 参照 (Visual Basic では Nothing) です。

NotSupportedException

attributesPublicStatic 以外のフラグ組み合わせです。

または

callingConventionStandard ではありません。

または

returnType は Type.IsByRef で true返される型です。

解説解説
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DynamicMethod コンストラクタ (String, Type, Type[], Module, Boolean)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

メソッド名、戻り値の型、パラメータの型、モジュール指定し、さらにモジュール内のすべての型のメンバに対して JIT (Just-In-Time) の参照範囲チェックスキップする必要があるかどうか指定してモジュールに対してグローバルな動的メソッド作成します

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    name As String, _
    returnType As Type, _
    parameterTypes As Type(), _
    m As Module, _
    skipVisibility As Boolean _
)
Dim name As String
Dim returnType As Type
Dim parameterTypes As Type()
Dim m As Module
Dim skipVisibility As Boolean

Dim instance As New DynamicMethod(name,
 returnType, parameterTypes, m, skipVisibility)
public DynamicMethod (
    string name,
    Type returnType,
    Type[] parameterTypes,
    Module m,
    bool skipVisibility
)
public:
DynamicMethod (
    String^ name, 
    Type^ returnType, 
    array<Type^>^ parameterTypes, 
    Module^ m, 
    bool skipVisibility
)
public DynamicMethod (
    String name, 
    Type returnType, 
    Type[] parameterTypes, 
    Module m, 
    boolean skipVisibility
)
public function DynamicMethod (
    name : String, 
    returnType : Type, 
    parameterTypes : Type[], 
    m : Module, 
    skipVisibility : boolean
)

パラメータ

name

動的メソッドの名前。長さ 0 の文字列でもかまいませんが、null 参照 (Visual Basic では Nothing) にはできません。

returnType

動的メソッド戻り値の型を指定する Type オブジェクトメソッド戻り値の型がない場合null 参照 (Visual Basic では Nothing)。

parameterTypes

動的メソッドパラメータの型を指定する Type オブジェクト配列メソッドパラメータない場合null 参照 (Visual Basic では Nothing)。

m

動的メソッド論理的に関連付けるモジュールを表す Module

skipVisibility

すべてのモジュール内のすべての型のメンバに対して JIT参照範囲チェックスキップする場合trueそれ以外場合false

例外例外
例外種類条件

ArgumentException

parameterTypes要素null 参照 (Visual Basic では Nothing) または Void です。

ArgumentNullException

namenull 参照 (Visual Basic では Nothing) です。

または

m null 参照 (Visual Basic では Nothing) です。

NotSupportedException

returnType は Type.IsByRef で true返される型です。

解説解説
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DynamicMethod コンストラクタ

動的メソッド作成します
オーバーロードの一覧オーバーロードの一覧

名前 説明
DynamicMethod (String, Type, Type[], Module) メソッド名、戻り値の型、パラメータの型、およびモジュール指定してモジュールに対してグローバルな動的メソッド作成します
DynamicMethod (String, Type, Type[], Type) メソッド名、戻り値の型、パラメータの型、および動的メソッド論理的に関連付ける型を指定して動的メソッド作成します
DynamicMethod (String, Type, Type[], Module, Boolean) メソッド名、戻り値の型、パラメータの型、モジュール指定し、さらにモジュール内のすべての型のメンバに対して JIT (Just-In-Time) の参照範囲チェックスキップする必要があるかどうか指定してモジュールに対してグローバルな動的メソッド作成します
DynamicMethod (String, Type, Type[], Type, Boolean) メソッド名、戻り値の型、パラメータの型、動的メソッド論理的に関連付ける型を指定し、さらにモジュール内の他の型のメンバに対して JIT (Just-In-Time) の参照範囲チェックスキップする必要があるかどうか指定して動的メソッド作成します
DynamicMethod (String, MethodAttributes, CallingConventions, Type, Type[], Module, Boolean) メソッド名、属性呼び出し規約戻り値の型、パラメータの型、モジュール指定し、さらにモジュール内のすべての型のメンバに対して JIT (Just-In-Time) の参照範囲チェックスキップする必要があるかどうか指定してモジュールに対してグローバルな動的メソッド作成します
DynamicMethod (String, MethodAttributes, CallingConventions, Type, Type[], Type, Boolean) メソッド名、属性呼び出し規約戻り値の型、パラメータの型、動的メソッド論理的に関連付ける型を指定し、さらにモジュール内の他の型のメンバに対して JIT (Just-In-Time) の参照範囲チェックスキップする必要があるかどうか指定して動的メソッド作成します
参照参照

関連項目

DynamicMethod クラス
DynamicMethod メンバ
System.Reflection.Emit 名前空間

その他の技術情報

リフレクション出力による動的メソッドシナリオ
方法 : 動的メソッドを定義および実行する

DynamicMethod コンストラクタ (String, Type, Type[], Module)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

メソッド名、戻り値の型、パラメータの型、およびモジュール指定してモジュールに対してグローバルな動的メソッド作成します

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    name As String, _
    returnType As Type, _
    parameterTypes As Type(), _
    m As Module _
)
Dim name As String
Dim returnType As Type
Dim parameterTypes As Type()
Dim m As Module

Dim instance As New DynamicMethod(name,
 returnType, parameterTypes, m)
public DynamicMethod (
    string name,
    Type returnType,
    Type[] parameterTypes,
    Module m
)
public:
DynamicMethod (
    String^ name, 
    Type^ returnType, 
    array<Type^>^ parameterTypes, 
    Module^ m
)
public DynamicMethod (
    String name, 
    Type returnType, 
    Type[] parameterTypes, 
    Module m
)
public function DynamicMethod (
    name : String, 
    returnType : Type, 
    parameterTypes : Type[], 
    m : Module
)

パラメータ

name

動的メソッドの名前。長さ 0 の文字列でもかまいませんが、null 参照 (Visual Basic では Nothing) にはできません。

returnType

動的メソッド戻り値の型を指定する Type オブジェクトメソッド戻り値の型がない場合null 参照 (Visual Basic では Nothing)。

parameterTypes

動的メソッドパラメータの型を指定する Type オブジェクト配列メソッドパラメータない場合null 参照 (Visual Basic では Nothing)。

m

動的メソッド論理的に関連付けるモジュールを表す Module

例外例外
例外種類条件

ArgumentException

parameterTypes要素null 参照 (Visual Basic では Nothing) または Void です。

ArgumentNullException

namenull 参照 (Visual Basic では Nothing) です。

または

m null 参照 (Visual Basic では Nothing) です。

NotSupportedException

returnType は Type.IsByRef で true返される型です。

解説解説
使用例使用例

2 つパラメータ使用する動的メソッド作成するコード例次に示します。この例では、コンソール1 つ目のパラメータ出力する簡単な関数本体出力し2 つ目のパラメータメソッド戻り値として使用してます。この例では、デリゲート作成することによってメソッド完了しさまざまなパラメータを持つデリゲート呼び出し最後に Invoke(Object,BindingFlags,Binder,Object[],CultureInfo) メソッド使用して動的メソッド呼び出します。

Imports System
Imports System.Reflection
Imports System.Reflection.Emit
Imports Microsoft.VisualBasic

Public Class Test
    ' Declare a delegate that will be used to execute the completed
    ' dynamic method. 
    Private Delegate Function
 HelloInvoker(ByVal msg As String,
 _
        ByVal ret As Integer)
 As Integer

    Public Shared Sub Main()
        ' Create an array that specifies the types of the parameters
        ' of the dynamic method. This method has a String parameter
        ' and an Integer parameter.
        Dim helloArgs() As Type = {GetType(String),
 GetType(Integer)}

        ' Create a dynamic method with the name "Hello", a
 return type
        ' of Integer, and two parameters whose types are specified by
        ' the array helloArgs. Create the method in the module that
        ' defines the Test class.
        Dim hello As New
 DynamicMethod("Hello", _
            GetType(Integer), _
            helloArgs, _
            GetType(Test).Module)

        ' Create an array that specifies the parameter types of the
        ' overload of Console.WriteLine to be used in Hello.
        Dim writeStringArgs() As Type = {GetType(String)}
        ' Get the overload of Console.WriteLine that has one
        ' String parameter.
        Dim writeString As MethodInfo = GetType(Console).
 _
            GetMethod("WriteLine", writeStringArgs)
 

        ' Get an ILGenerator and emit a body for the dynamic method.
        Dim il As ILGenerator = hello.GetILGenerator()
        ' Load the first argument, which is a string, onto the stack.
        il.Emit(OpCodes.Ldarg_0)
        ' Call the overload of Console.WriteLine that prints a string.
        il.EmitCall(OpCodes.Call, writeString, Nothing)
        ' The Hello method returns the value of the second argument;
        ' to do this, load the onto the stack and return.
        il.Emit(OpCodes.Ldarg_1)
        il.Emit(OpCodes.Ret)

        ' Create a delegate that represents the dynamic method. This
        ' action completes the method, and any further attempts to
        ' change the method will cause an exception.
    Dim hi As HelloInvoker = _
            hello.CreateDelegate(GetType(HelloInvoker))

        ' Use the delegate to execute the dynamic method. Save and
        ' print the return value.
        Dim retval As Integer
 = hi(vbCrLf & "Hello, World!", 42)
        Console.WriteLine("Executing delegate hi(""Hello,
 World!"", 42) returned " _
            & retval)

        ' Do it again, with different arguments.
        retval = hi(vbCrLf & "Hi, Mom!", 5280)
        Console.WriteLine("Executing delegate hi(""Hi,
 Mom!"", 5280) returned " _
            & retval)

        ' Create an array of arguments to use with the Invoke method.
        Dim invokeArgs() As Object
 = {vbCrLf & "Hello, World!", 42}
        ' Invoke the dynamic method using the arguments. This is much
        ' slower than using the delegate, because you must create an
        ' array to contain the arguments, and ValueType arguments
        ' must be boxed. Note that this overload of Invoke is 
        ' inherited from MethodBase, and simply calls the more 
        ' complete overload of Invoke.
        Dim objRet As Object
 = hello.Invoke(Nothing, invokeArgs)
        Console.WriteLine("hello.Invoke returned "
 & objRet)
    End Sub
End Class

' This code example produces the following output:
'
'Hello, World!
'Executing delegate hi("Hello, World!", 42) returned 42
'
'Hi, Mom!
'Executing delegate hi("Hi, Mom!", 5280) returned 5280
'
'Hello, World!
'hello.Invoke returned 42
'
using System;
using System.Reflection;
using System.Reflection.Emit;
using Microsoft.VisualBasic;

public class Test
{
    // Declare a delegate that will be used to execute the completed
    // dynamic method. 
    private delegate int HelloInvoker(string
 msg, int ret);

    public static void Main()
    {
        // Create an array that specifies the types of the parameters
        // of the dynamic method. This method has a string parameter
        // and an int parameter.
        Type[] helloArgs = {typeof(string), typeof(int)};

        // Create a dynamic method with the name "Hello",
 a return type
        // of int, and two parameters whose types are specified by the
        // array helloArgs. Create the method in the module that
        // defines the Test class.
        DynamicMethod hello = new DynamicMethod("Hello",
 
            typeof(int), 
            helloArgs, 
            typeof(Test).Module);

        // Create an array that specifies the parameter types of the
        // overload of Console.WriteLine to be used in Hello.
        Type[] writeStringArgs = {typeof(string)};
        // Get the overload of Console.WriteLine that has one
        // String parameter.
        MethodInfo writeString = 
            typeof(Console).GetMethod("WriteLine", writeStringArgs);

        // Get an ILGenerator and emit a body for the dynamic method.
        ILGenerator il = hello.GetILGenerator();
        // Load the first argument, which is a string, onto the stack.
        il.Emit(OpCodes.Ldarg_0);
        // Call the overload of Console.WriteLine that prints a string.
        il.EmitCall(OpCodes.Call, writeString, null);
        // The Hello method returns the value of the second argument;
        // to do this, load the onto the stack and return.
        il.Emit(OpCodes.Ldarg_1);
        il.Emit(OpCodes.Ret);

        // Create a delegate that represents the dynamic method. This
        // action completes the method, and any further attempts to
        // change the method will cause an exception.
        HelloInvoker hi = 
            (HelloInvoker) hello.CreateDelegate(typeof(HelloInvoker));

        // Use the delegate to execute the dynamic method. Save and
        // print the return value.
        int retval = hi("\r\nHello, World!", 42);
        Console.WriteLine("Executing delegate hi(\"Hello, World!\",
 42) returned {0}",
            retval);

        // Do it again, with different arguments.
        retval = hi("\r\nHi, Mom!", 5280);
        Console.WriteLine("Executing delegate hi(\"Hi, Mom!\", 5280)
 returned {0}",
            retval);
        
        // Create an array of arguments to use with the Invoke method.
        object[] invokeArgs = {"\r\nHello, World!", 42};
        // Invoke the dynamic method using the arguments. This is much
        // slower than using the delegate, because you must create an
        // array to contain the arguments, and ValueType arguments
        // must be boxed.
        object objRet = hello.Invoke(null, invokeArgs);
        Console.WriteLine("hello.Invoke returned {0}", objRet);
    }
}
using namespace System;
using namespace System::Reflection;
using namespace System::Reflection::Emit;

public ref class Test
{   
};

// Declare a delegate that will be used to execute the completed
// dynamic method.
delegate int HelloInvoker(String^ msg, int
 ret);

int main()
{
    // Create an array that specifies the types of the parameters
    // of the dynamic method. This method has a string parameter
    // and an int parameter.
    array<Type^>^ helloArgs = {String::typeid, int::typeid};

    // Create a dynamic method with the name "Hello", a return
 type
    // of int, and two parameters whose types are specified by the
    // array helloArgs. Create the method in the module that
    // defines the Test class.
    DynamicMethod^ hello = gcnew DynamicMethod("Hello", 
        int::typeid,
        helloArgs,
        Test::typeid->Module);

    // Create an array that specifies the parameter types of the
    // overload of Console.WriteLine to be used in Hello.
    array<Type^>^ writeStringArgs = {String::typeid};
    // Get the overload of Console.WriteLine that has one
    // String parameter.
    MethodInfo^ writeString =
        Console::typeid->GetMethod("WriteLine", writeStringArgs);

    // Get an ILGenerator and emit a body for the dynamic method.
    ILGenerator^ ilgen = hello->GetILGenerator();
    // Load the first argument, which is a string, onto the stack.
    ilgen->Emit(OpCodes::Ldarg_0);
    // Call the overload of Console.WriteLine that prints a string.
    ilgen->EmitCall(OpCodes::Call, writeString, nullptr);
    // The Hello method returns the value of the second argument;
    // to do this, load the onto the stack and return.
    ilgen->Emit(OpCodes::Ldarg_1);
    ilgen->Emit(OpCodes::Ret);

    // Create a delegate that represents the dynamic method. This
    // action completes the method, and any further attempts to
    // change the method will cause an exception.
    HelloInvoker^ helloDelegate =
        (HelloInvoker^) hello->CreateDelegate(HelloInvoker::typeid);

    // Use the delegate to execute the dynamic method. Save and
    // print the return value.
    int returnValue = helloDelegate("\r\nHello, World!",
 42);
    Console::WriteLine("helloDelegate(\"Hello, World!\", 42) returned
 {0}",
        returnValue);

    // Do it again, with different arguments.
    returnValue = helloDelegate("\r\nHi, Mom!", 5280);
    Console::WriteLine("helloDelegate(\"Hi, Mom!\", 5280) returned
 {0}",
        returnValue);

    // Create an array of arguments to use with the Invoke method.
    array<Object^>^ delegateArgs = {"\r\nHello, World!", 42};
    // Invoke the dynamic method using the arguments. This is much
    // slower than using the delegate, because you must create an
    // array to contain the arguments, and ValueType arguments
    // must be boxed.
    Object^ returnValueObject = hello->Invoke(nullptr, delegateArgs);
    Console::WriteLine("hello.Invoke returned {0}", returnValueObject);
}
import System.*;
import System.Reflection.*;
import System.Reflection.Emit.*;
import Microsoft.VisualBasic.*;

public class Test
{
    /** @delegate 
     */
    // Declare a delegate that will be used to execute the completed
    // dynamic method. 
    private delegate int HelloInvoker(String
 msg, int ret);

    public static void main(String[]
 args)
    {
        // Create an array that specifies the types of the parameters
        // of the dynamic method. This method has a string parameter
        // and an int parameter.
        Type helloArgs[] =  { String.class.ToType(), int.class.ToType()
 };
        // Create a dynamic method with the name "Hello",
 a return type
        // of int, and two parameters whose types are specified by the
        // array helloArgs. Create the method in the module that
        // defines the Test class.
        DynamicMethod hello = new DynamicMethod("Hello",
 int.class.ToType(),
            helloArgs, Test.class.ToType().get_Module());
        // Create an array that specifies the parameter types of the
        // overload of Console.WriteLine to be used in Hello.
        Type writeStringArgs[] = { String.class.ToType() };
        // Get the overload of Console.WriteLine that has one
        // String parameter.
        MethodInfo writeString = Console.class.ToType().GetMethod("WriteLine"
,
            writeStringArgs);
        // Get an ILGenerator and emit a body for the dynamic method.
        ILGenerator il = hello.GetILGenerator();
        // Load the first argument, which is a string, onto the stack.
        il.Emit(OpCodes.Ldarg_0);
        // Call the overload of Console.WriteLine that prints a string.
        il.EmitCall(OpCodes.Call, writeString, null);
        // The Hello method returns the value of the second argument;
        // to do this, load the onto the stack and return.
        il.Emit(OpCodes.Ldarg_1);
        il.Emit(OpCodes.Ret);

        // Create a delegate that represents the dynamic method. This
        // action completes the method, and any further attempts to
        // change the method will cause an exception.
        HelloInvoker hi = (HelloInvoker)(hello.CreateDelegate(
            HelloInvoker.class.ToType()));

        // Use the delegate to execute the dynamic method. Save and
        // print the return value.
        int retval = hi.Invoke("\r\nHello, World!",
 42);
        Console.WriteLine("Invoking delegate hi(\"Hello, World!\",
 42) returned {0}",
            System.Convert.ToString(retval));

        // Do it again, with different arguments.
        retval = hi.Invoke("\r\nHi, Mom!", 5280);
        Console.WriteLine("Invoking delegate hi(\"Hi, Mom!\", 5280)
 returned {0}",
            System.Convert.ToString(retval));

        // Create an array of arguments to use with the Invoke method.
        Object invokeArgs[] =  { "\r\nHello, World!", (System.Int32)42
 };
        // Invoke the dynamic method using the arguments. This is much
        // slower than using the delegate, because you must create an
        // array to contain the arguments, and ValueType arguments
        // must be boxed.
        Object objRet = hello.Invoke(null, invokeArgs);
        Console.WriteLine("hello.Invoke returned {0}", objRet);
    } //main 
} //Test
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DynamicMethod コンストラクタ (String, Type, Type[], Type, Boolean)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

メソッド名、戻り値の型、パラメータの型、動的メソッド論理的に関連付ける型を指定し、さらにモジュール内の他の型のメンバに対して JIT (Just-In-Time) の参照範囲チェックスキップする必要があるかどうか指定して動的メソッド作成します

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    name As String, _
    returnType As Type, _
    parameterTypes As Type(), _
    owner As Type, _
    skipVisibility As Boolean _
)
Dim name As String
Dim returnType As Type
Dim parameterTypes As Type()
Dim owner As Type
Dim skipVisibility As Boolean

Dim instance As New DynamicMethod(name,
 returnType, parameterTypes, owner, skipVisibility)
public DynamicMethod (
    string name,
    Type returnType,
    Type[] parameterTypes,
    Type owner,
    bool skipVisibility
)
public:
DynamicMethod (
    String^ name, 
    Type^ returnType, 
    array<Type^>^ parameterTypes, 
    Type^ owner, 
    bool skipVisibility
)
public DynamicMethod (
    String name, 
    Type returnType, 
    Type[] parameterTypes, 
    Type owner, 
    boolean skipVisibility
)
public function DynamicMethod (
    name : String, 
    returnType : Type, 
    parameterTypes : Type[], 
    owner : Type, 
    skipVisibility : boolean
)

パラメータ

name

動的メソッドの名前。長さ 0 の文字列でもかまいませんが、null 参照 (Visual Basic では Nothing) にはできません。

returnType

動的メソッド戻り値の型を指定する Type オブジェクトメソッド戻り値の型がない場合null 参照 (Visual Basic では Nothing)。

parameterTypes

動的メソッドパラメータの型を指定する Type オブジェクト配列メソッドパラメータない場合null 参照 (Visual Basic では Nothing)。

owner

動的メソッド論理的に関連付ける Type動的メソッドはこの型のすべてのメンバアクセスできます

skipVisibility

すべてのモジュール内のすべての型のすべてのメンバに対して JIT参照範囲チェックスキップする場合trueそれ以外場合false

例外例外
例外種類条件

ArgumentException

parameterTypes要素null 参照 (Visual Basic では Nothing) または Void です。

または

ownerインターフェイス配列オープン ジェネリック型いずれか、あるいはジェネリック型またはジェネリック メソッド型パラメータです。

ArgumentNullException

namenull 参照 (Visual Basic では Nothing) です。

または

owner null 参照 (Visual Basic では Nothing) です。

NotSupportedException

returnTypenull 参照 (Visual Basic では Nothing) であるか、IsByRef で true返される型です。

解説解説
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DynamicMethod コンストラクタ (String, Type, Type[], Type)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

メソッド名、戻り値の型、パラメータの型、および動的メソッド論理的に関連付ける型を指定して動的メソッド作成します

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub New ( _
    name As String, _
    returnType As Type, _
    parameterTypes As Type(), _
    owner As Type _
)
Dim name As String
Dim returnType As Type
Dim parameterTypes As Type()
Dim owner As Type

Dim instance As New DynamicMethod(name,
 returnType, parameterTypes, owner)
public DynamicMethod (
    string name,
    Type returnType,
    Type[] parameterTypes,
    Type owner
)
public:
DynamicMethod (
    String^ name, 
    Type^ returnType, 
    array<Type^>^ parameterTypes, 
    Type^ owner
)
public DynamicMethod (
    String name, 
    Type returnType, 
    Type[] parameterTypes, 
    Type owner
)
public function DynamicMethod (
    name : String, 
    returnType : Type, 
    parameterTypes : Type[], 
    owner : Type
)

パラメータ

name

動的メソッドの名前。長さ 0 の文字列でもかまいませんが、null 参照 (Visual Basic では Nothing) にはできません。

returnType

動的メソッド戻り値の型を指定する Type オブジェクトメソッド戻り値の型がない場合null 参照 (Visual Basic では Nothing)。

parameterTypes

動的メソッドパラメータの型を指定する Type オブジェクト配列メソッドパラメータない場合null 参照 (Visual Basic では Nothing)。

owner

動的メソッド論理的に関連付ける Type動的メソッドはこの型のすべてのメンバアクセスできます

例外例外
例外種類条件

ArgumentException

parameterTypes要素null 参照 (Visual Basic では Nothing) または Void です。

または

ownerインターフェイス配列オープン ジェネリック型いずれか、あるいはジェネリック型またはジェネリック メソッド型パラメータです。

ArgumentNullException

namenull 参照 (Visual Basic では Nothing) です。

または

owner null 参照 (Visual Basic では Nothing) です。

NotSupportedException

returnTypenull 参照 (Visual Basic では Nothing) であるか、IsByRef で true返される型です。

解説解説
使用例使用例

型に論理的に関連付けられた DynamicMethod を作成し、その型のプライベート メンバアクセスできるようにするコード例次に示します

このコード例では、プライベート フィールドを持つ Example という名前のクラス、この最初クラスから派生した DerivedFromxample という名前のクラス、Int32 を返しExample 型と Int32 型のパラメータを持つ UseLikeStatic というデリゲート型、および Int32返しInt32 型のパラメータ1 つ持つ UseLikeInstance という名前のデリゲート型定義します

次にExampleインスタンスプライベート フィールド変更し以前の値を返す DynamicMethod作成します

メモメモ

通常クラス内部フィールド変更することは、オブジェクト指向適切なコーディング作業ではありません。

この例のコードでは、Exampleインスタンス作成した後、2 つデリゲート作成してます。1 つ目は、動的メソッドと同じパラメータを持つ UseLikeStatic 型のデリゲートです。2 つ目は、1 つ目のパラメータ (Example 型) のない UseLikeInstance 型のデリゲートです。このデリゲートは、CreateDelegate(Type,Object) メソッド オーバーロード使用して作成されます。このメソッド オーバーロード2 つ目のパラメータExampleインスタンスです。この場合インスタンス作成するだけで新しく作成されデリゲートバインドされます。このデリゲート呼び出すたびに、動的メソッドExampleバインドされたインスタンスに対して機能します

UseLikeStatic デリゲート呼び出されUseLikeInstance デリゲートバインドされた Exampleインスタンス渡されます。次にUseLikeInstance デリゲート呼び出され、この 2 つデリゲートExample の同じインスタンスに対して機能します内部フィールドの値の変更は、各呼び出しの後に表示されます。最後にUseLikeInstance デリゲートDerivedFromxampleインスタンスバインドされ、デリゲート呼び出し繰り返されます。

Imports System
Imports System.Reflection
Imports System.Reflection.Emit

' These classes are for demonstration purposes.
'
Public Class Example
    Private _id As Integer
 = 0
    
    Public Sub New(ByVal
 newId As Integer) 
        _id = newId    
    End Sub
    
    Public ReadOnly Property
 ID() As Integer 
        Get
            Return _id
        End Get
    End Property 
End Class

Public Class DerivedFromExample
    Inherits Example
    
    Public Sub New(ByVal
 newId As Integer) 
        MyBase.New(newId)
    End Sub
End Class
 
' Two delegates are declared: UseLikeInstance treats the dynamic
' method as if it were an instance method, and UseLikeStatic
' treats the dynamic method in the ordinary fashion.
' 
Public Delegate Function
 UseLikeInstance(ByVal newID As Integer)
 _
    As Integer 
Public Delegate Function
 UseLikeStatic(ByVal ex As Example, _
    ByVal newID As Integer)
 As Integer 

Public Class Demo
    
    Public Shared Sub Main()
 
        ' This dynamic method changes the private _id field. It 
        ' has no name; it returns the old _id value (return type 
        ' Integer); it takes two parameters, an instance of Example
 
        ' and an Integer that is the new value of _id; and it is 
        ' declared with Example as the owner type, so it can 
        ' access all members, public and private.
        '
        Dim changeID As New
 DynamicMethod( _
            "", _
            GetType(Integer), _
            New Type() {GetType(Example), GetType(Integer)},
 _
            GetType(Example) _
        )
        
        ' Get a FieldInfo for the private field '_id'.
        Dim fid As FieldInfo = GetType(Example).GetField(
 _
            "_id", _
            BindingFlags.NonPublic Or BindingFlags.Instance _
        )
        
        Dim ilg As ILGenerator = changeID.GetILGenerator()
        
        ' Push the current value of the id field onto the 
        ' evaluation stack. It's an instance field, so load the
        ' instance of Example before accessing the field.
        ilg.Emit(OpCodes.Ldarg_0)
        ilg.Emit(OpCodes.Ldfld, fid)
        
        ' Load the instance of Example again, load the new value 
        ' of id, and store the new field value. 
        ilg.Emit(OpCodes.Ldarg_0)
        ilg.Emit(OpCodes.Ldarg_1)
        ilg.Emit(OpCodes.Stfld, fid)
        
        ' The original value of the id field is now the only 
        ' thing on the stack, so return from the call.
        ilg.Emit(OpCodes.Ret)
        
        
        ' Create a delegate that uses changeID in the ordinary
        ' way, as a static method that takes an instance of
        ' Example and an Integer.
        '
        Dim uls As UseLikeStatic = CType( _
            changeID.CreateDelegate(GetType(UseLikeStatic)), _
            UseLikeStatic _
        )
        
        ' Create an instance of Example with an id of 42.
        '
        Dim ex As New Example(42)
        
        ' Create a delegate that is bound to the instance of 
        ' of Example. This is possible because the first 
        ' parameter of changeID is of type Example. The 
        ' delegate has all the parameters of changeID except
        ' the first.
        Dim uli As UseLikeInstance = CType(
 _
            changeID.CreateDelegate( _
                GetType(UseLikeInstance), _
                ex), _
            UseLikeInstance _
        )
        
        ' First, change the value of _id by calling changeID as
        ' a static method, passing in the instance of Example.
        '
        Console.WriteLine( _
            "Change the value of _id; previous value: {0}",
 _
            uls(ex, 1492) _
        )
        
        ' Change the value of _id again using the delegate 
        ' bound to the instance of Example.
        '
        Console.WriteLine( _
            "Change the value of _id; previous value: {0}",
 _
            uli(2700) _
        )
        
        Console.WriteLine("Final value of _id: {0}",
 ex.ID)
    

        ' Now repeat the process with a class that derives
        ' from Example.
        '
        Dim dfex As New
 DerivedFromExample(71)

        uli = CType( _
            changeID.CreateDelegate( _
                GetType(UseLikeInstance), _
                dfex), _
            UseLikeInstance _
        )

        Console.WriteLine( _
            "Change the value of _id; previous value: {0}",
 _
            uls(dfex, 73) _
        )
        Console.WriteLine( _
            "Change the value of _id; previous value: {0}",
 _
            uli(79) _
        )
        Console.WriteLine("Final value of _id: {0}",
 dfex.ID)

    End Sub
End Class

' This code example produces the following output:
'
'Change the value of _id; previous value: 42
'Change the value of _id; previous value: 1492
'Final value of _id: 2700
'Change the value of _id; previous value: 71
'Change the value of _id; previous value: 73
'Final value of _id: 79' 
using System;
using System.Reflection;
using System.Reflection.Emit;

// These classes are for demonstration purposes.
//
public class Example
{
    private int id = 0;
    public Example(int id)
    {
        this.id = id;
    }
    public int ID { get
 { return id; }}
}

public class DerivedFromExample : Example
{
    public DerivedFromExample(int id) : base(id)
 {} 
}

// Two delegates are declared: UseLikeInstance treats the dynamic
// method as if it were an instance method, and UseLikeStatic
// treats the dynamic method in the ordinary fashion.
// 
public delegate int UseLikeInstance(int
 newID);
public delegate int UseLikeStatic(Example ex,
 int newID);

public class Demo
{
    public static void Main()
    {
        // This dynamic method changes the private id field. It has
        // no name; it returns the old id value (return type int);
        // it takes two parameters, an instance of Example and 
        // an int that is the new value of id; and it is declared 
        // with Example as the owner type, so it can access all 
        // members, public and private.
        //
        DynamicMethod changeID = new DynamicMethod(
            "",
            typeof(int),
            new Type[] { typeof(Example), typeof(int)
 },
            typeof(Example)
        );

        // Get a FieldInfo for the private field 'id'.
        FieldInfo fid = typeof(Example).GetField(
            "id",
            BindingFlags.NonPublic | BindingFlags.Instance
        );
    
        ILGenerator ilg = changeID.GetILGenerator();

        // Push the current value of the id field onto the 
        // evaluation stack. It's an instance field, so load the
        // instance of Example before accessing the field.
        ilg.Emit(OpCodes.Ldarg_0);
        ilg.Emit(OpCodes.Ldfld, fid);

        // Load the instance of Example again, load the new value 
        // of id, and store the new field value. 
        ilg.Emit(OpCodes.Ldarg_0);
        ilg.Emit(OpCodes.Ldarg_1);
        ilg.Emit(OpCodes.Stfld, fid);

        // The original value of the id field is now the only 
        // thing on the stack, so return from the call.
        ilg.Emit(OpCodes.Ret);


        // Create a delegate that uses changeID in the ordinary
        // way, as a static method that takes an instance of
        // Example and an int.
        //
        UseLikeStatic uls = 
            (UseLikeStatic) changeID.CreateDelegate(
                typeof(UseLikeStatic)
            );

        // Create an instance of Example with an id of 42.
        //
        Example ex = new Example(42);

        // Create a delegate that is bound to the instance of 
        // of Example. This is possible because the first 
        // parameter of changeID is of type Example. The 
        // delegate has all the parameters of changeID except
        // the first.
        UseLikeInstance uli = 
            (UseLikeInstance) changeID.CreateDelegate(
                typeof(UseLikeInstance),
                ex
            );

        // First, change the value of id by calling changeID as
        // a static method, passing in the instance of Example.
        //
        Console.WriteLine(
            "Change the value of id; previous value: {0}",
            uls(ex, 1492)
        );

        // Change the value of id again using the delegate bound
        // to the instance of Example.
        //
        Console.WriteLine(
            "Change the value of id; previous value: {0}",
            uli(2700)
        );

        Console.WriteLine("Final value of id: {0}", ex.ID);


        // Now repeat the process with a class that derives
        // from Example.
        //
        DerivedFromExample dfex = new DerivedFromExample(71);

        uli = (UseLikeInstance) changeID.CreateDelegate(
                typeof(UseLikeInstance),
                dfex
            );

        Console.WriteLine(
            "Change the value of id; previous value: {0}",
            uls(dfex, 73)
        );
        Console.WriteLine(
            "Change the value of id; previous value: {0}",
            uli(79)
        );
        Console.WriteLine("Final value of id: {0}", dfex.ID);
    }
}

/* This code example produces the following output:

Change the value of id; previous value: 42
Change the value of id; previous value: 1492
Final value of id: 2700
Change the value of id; previous value: 71
Change the value of id; previous value: 73
Final value of id: 79
 */
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DynamicMethod プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ Attributes オーバーライドされます動的メソッド作成時に指定した属性取得します
パブリック プロパティ CallingConvention オーバーライドされます動的メソッド作成時に指定した呼び出し規約取得します
パブリック プロパティ ContainsGenericParameters  ジェネリック メソッドに未割り当てジェネリック型パラメータ含まれているかどうかを示す値を取得します。 ( MethodInfo から継承されます。)
パブリック プロパティ DeclaringType オーバーライドされます動的メソッドに対して常に null 参照 (Visual Basic では Nothing) である、メソッド宣言する型を取得します
パブリック プロパティ InitLocals メソッドローカル変数を 0 で初期化するかどうかを示す値を取得または設定します
パブリック プロパティ IsAbstract  メソッド抽象メソッドかどうかを示す値を取得します。 ( MethodBase から継承されます。)
パブリック プロパティ IsAssembly  同じアセンブリ異なクラスからこのメソッド呼び出すことができるかどうかを示す値を取得します。 ( MethodBase から継承されます。)
パブリック プロパティ IsConstructor  メソッドコンストラクタかどうかを示す値を取得します。 ( MethodBase から継承されます。)
パブリック プロパティ IsFamily  このメソッドへのアクセスクラスメンバ派生クラスメンバ制限されているかどうかを示す値を取得します。 ( MethodBase から継承されます。)
パブリック プロパティ IsFamilyAndAssembly  同じアセンブリ派生クラスからこのメソッド呼び出すことができるかどうかを示す値を取得します。 ( MethodBase から継承されます。)
パブリック プロパティ IsFamilyOrAssembly  すべての派生クラスおよび同じアセンブリすべてのクラスからこのメソッド呼び出すことができるかどうかを示す値を取得します。 ( MethodBase から継承されます。)
パブリック プロパティ IsFinal  このメソッドfinal かどうかを示す値を取得します。 ( MethodBase から継承されます。)
パブリック プロパティ IsGenericMethod  現在のメソッドジェネリック メソッドかどうかを示す値を取得します。 ( MethodInfo から継承されます。)
パブリック プロパティ IsGenericMethodDefinition  現在の MethodInfo がジェネリック メソッドの定義を表しているかどうかを示す値を取得します。 ( MethodInfo から継承されます。)
パブリック プロパティ IsHideBySig  派生クラスで、正確に同じシグネチャを持つ同じ種類メンバだけが隠しメンバになるかどうかを示す値を取得します。 ( MethodBase から継承されます。)
パブリック プロパティ IsPrivate  このメンバプライベートかどうかを示す値を取得します。 ( MethodBase から継承されます。)
パブリック プロパティ IsPublic  パブリック メソッドかどうかを示す値を取得します。 ( MethodBase から継承されます。)
パブリック プロパティ IsSpecialName  特別な名前のメソッドかどうかを示す値を取得します。 ( MethodBase から継承されます。)
パブリック プロパティ IsStatic  メソッドstatic かどうかを示す値を取得します。 ( MethodBase から継承されます。)
パブリック プロパティ IsVirtual  メソッドvirtual かどうかを示す値を取得します。 ( MethodBase から継承されます。)
パブリック プロパティ MemberType  このメンバメソッドであることを示す MemberTypes 値を取得します。 ( MethodInfo から継承されます。)
パブリック プロパティ MetadataToken  メタデータ要素識別する値を取得します。 ( MemberInfo から継承されます。)
パブリック プロパティ MethodHandle オーバーライドされます動的メソッドではサポートされていません。
パブリック プロパティ Module オーバーライドされます動的メソッド論理的に関連付けるモジュール取得します
パブリック プロパティ Name オーバーライドされます動的メソッドの名前を取得します
パブリック プロパティ ReflectedType オーバーライドされますメソッド取得するためにリフレクション使用したクラス取得します
パブリック プロパティ ReturnParameter オーバーライドされます動的メソッド返されるパラメータ取得します
パブリック プロパティ ReturnType オーバーライドされます動的メソッド戻り値の型を取得します
パブリック プロパティ ReturnTypeCustomAttributes オーバーライドされます動的メソッド戻り値の型のカスタム属性取得します
参照参照

関連項目

DynamicMethod クラス
System.Reflection.Emit 名前空間

その他の技術情報

リフレクション出力による動的メソッドシナリオ
方法 : 動的メソッドを定義および実行する

DynamicMethod メソッド


パブリック メソッドパブリック メソッド

  名前 説明
パブリック メソッド CreateDelegate オーバーロードされます動的メソッド完了しメソッド実行使用できるデリゲート作成します
パブリック メソッド DefineParameter 動的メソッドパラメータ定義します
パブリック メソッド Equals  オーバーロードされます2 つObject インスタンス等しかどうか判断します。 ( Object から継承されます。)
パブリック メソッド GetBaseDefinition オーバーライドされますメソッド基本実装返します
パブリック メソッド GetCurrentMethod  現在実行中のメソッドを表す MethodBase オブジェクト返します。 ( MethodBase から継承されます。)
パブリック メソッド GetCustomAttributes オーバーロードされますオーバーライドされますメソッド適用されカスタム属性返します
パブリック メソッド GetDynamicILInfo メタデータ トークンスコープ、および MSIL (Microsoft Intermediate Language) ストリームからメソッド本体生成する際に使用できる DynamicILInfo オブジェクト返します
パブリック メソッド GetGenericArguments  ジェネリック メソッド型引数またはジェネリック メソッド定義の型パラメータを表す Type オブジェクト配列返します。 ( MethodInfo から継承されます。)
パブリック メソッド GetGenericMethodDefinition  現在のメソッド構築する元になるジェネリック メソッド定義を表す MethodInfo オブジェクト返します。 ( MethodInfo から継承されます。)
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用適してます。 ( Object から継承されます。)
パブリック メソッド GetILGenerator オーバーロードされます動的メソッド本体出力する際に使用できる MSIL ジェネレータ返します
パブリック メソッド GetMethodBody  派生クラスオーバーライドされると、現在のメソッドMSIL ストリームローカル変数、および例外アクセスできるようにする MethodBody オブジェクト取得します。 ( MethodBase から継承されます。)
パブリック メソッド GetMethodFromHandle  オーバーロードされます指定したハンドル使用してメソッド情報取得します。 ( MethodBase から継承されます。)
パブリック メソッド GetMethodImplementationFlags オーバーライドされますメソッド実装フラグ返します
パブリック メソッド GetParameters オーバーライドされます動的メソッドパラメータ返します
パブリック メソッド GetType  現在のインスタンスType取得します。 ( Object から継承されます。)
パブリック メソッド Invoke オーバーロードされます動的メソッド呼び出します。
パブリック メソッド IsDefined オーバーライドされます指定したカスタム属性の型が定義されているかどうか示します
パブリック メソッド MakeGenericMethod  型の配列要素現在のジェネリック メソッド定義の型パラメータ置き換え結果構築メソッドを表す MethodInfo オブジェクト返します。 ( MethodInfo から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 ( Object から継承されます。)
パブリック メソッド ToString オーバーライドされます文字列として表されメソッドシグネチャ返します
参照参照

関連項目

DynamicMethod クラス
System.Reflection.Emit 名前空間

その他の技術情報

リフレクション出力による動的メソッドシナリオ
方法 : 動的メソッドを定義および実行する

DynamicMethod メンバ

動的メソッドを定義および表現します。このクラス継承できません。

DynamicMethod データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ Attributes オーバーライドされます動的メソッド作成時に指定した属性取得します
パブリック プロパティ CallingConvention オーバーライドされます動的メソッド作成時に指定した呼び出し規約取得します
パブリック プロパティ ContainsGenericParameters  ジェネリック メソッドに未割り当てジェネリック型パラメータ含まれているかどうかを示す値を取得します。(MethodInfo から継承されます。)
パブリック プロパティ DeclaringType オーバーライドされます動的メソッドに対して常に null 参照 (Visual Basic では Nothing) である、メソッド宣言する型を取得します
パブリック プロパティ InitLocals メソッドローカル変数を 0 で初期化するかどうかを示す値を取得または設定します
パブリック プロパティ IsAbstract  メソッド抽象メソッドかどうかを示す値を取得します。(MethodBase から継承されます。)
パブリック プロパティ IsAssembly  同じアセンブリ異なクラスからこのメソッド呼び出すことができるかどうかを示す値を取得します。(MethodBase から継承されます。)
パブリック プロパティ IsConstructor  メソッドコンストラクタかどうかを示す値を取得します。(MethodBase から継承されます。)
パブリック プロパティ IsFamily  このメソッドへのアクセスクラスメンバ派生クラスメンバ制限されているかどうかを示す値を取得します。(MethodBase から継承されます。)
パブリック プロパティ IsFamilyAndAssembly  同じアセンブリ派生クラスからこのメソッド呼び出すことができるかどうかを示す値を取得します。(MethodBase から継承されます。)
パブリック プロパティ IsFamilyOrAssembly  すべての派生クラスおよび同じアセンブリすべてのクラスからこのメソッド呼び出すことができるかどうかを示す値を取得します。(MethodBase から継承されます。)
パブリック プロパティ IsFinal  このメソッドfinal かどうかを示す値を取得します。(MethodBase から継承されます。)
パブリック プロパティ IsGenericMethod  現在のメソッドジェネリック メソッドかどうかを示す値を取得します。(MethodInfo から継承されます。)
パブリック プロパティ IsGenericMethodDefinition  現在の MethodInfoジェネリック メソッドの定義を表しているかどうかを示す値を取得します。(MethodInfo から継承されます。)
パブリック プロパティ IsHideBySig  派生クラスで、正確に同じシグネチャを持つ同じ種類メンバだけが隠しメンバになるかどうかを示す値を取得します。(MethodBase から継承されます。)
パブリック プロパティ IsPrivate  このメンバプライベートかどうかを示す値を取得します。(MethodBase から継承されます。)
パブリック プロパティ IsPublic  パブリック メソッドかどうかを示す値を取得します。(MethodBase から継承されます。)
パブリック プロパティ IsSpecialName  特別な名前のメソッドかどうかを示す値を取得します。(MethodBase から継承されます。)
パブリック プロパティ IsStatic  メソッドstatic かどうかを示す値を取得します。(MethodBase から継承されます。)
パブリック プロパティ IsVirtual  メソッドvirtual かどうかを示す値を取得します。(MethodBase から継承されます。)
パブリック プロパティ MemberType  このメンバメソッドであることを示す MemberTypes 値を取得します。(MethodInfo から継承されます。)
パブリック プロパティ MetadataToken  メタデータ要素識別する値を取得します。(MemberInfo から継承されます。)
パブリック プロパティ MethodHandle オーバーライドされます動的メソッドではサポートされていません。
パブリック プロパティ Module オーバーライドされます動的メソッド論理的に関連付けるモジュール取得します
パブリック プロパティ Name オーバーライドされます動的メソッドの名前を取得します
パブリック プロパティ ReflectedType オーバーライドされますメソッド取得するためにリフレクション使用したクラス取得します
パブリック プロパティ ReturnParameter オーバーライドされます動的メソッド返されるパラメータ取得します
パブリック プロパティ ReturnType オーバーライドされます動的メソッド戻り値の型を取得します
パブリック プロパティ ReturnTypeCustomAttributes オーバーライドされます動的メソッド戻り値の型のカスタム属性取得します
パブリック メソッドパブリック メソッド
  名前 説明
パブリック メソッド CreateDelegate オーバーロードされます動的メソッド完了しメソッド実行使用できるデリゲート作成します
パブリック メソッド DefineParameter 動的メソッドパラメータ定義します
パブリック メソッド Equals  オーバーロードされます2 つObject インスタンス等しかどうか判断します。 (Object から継承されます。)
パブリック メソッド GetBaseDefinition オーバーライドされますメソッド基本実装返します
パブリック メソッド GetCurrentMethod  現在実行中のメソッドを表す MethodBase オブジェクト返します。 (MethodBase から継承されます。)
パブリック メソッド GetCustomAttributes オーバーロードされますオーバーライドされますメソッド適用されカスタム属性返します
パブリック メソッド GetDynamicILInfo メタデータ トークンスコープ、および MSIL (Microsoft Intermediate Language) ストリームからメソッド本体生成する際に使用できる DynamicILInfo オブジェクト返します
パブリック メソッド GetGenericArguments  ジェネリック メソッド型引数またはジェネリック メソッド定義の型パラメータを表す Type オブジェクト配列返します。 (MethodInfo から継承されます。)
パブリック メソッド GetGenericMethodDefinition  現在のメソッド構築する元になるジェネリック メソッド定義を表す MethodInfo オブジェクト返します。 (MethodInfo から継承されます。)
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用適してます。 (Object から継承されます。)
パブリック メソッド GetILGenerator オーバーロードされます動的メソッド本体出力する際に使用できる MSIL ジェネレータ返します
パブリック メソッド GetMethodBody  派生クラスオーバーライドされると、現在のメソッドMSIL ストリームローカル変数、および例外アクセスできるようにする MethodBody オブジェクト取得します。 (MethodBase から継承されます。)
パブリック メソッド GetMethodFromHandle  オーバーロードされます指定したハンドル使用してメソッド情報取得します。 (MethodBase から継承されます。)
パブリック メソッド GetMethodImplementationFlags オーバーライドされますメソッド実装フラグ返します
パブリック メソッド GetParameters オーバーライドされます動的メソッドパラメータ返します
パブリック メソッド GetType  現在のインスタンスType取得します。 (Object から継承されます。)
パブリック メソッド Invoke オーバーロードされます動的メソッド呼び出します。
パブリック メソッド IsDefined オーバーライドされます指定したカスタム属性の型が定義されているかどうか示します
パブリック メソッド MakeGenericMethod  型の配列要素現在のジェネリック メソッド定義の型パラメータ置き換え結果構築メソッドを表す MethodInfo オブジェクト返します。 (MethodInfo から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 (Object から継承されます。)
パブリック メソッド ToString オーバーライドされます文字列として表されメソッドシグネチャ返します
参照参照

関連項目

DynamicMethod クラス
System.Reflection.Emit 名前空間

その他の技術情報

リフレクション出力による動的メソッドシナリオ
方法 : 動的メソッドを定義および実行する



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「DynamicMethod」の関連用語

DynamicMethodのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DynamicMethodのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS