DynamicMethod クラス

定義

コンパイル、実行、および破棄できる動的メソッドを定義して表します。 破棄されたメソッドは、ガベージ コレクションで使用できます。

public ref class DynamicMethod sealed : System::Reflection::MethodInfo
public sealed class DynamicMethod : System.Reflection.MethodInfo
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class DynamicMethod : System.Reflection.MethodInfo
type DynamicMethod = class
    inherit MethodInfo
[<System.Runtime.InteropServices.ComVisible(true)>]
type DynamicMethod = class
    inherit MethodInfo
Public NotInheritable Class DynamicMethod
Inherits MethodInfo
継承
属性

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

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);

        // 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.
        hello.DefineParameter(1, ParameterAttributes.In, "message");
        hello.DefineParameter(2, ParameterAttributes.In, "valueToReturn");

        // Create a delegate that represents the dynamic method. This
        // action completes the method. Any further attempts to
        // change the method are ignored.
        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);

        Console.WriteLine("\r\n ----- Display information about the dynamic method -----");
        // 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());

        // 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);
        }
    }
}

/* This code example produces the following output:

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

 ----- Display information about the dynamic method -----

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
 */
Imports System.Reflection
Imports System.Reflection.Emit
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)

        ' 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.
        hello.DefineParameter(1, ParameterAttributes.In, "message")
        hello.DefineParameter(2, ParameterAttributes.In, "valueToReturn")

        ' Create a delegate that represents the dynamic method. This
        ' action completes the method. Any further attempts to
        ' change the method are ignored.
    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)

        Console.WriteLine(vbCrLf & _
            " ----- Display information about the dynamic method -----")
        ' 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())

        ' 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
    End Sub
End Class

' This code example produces the following output:
'
'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
'
' ----- Display information about the dynamic method -----
'
'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

注釈

DynamicMethod クラスを使用すると、動的アセンブリと動的な型を生成してメソッドを格納することなく、実行時にメソッドを生成および実行できます。 Just-In-Time (JIT) コンパイラによって作成された実行可能コードは、 DynamicMethod オブジェクトが再利用されるときに再利用されます。 動的メソッドは、少量のコードを生成して実行する最も効率的な方法です。

動的メソッドは、匿名でホストすることも、モジュールまたは型に論理的に関連付けることもできます。

  • 動的メソッドが匿名でホストされている場合、動的メソッドはシステム提供のアセンブリに配置されるため、他のコードから分離されます。 既定では、パブリックではないデータにはアクセスできません。 匿名でホストされる動的メソッドには、JIT コンパイラの可視性チェックをスキップする機能が制限されている場合があります (ReflectionPermission フラグを使用してReflectionPermissionFlag.RestrictedMemberAccessが許可されている場合)。 動的メソッドによって非パブリック メンバーがアクセスされるアセンブリの信頼レベルは、動的メソッドを生成した呼び出し履歴の信頼レベルと等しいか、そのサブセットである必要があります。 匿名でホストされる動的メソッドの詳細については、「 チュートリアル: 部分信頼シナリオでのコードの出力」を参照してください。

  • 動的メソッドが指定したモジュールに関連付けられている場合、動的メソッドは実質的にそのモジュールに対してグローバルになります。 モジュール内のすべての型と、その型のすべての internal (Visual Basic のFriend ) メンバーにアクセスできます。 コードを含むコールスタックで ReflectionPermission フラグが設定された RestrictedMemberAccess の要求を満たすことができる場合、動的メソッドはモジュールを作成したかどうかに関係なく、任意のモジュールに関連付けることができます。 ReflectionPermissionFlag.MemberAccess フラグが許可に含まれている場合、動的メソッドは JIT コンパイラの可視性チェックをスキップし、モジュールまたは任意のアセンブリ内の他のモジュールで宣言されているすべての型のプライベート データにアクセスできます。

    Note

    動的メソッドが関連付けられているモジュールを指定する場合、そのモジュールは、匿名ホスティングに使用されるシステム提供のアセンブリに含まれてはなりません。

  • 動的メソッドが指定した型に関連付けられている場合は、アクセス レベルに関係なく、その型のすべてのメンバーにアクセスできます。 さらに、JIT 可視性チェックはスキップできます。 これにより、動的メソッドは、同じモジュールまたは任意のアセンブリ内の他のモジュールで宣言されている他の型のプライベート データにアクセスできます。 動的メソッドは任意の型に関連付けることができますが、コードにはReflectionPermissionフラグとRestrictedMemberAccess フラグの両方でMemberAccessを付与する必要があります。

次の表は、ReflectionPermission フラグを持つRestrictedMemberAccessが許可されているかどうかに応じて、JIT 可視性チェックの有無に応じて、匿名でホストされる動的メソッドからアクセスできる型とメンバーを示しています。

可視性チェック RestrictedMemberAccess なし RestrictedMemberAccessと共に
JIT 可視性チェックをスキップしない 任意のアセンブリ内のパブリック型のパブリック メンバー。 任意のアセンブリ内のパブリック型のパブリック メンバー。
制限付きの JIT 可視性チェックのスキップ 任意のアセンブリ内のパブリック型のパブリック メンバー。 信頼レベルが、動的メソッドを生成したアセンブリの信頼レベルと同等かそれ以下であるアセンブリ内の、すべての型のすべてのメンバー。

次の表は、モジュールまたはモジュール内の型に関連付けられている動的メソッドからアクセスできる型とメンバーを示しています。

JIT 可視性チェックをスキップする モジュールに関連付けられている 型に関連付けられている
いいえ モジュール内のパブリック型、内部型、およびプライベート型のパブリック メンバーと内部メンバー。

任意のアセンブリ内のパブリック型のパブリック メンバー。
関連付けられている型のすべてのメンバー。 モジュール内の他のすべての型のパブリック メンバーと内部メンバー。

任意のアセンブリ内のパブリック型のパブリック メンバー。
イエス あらゆるアセンブリ内のすべての型のすべてのメンバー。 あらゆるアセンブリ内のすべての型のすべてのメンバー。

モジュールに関連付けられている動的メソッドには、そのモジュールのアクセス許可があります。 型に関連付けられている動的メソッドには、その型を含むモジュールのアクセス許可があります。

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

動的メソッドは static メソッド (Visual Basic では Shared メソッド) ですが、デリゲート バインドの緩やかな規則により、動的メソッドをオブジェクトにバインドできるため、そのデリゲート インスタンスを使用して呼び出されたときにインスタンス メソッドのように動作します。 これを示す例は、 CreateDelegate(Type, Object) メソッドのオーバーロードに対して提供されます。

検証

次の一覧は、動的メソッドに検証不可能なコードを含めることができる条件をまとめたものです。 (たとえば、動的メソッドは、 InitLocals プロパティが false に設定されている場合は検証できません)。

  • セキュリティ クリティカルなアセンブリに関連付けられている動的メソッドもセキュリティ クリティカルであり、検証をスキップできます。 たとえば、デスクトップ アプリケーションとして実行されるセキュリティ属性のないアセンブリは、ランタイムによってセキュリティ クリティカルとして扱われます。 動的メソッドをアセンブリに関連付ける場合、動的メソッドには検証不可能なコードを含めることができます。
  • 検証できないコードを含む動的メソッドがレベル 1 の透過性を持つアセンブリに関連付けられている場合、Just-In-Time (JIT) コンパイラによってセキュリティ要求が挿入されます。 要求は、動的メソッドが完全に信頼されたコードによって実行される場合にのみ成功します。 「 Security-Transparent コード、レベル 1」を参照してください。
  • 検証不可能なコードを含む動的メソッドが、レベル 2 の透過性 (mscorlib.dllなど) のアセンブリに関連付けられている場合、セキュリティ要求を行う代わりに (JIT コンパイラによって挿入される) 例外がスローされます。 「 Security-Transparent コード、レベル 2」を参照してください。
  • 検証できないコードを含む匿名でホストされる動的メソッドは、常に例外をスローします。 完全に信頼されたコードによって作成および実行された場合でも、検証をスキップすることはできません。

検証できないコードに対してスローされる例外は、動的メソッドの呼び出し方法によって異なります。 CreateDelegate メソッドから返されたデリゲートを使用して動的メソッドを呼び出すと、VerificationException がスローされます。 Invoke メソッドを使用して動的メソッドを呼び出すと、内部の TargetInvocationException と共に VerificationException がスローされます。

コンストラクター

名前 説明
DynamicMethod(String, MethodAttributes, CallingConventions, Type, Type[], Module, Boolean)

メソッド名、属性、呼び出し規則、戻り値の型、パラメーター型、モジュール、および動的メソッドのMicrosoft中間言語 (MSIL) によってアクセスされる型とメンバーに対して Just-In-Time (JIT) 可視性チェックをスキップするかどうかを指定して、モジュールにグローバルな動的メソッドを作成します。

DynamicMethod(String, MethodAttributes, CallingConventions, Type, Type[], Type, Boolean)

動的メソッドを作成し、メソッド名、属性、呼び出し規則、戻り値の型、パラメーター型、動的メソッドが論理的に関連付けられている型、および動的メソッドのMicrosoft中間言語 (MSIL) によってアクセスされる型とメンバーに対して Just-In-Time (JIT) 可視性チェックをスキップするかどうかを指定します。

DynamicMethod(String, Type, Type[], Boolean)

匿名でホストされる動的メソッドを初期化し、メソッド名、戻り値の型、パラメーターの型、および動的メソッドのMicrosoft中間言語 (MSIL) によってアクセスされる型とメンバーの Just-In-Time (JIT) 可視性チェックをスキップするかどうかを指定します。

DynamicMethod(String, Type, Type[], Module, Boolean)

メソッド名、戻り値の型、パラメーター型、モジュール、および動的メソッドのMicrosoft中間言語 (MSIL) によってアクセスされる型とメンバーに対して Just-In-Time (JIT) 可視性チェックをスキップするかどうかを指定して、モジュールにグローバルな動的メソッドを作成します。

DynamicMethod(String, Type, Type[], Module)

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

DynamicMethod(String, Type, Type[], Type, Boolean)

動的メソッドを作成し、メソッド名、戻り値の型、パラメーター型、動的メソッドが論理的に関連付けられている型、および動的メソッドのMicrosoft中間言語 (MSIL) によってアクセスされる型とメンバーに対して Just-In-Time (JIT) 可視性チェックをスキップするかどうかを指定します。

DynamicMethod(String, Type, Type[], Type)

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

DynamicMethod(String, Type, Type[])

メソッド名、戻り値の型、およびパラメーター型を指定して、匿名でホストされる動的メソッドを初期化します。

プロパティ

名前 説明
Attributes

動的メソッドの作成時に指定された属性を取得します。

CallingConvention

動的メソッドの作成時に指定された呼び出し規則を取得します。

ContainsGenericParameters

ジェネリック メソッドに割り当てられていないジェネリック型パラメーターが含まれているかどうかを示す値を取得します。

(継承元 MethodInfo)
CustomAttributes

このメンバーのカスタム属性を含むコレクションを取得します。

(継承元 MemberInfo)
DeclaringType

動的メソッドに対して常に null されるメソッドを宣言する型を取得します。

InitLocals

メソッド内のローカル変数がゼロ初期化されているかどうかを示す値を取得または設定します。

IsAbstract

メソッドが抽象であるかどうかを示す値を取得します。

(継承元 MethodBase)
IsAssembly

このメソッドまたはコンストラクターの潜在的な可視性が Assemblyによって記述されているかどうかを示す値を取得します。つまり、メソッドまたはコンストラクターは、同じアセンブリ内の他の型に対して最大で表示され、アセンブリ外の派生型には表示されません。

(継承元 MethodBase)
IsCollectible

この MemberInfo オブジェクトが収集可能な AssemblyLoadContextに保持されている 1 つ以上のアセンブリを参照するかどうかを示す値を取得します。

(継承元 MemberInfo)
IsConstructedGenericMethod

コンパイル、実行、および破棄できる動的メソッドを定義して表します。 破棄されたメソッドは、ガベージ コレクションで使用できます。

(継承元 MethodBase)
IsConstructor

メソッドがコンストラクターであるかどうかを示す値を取得します。

(継承元 MethodBase)
IsFamily

このメソッドまたはコンストラクターの可視性が Familyによって記述されているかどうかを示す値を取得します。つまり、メソッドまたはコンストラクターは、そのクラスおよび派生クラス内でのみ表示されます。

(継承元 MethodBase)
IsFamilyAndAssembly

このメソッドまたはコンストラクターの可視性が FamANDAssemによって記述されているかどうかを示す値を取得します。つまり、メソッドまたはコンストラクターは派生クラスによって呼び出すことができますが、同じアセンブリ内にある場合にのみ呼び出すことができます。

(継承元 MethodBase)
IsFamilyOrAssembly

このメソッドまたはコンストラクターの潜在的な可視性が FamORAssemによって記述されているかどうかを示す値を取得します。つまり、メソッドまたはコンストラクターは、どこにいても派生クラス、および同じアセンブリ内のクラスによって呼び出すことができます。

(継承元 MethodBase)
IsFinal

このメソッドが finalされているかどうかを示す値を取得します。

(継承元 MethodBase)
IsGenericMethod

現在のメソッドがジェネリック メソッドかどうかを示す値を取得します。

(継承元 MethodInfo)
IsGenericMethodDefinition

現在の MethodInfo がジェネリック メソッドの定義を表すかどうかを示す値を取得します。

(継承元 MethodInfo)
IsHideBySig

まったく同じシグネチャを持つ同じ種類のメンバーのみが派生クラスで非表示かどうかを示す値を取得します。

(継承元 MethodBase)
IsPrivate

このメンバーがプライベートかどうかを示す値を取得します。

(継承元 MethodBase)
IsPublic

これがパブリック メソッドであるかどうかを示す値を取得します。

(継承元 MethodBase)
IsSecurityCritical

現在の動的メソッドがセキュリティ クリティカルかセキュリティ セーフ クリティカルかを示す値を取得します。そのため、重要な操作を実行できます。

IsSecurityCritical

現在のメソッドまたはコンストラクターが現在の信頼レベルでセキュリティ クリティカルかセキュリティ セーフ クリティカルかを示す値を取得します。そのため、重要な操作を実行できます。

(継承元 MethodBase)
IsSecuritySafeCritical

現在の動的メソッドが現在の信頼レベルでセキュリティ セーフ クリティカルであるかどうかを示す値を取得します。つまり、重要な操作を実行でき、透過的なコードからアクセスできるかどうかです。

IsSecuritySafeCritical

現在のメソッドまたはコンストラクターが現在の信頼レベルでセキュリティ セーフ クリティカルであるかどうかを示す値を取得します。つまり、重要な操作を実行でき、透過的なコードからアクセスできるかどうかです。

(継承元 MethodBase)
IsSecurityTransparent

現在の動的メソッドが現在の信頼レベルで透過的であり、重要な操作を実行できないかどうかを示す値を取得します。

IsSecurityTransparent

現在のメソッドまたはコンストラクターが現在の信頼レベルで透過的であり、重要な操作を実行できないかどうかを示す値を取得します。

(継承元 MethodBase)
IsSpecialName

このメソッドに特別な名前があるかどうかを示す値を取得します。

(継承元 MethodBase)
IsStatic

メソッドが staticされているかどうかを示す値を取得します。

(継承元 MethodBase)
IsVirtual

メソッドが virtualされているかどうかを示す値を取得します。

(継承元 MethodBase)
MemberType

このメンバーがメソッドであることを示す MemberTypes 値を取得します。

(継承元 MethodInfo)
MetadataToken

メタデータ要素を識別する値を取得します。

(継承元 MemberInfo)
MethodHandle

動的メソッドではサポートされていません。

MethodImplementationFlags

コンパイル、実行、および破棄できる動的メソッドを定義して表します。 破棄されたメソッドは、ガベージ コレクションで使用できます。

MethodImplementationFlags

メソッド実装の属性を指定する MethodImplAttributes フラグを取得します。

(継承元 MethodBase)
Module

動的メソッドが論理的に関連付けられているモジュールを取得します。

Module

現在の MemberInfo によって表されるメンバーを宣言する型が定義されているモジュールを取得します。

(継承元 MemberInfo)
Name

動的メソッドの名前を取得します。

ReflectedType

リフレクションでメソッドを取得するために使用されたクラスを取得します。

ReturnParameter

動的メソッドの戻り値パラメーターを取得します。

ReturnType

動的メソッドの戻り値の型を取得します。

ReturnTypeCustomAttributes

動的メソッドの戻り値の型のカスタム属性を取得します。

ReturnTypeCustomAttributes

戻り値の型のカスタム属性を取得します。

(継承元 MethodInfo)

メソッド

名前 説明
CreateDelegate(Type, Object)

動的メソッドを完了し、デリゲートの実行に使用できるデリゲートを作成します。デリゲートの型とデリゲートがバインドされているオブジェクトを指定します。

CreateDelegate(Type)

動的メソッドを完了し、それを実行するために使用できるデリゲートを作成します。

CreateDelegate<T>()

このメソッドから T 型のデリゲートを作成します。

(継承元 MethodInfo)
CreateDelegate<T>(Object)

このメソッドから、指定したターゲットを使用して T 型のデリゲートを作成します。

(継承元 MethodInfo)
DefineParameter(Int32, ParameterAttributes, String)

動的メソッドのパラメーターを定義します。

Equals(Object)

このインスタンスが指定したオブジェクトと等しいかどうかを示す値を返します。

(継承元 MethodInfo)
GetBaseDefinition()

メソッドの基本実装を返します。

GetBaseDefinition()

派生クラスでオーバーライドされた場合、このインスタンスによって表されるメソッドが最初に宣言された直接または間接基底クラスのメソッドの MethodInfo オブジェクトを返します。

(継承元 MethodInfo)
GetCustomAttributes(Boolean)

メソッドに定義されているすべてのカスタム属性を返します。

GetCustomAttributes(Type, Boolean)

メソッドに適用されている、指定した型のカスタム属性を返します。

GetCustomAttributesData()

ターゲット メンバーに適用 CustomAttributeData 属性に関するデータを表すオブジェクトの一覧を返します。

(継承元 MemberInfo)
GetDynamicILInfo()

メタデータ トークン、スコープ、Microsoft中間言語 (MSIL) ストリームからメソッド本体を生成するために使用できるDynamicILInfo オブジェクトを返します。

GetGenericArguments()

ジェネリック メソッドの型引数またはジェネリック メソッド定義の型パラメーターを表す Type オブジェクトの配列を返します。

(継承元 MethodInfo)
GetGenericMethodDefinition()

現在のメソッドを構築できるジェネリック メソッド定義を表す MethodInfo オブジェクトを返します。

(継承元 MethodInfo)
GetHashCode()

このインスタンスのハッシュ コードを返します。

(継承元 MethodInfo)
GetILGenerator()

既定の MSIL ストリーム サイズが 64 バイトのメソッドのMicrosoft中間言語 (MSIL) ジェネレーターを返します。

GetILGenerator(Int32)

指定した MSIL ストリーム サイズを持つメソッドのMicrosoft中間言語 (MSIL) ジェネレーターを返します。

GetMethodBody()

派生クラスでオーバーライドされると、MSIL ストリーム、ローカル変数、および現在のメソッドの例外へのアクセスを提供する MethodBody オブジェクトを取得します。

(継承元 MethodBase)
GetMethodImplementationFlags()

メソッドの実装フラグを返します。

GetMethodImplementationFlags()

派生クラスでオーバーライドされると、 MethodImplAttributes フラグを返します。

(継承元 MethodBase)
GetParameters()

動的メソッドのパラメーターを返します。

HasSameMetadataDefinitionAs(MemberInfo)

コンパイル、実行、および破棄できる動的メソッドを定義して表します。 破棄されたメソッドは、ガベージ コレクションで使用できます。

(継承元 MemberInfo)
Invoke(Object, BindingFlags, Binder, Object[], CultureInfo)

指定したカルチャ情報を使用して、指定したバインダーの制約の下で、指定したパラメーターを使用して動的メソッドを呼び出します。

IsDefined(Type, Boolean)

指定したカスタム属性の型が定義されているかどうかを示します。

MakeGenericMethod(Type[])

型の配列の要素を現在のジェネリック メソッド定義の型パラメーターに置き換え、結果として構築されたメソッドを表す MethodInfo オブジェクトを返します。

(継承元 MethodInfo)
MemberwiseClone()

現在の Objectの簡易コピーを作成します。

(継承元 Object)
ToString()

文字列として表されるメソッドのシグネチャを返します。

明示的なインターフェイスの実装

名前 説明
_MemberInfo.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

一連の名前を対応する一連のディスパッチ識別子に割り当てます。

(継承元 MemberInfo)
_MemberInfo.GetType()

Type クラスを表すMemberInfo オブジェクトを取得します。

(継承元 MemberInfo)
_MemberInfo.GetTypeInfo(UInt32, UInt32, IntPtr)

オブジェクトの型情報を取得します。この型情報を使用して、インターフェイスの型情報を取得できます。

(継承元 MemberInfo)
_MemberInfo.GetTypeInfoCount(UInt32)

オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。

(継承元 MemberInfo)
_MemberInfo.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

オブジェクトによって公開されるプロパティとメソッドへのアクセスを提供します。

(継承元 MemberInfo)
_MethodBase.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

一連の名前を対応する一連のディスパッチ識別子に割り当てます。

(継承元 MethodBase)
_MethodBase.GetType()

このメンバーの説明については、 GetType()を参照してください。

(継承元 MethodBase)
_MethodBase.GetTypeInfo(UInt32, UInt32, IntPtr)

オブジェクトの型情報を取得します。この型情報を使用して、インターフェイスの型情報を取得できます。

(継承元 MethodBase)
_MethodBase.GetTypeInfoCount(UInt32)

オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。

(継承元 MethodBase)
_MethodBase.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

オブジェクトによって公開されるプロパティとメソッドへのアクセスを提供します。

(継承元 MethodBase)
_MethodBase.IsAbstract

このメンバーの説明については、 IsAbstractを参照してください。

(継承元 MethodBase)
_MethodBase.IsAssembly

このメンバーの説明については、 IsAssemblyを参照してください。

(継承元 MethodBase)
_MethodBase.IsConstructor

このメンバーの説明については、 IsConstructorを参照してください。

(継承元 MethodBase)
_MethodBase.IsFamily

このメンバーの説明については、 IsFamilyを参照してください。

(継承元 MethodBase)
_MethodBase.IsFamilyAndAssembly

このメンバーの説明については、 IsFamilyAndAssemblyを参照してください。

(継承元 MethodBase)
_MethodBase.IsFamilyOrAssembly

このメンバーの説明については、 IsFamilyOrAssemblyを参照してください。

(継承元 MethodBase)
_MethodBase.IsFinal

このメンバーの説明については、 IsFinalを参照してください。

(継承元 MethodBase)
_MethodBase.IsHideBySig

このメンバーの説明については、 IsHideBySigを参照してください。

(継承元 MethodBase)
_MethodBase.IsPrivate

このメンバーの説明については、 IsPrivateを参照してください。

(継承元 MethodBase)
_MethodBase.IsPublic

このメンバーの説明については、 IsPublicを参照してください。

(継承元 MethodBase)
_MethodBase.IsSpecialName

このメンバーの説明については、 IsSpecialNameを参照してください。

(継承元 MethodBase)
_MethodBase.IsStatic

このメンバーの説明については、 IsStaticを参照してください。

(継承元 MethodBase)
_MethodBase.IsVirtual

このメンバーの説明については、 IsVirtualを参照してください。

(継承元 MethodBase)
_MethodInfo.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

一連の名前を対応する一連のディスパッチ識別子に割り当てます。

(継承元 MethodInfo)
_MethodInfo.GetType()

COM から GetType() メソッドへのアクセスを提供します。

(継承元 MethodInfo)
_MethodInfo.GetTypeInfo(UInt32, UInt32, IntPtr)

インターフェイスの型情報を取得するために使用できるオブジェクトの型情報を取得します。

(継承元 MethodInfo)
_MethodInfo.GetTypeInfoCount(UInt32)

オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。

(継承元 MethodInfo)
_MethodInfo.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

オブジェクトによって公開されるプロパティとメソッドへのアクセスを提供します。

(継承元 MethodInfo)
ICustomAttributeProvider.GetCustomAttributes(Boolean)

名前付き属性を除き、このメンバーで定義されているすべてのカスタム属性の配列を返します。カスタム属性がない場合は空の配列を返します。

(継承元 MemberInfo)
ICustomAttributeProvider.GetCustomAttributes(Type, Boolean)

このメンバーで定義されているカスタム属性の配列を型で識別するか、その型のカスタム属性がない場合は空の配列を返します。

(継承元 MemberInfo)
ICustomAttributeProvider.IsDefined(Type, Boolean)

attributeTypeの 1 つ以上のインスタンスがこのメンバーで定義されているかどうかを示します。

(継承元 MemberInfo)

拡張メソッド

名前 説明
GetBaseDefinition(MethodInfo)

コンパイル、実行、および破棄できる動的メソッドを定義して表します。 破棄されたメソッドは、ガベージ コレクションで使用できます。

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)

指定したメンバーに適用される、指定した型のカスタム属性のコレクションを取得します。

GetMetadataToken(MemberInfo)

指定されたメンバーのメタデータ トークンを取得します (使用可能な場合)。

GetRuntimeBaseDefinition(MethodInfo)

メソッドが最初に宣言されたダイレクト 基底クラスまたは間接基底クラスで、指定されたメソッドを表すオブジェクトを取得します。

HasMetadataToken(MemberInfo)

指定したメンバーに対してメタデータ トークンを使用できるかどうかを示す値を返します。

IsDefined(MemberInfo, Type, Boolean)

指定した型のカスタム属性が指定したメンバーに適用され、必要に応じてその先祖に適用されるかどうかを示します。

IsDefined(MemberInfo, Type)

指定した型のカスタム属性が、指定したメンバーに適用されるかどうかを示します。

適用対象

こちらもご覧ください