DynamicMethod Kelas

Definisi

Mendefinisikan dan mewakili metode dinamis yang dapat dikompilasi, dijalankan, dan dibuang. Metode yang dibuang tersedia untuk pengumpulan sampah.

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
Warisan
Atribut

Contoh

Contoh kode berikut membuat metode dinamis yang mengambil dua parameter. Contoh memancarkan isi fungsi sederhana yang mencetak parameter pertama ke konsol, dan contohnya menggunakan parameter kedua sebagai nilai pengembalian metode. Contoh menyelesaikan metode dengan membuat delegasi, memanggil delegasi dengan parameter yang berbeda, dan akhirnya memanggil metode dinamis menggunakan Invoke metode .

using namespace System;
using namespace System::Reflection;
using namespace System::Reflection::Emit;
using namespace System::Globalization;

// Declare a delegate type that can be used to execute the completed
// dynamic method. 
private delegate int HelloDelegate(String^ msg, int ret);

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.
    array<Type^>^ helloArgs = { String::typeid, int::typeid };

    // 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 = gcnew DynamicMethod("Hello", 
        int::typeid, 
        helloArgs, 
        String::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,
    // 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, nullptr);
    // 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(HelloDelegate::typeid);

    // 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.
    array<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(nullptr, BindingFlags::ExactBinding, nullptr, invokeArgs, gcnew 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 == nullptr)
    {
        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 == nullptr)
    {
        Console::WriteLine("\r\nReflectedType is null.");
    }
    else
    {
        Console::WriteLine("\r\nReflectedType: {0}", hello->ReflectedType);
    }

    if (hello->ReturnParameter == nullptr)
    {
        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 == Void::typeid)
    {
        Console::WriteLine("The method has no return type.");
    }
    else
    {
        ICustomAttributeProvider^ caProvider = hello->ReturnTypeCustomAttributes;
        array<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:");
            for each (Object^ attr in returnAttributes)
            {
                Console::WriteLine("\t{0}", attr->ToString());
            }
        }
    }

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

    // Display parameter information.
    array<ParameterInfo^>^ parameters = hello->GetParameters();
    Console::WriteLine("\r\nParameters: name, type, ParameterAttributes");
    for each (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
 */
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

Keterangan

Untuk informasi selengkapnya tentang API ini, lihat Keterangan API Tambahan untuk DynamicMethod.

Konstruktor

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

Membuat metode dinamis yang bersifat global untuk modul, menentukan nama metode, atribut, konvensi panggilan, jenis pengembalian, jenis parameter, modul, dan apakah pemeriksaan visibilitas just-in-time (JIT) harus dilewati untuk jenis dan anggota yang diakses oleh bahasa perantara Microsoft (MSIL) dari metode dinamis.

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

Membuat metode dinamis, menentukan nama metode, atribut, konvensi panggilan, jenis pengembalian, jenis parameter, jenis yang terkait dengan metode dinamis, dan apakah pemeriksaan visibilitas just-in-time (JIT) harus dilewati untuk jenis dan anggota yang diakses oleh bahasa perantara Microsoft (MSIL) dari metode dinamis.

DynamicMethod(String, Type, Type[])

Menginisialisasi metode dinamis yang dihosting secara anonim, menentukan nama metode, jenis pengembalian, dan jenis parameter.

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

Menginisialisasi metode dinamis yang dihosting secara anonim, menentukan nama metode, jenis pengembalian, jenis parameter, dan apakah pemeriksaan visibilitas just-in-time (JIT) harus dilewati untuk jenis dan anggota yang diakses oleh bahasa perantara Microsoft (MSIL) dari metode dinamis.

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

Membuat metode dinamis yang bersifat global untuk modul, menentukan nama metode, jenis pengembalian, jenis parameter, dan modul.

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

Membuat metode dinamis yang bersifat global ke modul, menentukan nama metode, jenis pengembalian, jenis parameter, modul, dan apakah pemeriksaan visibilitas just-in-time (JIT) harus dilewati untuk jenis dan anggota yang diakses oleh bahasa perantara Microsoft (MSIL) dari metode dinamis.

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

Membuat metode dinamis, menentukan nama metode, jenis pengembalian, jenis parameter, dan jenis yang dikaitkan dengan metode dinamis secara logis.

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

Membuat metode dinamis, menentukan nama metode, jenis pengembalian, jenis parameter, jenis yang metode dinamisnya terkait secara logis, dan apakah pemeriksaan visibilitas just-in-time (JIT) harus dilewati untuk jenis dan anggota yang diakses oleh bahasa perantara Microsoft (MSIL) dari metode dinamis.

Properti

Attributes

Mendapatkan atribut yang ditentukan ketika metode dinamis dibuat.

CallingConvention

Mendapatkan konvensi panggilan yang ditentukan ketika metode dinamis dibuat.

ContainsGenericParameters

Mendapatkan nilai yang menunjukkan apakah metode generik berisi parameter jenis generik yang tidak ditetapkan.

(Diperoleh dari MethodInfo)
CustomAttributes

Mendapatkan koleksi yang berisi atribut kustom anggota ini.

(Diperoleh dari MemberInfo)
DeclaringType

Mendapatkan jenis yang mendeklarasikan metode , yang selalu null untuk metode dinamis.

InitLocals

Mendapatkan atau menetapkan nilai yang menunjukkan apakah variabel lokal dalam metode diinisialisasi nol.

IsAbstract

Mendapatkan nilai yang menunjukkan apakah metode tersebut abstrak.

(Diperoleh dari MethodBase)
IsAssembly

Mendapatkan nilai yang menunjukkan apakah visibilitas potensial dari metode atau konstruktor ini dijelaskan oleh ; yaitu, metode atau konstruktor terlihat paling banyak ke jenis lain dalam perakitan yang sama, dan tidak terlihat oleh Assemblyjenis turunan di luar perakitan.

(Diperoleh dari MethodBase)
IsCollectible

Mendapatkan nilai yang menunjukkan apakah objek ini MemberInfo adalah bagian dari perakitan yang dipegang dalam koleksi AssemblyLoadContext.

(Diperoleh dari MemberInfo)
IsConstructedGenericMethod

Mendefinisikan dan mewakili metode dinamis yang dapat dikompilasi, dijalankan, dan dibuang. Metode yang dibuang tersedia untuk pengumpulan sampah.

(Diperoleh dari MethodBase)
IsConstructor

Mendapatkan nilai yang menunjukkan apakah metode tersebut adalah konstruktor.

(Diperoleh dari MethodBase)
IsFamily

Mendapatkan nilai yang menunjukkan apakah visibilitas metode atau konstruktor ini dijelaskan oleh Family; yaitu, metode atau konstruktor hanya terlihat dalam kelas dan kelas turunannya.

(Diperoleh dari MethodBase)
IsFamilyAndAssembly

Mendapatkan nilai yang menunjukkan apakah visibilitas metode atau konstruktor ini dijelaskan oleh FamANDAssem; yaitu, metode atau konstruktor dapat dipanggil oleh kelas turunan, tetapi hanya jika mereka berada dalam perakitan yang sama.

(Diperoleh dari MethodBase)
IsFamilyOrAssembly

Mendapatkan nilai yang menunjukkan apakah visibilitas potensial dari metode atau konstruktor ini dijelaskan oleh FamORAssem; yaitu, metode atau konstruktor dapat dipanggil oleh kelas turunan di mana pun mereka berada, dan berdasarkan kelas dalam perakitan yang sama.

(Diperoleh dari MethodBase)
IsFinal

Mendapatkan nilai yang menunjukkan apakah metode ini adalah final.

(Diperoleh dari MethodBase)
IsGenericMethod

Mendapatkan nilai yang menunjukkan apakah metode saat ini adalah metode generik.

(Diperoleh dari MethodInfo)
IsGenericMethodDefinition

Mendapatkan nilai yang menunjukkan apakah saat ini MethodInfo mewakili definisi metode generik.

(Diperoleh dari MethodInfo)
IsHideBySig

Mendapatkan nilai yang menunjukkan apakah hanya anggota dari jenis yang sama dengan tanda tangan yang sama persis yang disembunyikan di kelas turunan.

(Diperoleh dari MethodBase)
IsPrivate

Mendapatkan nilai yang menunjukkan apakah anggota ini bersifat privat.

(Diperoleh dari MethodBase)
IsPublic

Mendapatkan nilai yang menunjukkan apakah ini adalah metode publik.

(Diperoleh dari MethodBase)
IsSecurityCritical

Mendapatkan nilai yang menunjukkan apakah metode dinamis saat ini penting bagi keamanan atau keamanan kritis, dan karenanya dapat melakukan operasi penting.

IsSecurityCritical

Mendapatkan nilai yang menunjukkan apakah metode atau konstruktor saat ini kritis terhadap keamanan atau keamanan-aman-kritis pada tingkat kepercayaan saat ini, dan karenanya dapat melakukan operasi penting.

(Diperoleh dari MethodBase)
IsSecuritySafeCritical

Mendapatkan nilai yang menunjukkan apakah metode dinamis saat ini adalah keamanan-aman-kritis pada tingkat kepercayaan saat ini; yaitu, apakah dapat melakukan operasi penting dan dapat diakses dengan kode transparan.

IsSecuritySafeCritical

Mendapatkan nilai yang menunjukkan apakah metode atau konstruktor saat ini kritis keamanan-aman pada tingkat kepercayaan saat ini; yaitu, apakah dapat melakukan operasi penting dan dapat diakses dengan kode transparan.

(Diperoleh dari MethodBase)
IsSecurityTransparent

Mendapatkan nilai yang menunjukkan apakah metode dinamis saat ini transparan pada tingkat kepercayaan saat ini, dan karenanya tidak dapat melakukan operasi penting.

IsSecurityTransparent

Mendapatkan nilai yang menunjukkan apakah metode atau konstruktor saat ini transparan pada tingkat kepercayaan saat ini, dan karenanya tidak dapat melakukan operasi penting.

(Diperoleh dari MethodBase)
IsSpecialName

Mendapatkan nilai yang menunjukkan apakah metode ini memiliki nama khusus.

(Diperoleh dari MethodBase)
IsStatic

Mendapatkan nilai yang menunjukkan apakah metodenya adalah static.

(Diperoleh dari MethodBase)
IsVirtual

Mendapatkan nilai yang menunjukkan apakah metodenya adalah virtual.

(Diperoleh dari MethodBase)
MemberType

Mendapatkan nilai yang MemberTypes menunjukkan bahwa anggota ini adalah metode .

(Diperoleh dari MethodInfo)
MetadataToken

Mendapatkan nilai yang mengidentifikasi elemen metadata.

(Diperoleh dari MemberInfo)
MethodHandle

Tidak didukung untuk metode dinamis.

MethodHandle

Mendapatkan handel ke representasi metadata internal metode .

(Diperoleh dari MethodBase)
MethodImplementationFlags

Mendefinisikan dan mewakili metode dinamis yang dapat dikompilasi, dijalankan, dan dibuang. Metode yang dibuang tersedia untuk pengumpulan sampah.

MethodImplementationFlags

MethodImplAttributes Mendapatkan bendera yang menentukan atribut implementasi metode.

(Diperoleh dari MethodBase)
Module

Mendapatkan modul yang metode dinamisnya dikaitkan secara logis.

Module

Mendapatkan modul di mana jenis yang menyatakan anggota yang diwakili oleh saat ini MemberInfo ditentukan.

(Diperoleh dari MemberInfo)
Name

Mendapatkan nama metode dinamis.

ReflectedType

Mendapatkan kelas yang digunakan dalam refleksi untuk mendapatkan metode .

ReflectedType

Mendapatkan objek kelas yang digunakan untuk mendapatkan instans ini dari MemberInfo.

(Diperoleh dari MemberInfo)
ReturnParameter

Mendapatkan parameter pengembalian dari metode dinamis.

ReturnType

Mendapatkan jenis nilai pengembalian untuk metode dinamis.

ReturnTypeCustomAttributes

Mendapatkan atribut kustom dari jenis pengembalian untuk metode dinamis.

ReturnTypeCustomAttributes

Mendapatkan atribut kustom untuk jenis pengembalian.

(Diperoleh dari MethodInfo)

Metode

CreateDelegate(Type)

Menyelesaikan metode dinamis dan membuat delegasi yang dapat digunakan untuk menjalankannya.

CreateDelegate(Type, Object)

Menyelesaikan metode dinamis dan membuat delegasi yang dapat digunakan untuk menjalankannya, menentukan jenis delegasi dan objek yang terikat delegasi.

CreateDelegate<T>()

Membuat delegasi jenis T dari metode ini.

(Diperoleh dari MethodInfo)
CreateDelegate<T>(Object)

Membuat delegasi jenis T dengan target yang ditentukan dari metode ini.

(Diperoleh dari MethodInfo)
DefineParameter(Int32, ParameterAttributes, String)

Mendefinisikan parameter metode dinamis.

Equals(Object)

Mengembalikan nilai yang menunjukkan apakah instans ini sama dengan objek tertentu.

(Diperoleh dari MethodInfo)
GetBaseDefinition()

Mengembalikan implementasi dasar untuk metode .

GetBaseDefinition()

Ketika ditimpa dalam kelas turunan, mengembalikan MethodInfo objek untuk metode pada kelas dasar langsung atau tidak langsung di mana metode yang diwakili oleh instans ini pertama kali dideklarasikan.

(Diperoleh dari MethodInfo)
GetCustomAttributes(Boolean)

Mengembalikan semua atribut kustom yang ditentukan untuk metode .

GetCustomAttributes(Boolean)

Saat ditimpa di kelas turunan, mengembalikan array semua atribut kustom yang diterapkan ke anggota ini.

(Diperoleh dari MemberInfo)
GetCustomAttributes(Type, Boolean)

Mengembalikan atribut kustom dari jenis yang ditentukan yang telah diterapkan ke metode .

GetCustomAttributes(Type, Boolean)

Saat ditimpa di kelas turunan, mengembalikan array atribut kustom yang diterapkan ke anggota ini dan diidentifikasi oleh Type.

(Diperoleh dari MemberInfo)
GetCustomAttributesData()

Mengembalikan daftar CustomAttributeData objek yang mewakili data tentang atribut yang telah diterapkan ke anggota target.

(Diperoleh dari MemberInfo)
GetDynamicILInfo()

DynamicILInfo Mengembalikan objek yang dapat digunakan untuk menghasilkan isi metode dari token metadata, cakupan, dan aliran bahasa perantara Microsoft (MSIL).

GetGenericArguments()

Mengembalikan array Type objek yang mewakili argumen jenis metode generik atau parameter jenis definisi metode generik.

(Diperoleh dari MethodInfo)
GetGenericMethodDefinition()

MethodInfo Mengembalikan objek yang mewakili definisi metode generik tempat metode saat ini dapat dibangun.

(Diperoleh dari MethodInfo)
GetHashCode()

Mengembalikan kode hash untuk instans ini.

(Diperoleh dari MethodInfo)
GetILGenerator()

Mengembalikan generator bahasa perantara Microsoft (MSIL) untuk metode dengan ukuran aliran MSIL default 64 byte.

GetILGenerator(Int32)

Mengembalikan generator bahasa perantara Microsoft (MSIL) untuk metode dengan ukuran aliran MSIL yang ditentukan.

GetMethodBody()

Ketika ditimpa di kelas turunan, mendapatkan MethodBody objek yang menyediakan akses ke aliran MSIL, variabel lokal, dan pengecualian untuk metode saat ini.

(Diperoleh dari MethodBase)
GetMethodImplementationFlags()

Mengembalikan bendera implementasi untuk metode .

GetMethodImplementationFlags()

Saat ditimpa di kelas turunan MethodImplAttributes , mengembalikan bendera.

(Diperoleh dari MethodBase)
GetParameters()

Mengembalikan parameter metode dinamis.

GetType()

Menemukan atribut metode dan menyediakan akses ke metadata metode.

(Diperoleh dari MethodInfo)
HasSameMetadataDefinitionAs(MemberInfo)

Mendefinisikan dan mewakili metode dinamis yang dapat dikompilasi, dijalankan, dan dibuang. Metode yang dibuang tersedia untuk pengumpulan sampah.

(Diperoleh dari MemberInfo)
Invoke(Object, BindingFlags, Binder, Object[], CultureInfo)

Memanggil metode dinamis menggunakan parameter yang ditentukan, di bawah batasan pengikat yang ditentukan, dengan informasi budaya yang ditentukan.

Invoke(Object, BindingFlags, Binder, Object[], CultureInfo)

Ketika ditimpa di kelas turunan, memanggil metode atau konstruktor yang tercermin dengan parameter yang diberikan.

(Diperoleh dari MethodBase)
Invoke(Object, Object[])

Memanggil metode atau konstruktor yang diwakili oleh instans saat ini, menggunakan parameter yang ditentukan.

(Diperoleh dari MethodInfo)
IsDefined(Type, Boolean)

Menunjukkan apakah jenis atribut kustom yang ditentukan ditentukan.

IsDefined(Type, Boolean)

Ketika ditimpa di kelas turunan, menunjukkan apakah satu atau beberapa atribut dari jenis yang ditentukan atau jenis turunannya diterapkan kepada anggota ini.

(Diperoleh dari MemberInfo)
MakeGenericMethod(Type[])

Mengganti elemen larik tipe untuk parameter jenis dari definisi metode generik saat ini, dan menghasilkan objek MethodInfo yang mewakili metode konstruiksi yang dibuat.

(Diperoleh dari MethodInfo)
MemberwiseClone()

Membuat salinan dangkal dari saat ini Object.

(Diperoleh dari Object)
ToString()

Mengembalikan tanda tangan metode , yang direpresentasikan sebagai string.

Implementasi Antarmuka Eksplisit

_MemberInfo.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Memetakan sekumpulan nama ke sekumpulan pengidentifikasi pengiriman yang sesuai.

(Diperoleh dari MemberInfo)
_MemberInfo.GetType()

Mendapatkan objek yang Type mewakili MemberInfo kelas .

(Diperoleh dari MemberInfo)
_MemberInfo.GetTypeInfo(UInt32, UInt32, IntPtr)

Mengambil informasi jenis untuk objek, yang kemudian dapat digunakan untuk mendapatkan informasi jenis untuk antarmuka.

(Diperoleh dari MemberInfo)
_MemberInfo.GetTypeInfoCount(UInt32)

Mengambil jumlah antarmuka informasi jenis yang disediakan objek (baik 0 atau 1).

(Diperoleh dari MemberInfo)
_MemberInfo.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Menyediakan akses ke properti dan metode yang diekspos oleh objek.

(Diperoleh dari MemberInfo)
_MethodBase.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Memetakan sekumpulan nama ke sekumpulan pengidentifikasi pengiriman yang sesuai.

(Diperoleh dari MethodBase)
_MethodBase.GetType()

Untuk deskripsi anggota ini, lihat GetType().

(Diperoleh dari MethodBase)
_MethodBase.GetTypeInfo(UInt32, UInt32, IntPtr)

Mengambil informasi jenis untuk objek, yang kemudian dapat digunakan untuk mendapatkan informasi jenis untuk antarmuka.

(Diperoleh dari MethodBase)
_MethodBase.GetTypeInfoCount(UInt32)

Mengambil jumlah antarmuka informasi jenis yang disediakan objek (baik 0 atau 1).

(Diperoleh dari MethodBase)
_MethodBase.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Menyediakan akses ke properti dan metode yang diekspos oleh objek.

(Diperoleh dari MethodBase)
_MethodBase.IsAbstract

Untuk deskripsi anggota ini, lihat IsAbstract.

(Diperoleh dari MethodBase)
_MethodBase.IsAssembly

Untuk deskripsi anggota ini, lihat IsAssembly.

(Diperoleh dari MethodBase)
_MethodBase.IsConstructor

Untuk deskripsi anggota ini, lihat IsConstructor.

(Diperoleh dari MethodBase)
_MethodBase.IsFamily

Untuk deskripsi anggota ini, lihat IsFamily.

(Diperoleh dari MethodBase)
_MethodBase.IsFamilyAndAssembly

Untuk deskripsi anggota ini, lihat IsFamilyAndAssembly.

(Diperoleh dari MethodBase)
_MethodBase.IsFamilyOrAssembly

Untuk deskripsi anggota ini, lihat IsFamilyOrAssembly.

(Diperoleh dari MethodBase)
_MethodBase.IsFinal

Untuk deskripsi anggota ini, lihat IsFinal.

(Diperoleh dari MethodBase)
_MethodBase.IsHideBySig

Untuk deskripsi anggota ini, lihat IsHideBySig.

(Diperoleh dari MethodBase)
_MethodBase.IsPrivate

Untuk deskripsi anggota ini, lihat IsPrivate.

(Diperoleh dari MethodBase)
_MethodBase.IsPublic

Untuk deskripsi anggota ini, lihat IsPublic.

(Diperoleh dari MethodBase)
_MethodBase.IsSpecialName

Untuk deskripsi anggota ini, lihat IsSpecialName.

(Diperoleh dari MethodBase)
_MethodBase.IsStatic

Untuk deskripsi anggota ini, lihat IsStatic.

(Diperoleh dari MethodBase)
_MethodBase.IsVirtual

Untuk deskripsi anggota ini, lihat IsVirtual.

(Diperoleh dari MethodBase)
_MethodInfo.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Memetakan sekumpulan nama ke sekumpulan pengidentifikasi pengiriman yang sesuai.

(Diperoleh dari MethodInfo)
_MethodInfo.GetType()

Menyediakan akses ke GetType() metode dari COM.

(Diperoleh dari MethodInfo)
_MethodInfo.GetTypeInfo(UInt32, UInt32, IntPtr)

Mengambil informasi jenis untuk objek, yang dapat digunakan untuk mendapatkan informasi jenis untuk antarmuka.

(Diperoleh dari MethodInfo)
_MethodInfo.GetTypeInfoCount(UInt32)

Mengambil jumlah antarmuka informasi jenis yang disediakan objek (baik 0 atau 1).

(Diperoleh dari MethodInfo)
_MethodInfo.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Menyediakan akses ke properti dan metode yang diekspos oleh objek.

(Diperoleh dari MethodInfo)
ICustomAttributeProvider.GetCustomAttributes(Boolean)

Mengembalikan array dari semua atribut kustom yang ditentukan pada anggota ini, tidak termasuk atribut bernama, atau array kosong jika tidak ada atribut kustom.

(Diperoleh dari MemberInfo)
ICustomAttributeProvider.GetCustomAttributes(Type, Boolean)

Mengembalikan array atribut kustom yang ditentukan pada anggota ini, diidentifikasi berdasarkan jenis, atau array kosong jika tidak ada atribut kustom dari jenis tersebut.

(Diperoleh dari MemberInfo)
ICustomAttributeProvider.IsDefined(Type, Boolean)

Menunjukkan apakah satu atau beberapa attributeType instans ditentukan pada anggota ini.

(Diperoleh dari MemberInfo)

Metode Ekstensi

GetCustomAttribute(MemberInfo, Type)

Mengambil atribut kustom dari jenis tertentu yang diterapkan ke anggota tertentu.

GetCustomAttribute(MemberInfo, Type, Boolean)

Mengambil atribut kustom dari jenis tertentu yang diterapkan ke anggota tertentu, dan secara opsional memeriksa leluhur anggota tersebut.

GetCustomAttribute<T>(MemberInfo)

Mengambil atribut kustom dari jenis tertentu yang diterapkan ke anggota tertentu.

GetCustomAttribute<T>(MemberInfo, Boolean)

Mengambil atribut kustom dari jenis tertentu yang diterapkan ke anggota tertentu, dan secara opsional memeriksa leluhur anggota tersebut.

GetCustomAttributes(MemberInfo)

Mengambil kumpulan atribut kustom yang diterapkan ke anggota tertentu.

GetCustomAttributes(MemberInfo, Boolean)

Mengambil kumpulan atribut kustom yang diterapkan ke anggota tertentu, dan secara opsional memeriksa leluhur anggota tersebut.

GetCustomAttributes(MemberInfo, Type)

Mengambil kumpulan atribut kustom dari jenis tertentu yang diterapkan ke anggota tertentu.

GetCustomAttributes(MemberInfo, Type, Boolean)

Mengambil kumpulan atribut kustom dari jenis tertentu yang diterapkan ke anggota tertentu, dan secara opsional memeriksa leluhur anggota tersebut.

GetCustomAttributes<T>(MemberInfo)

Mengambil kumpulan atribut kustom dari jenis tertentu yang diterapkan ke anggota tertentu.

GetCustomAttributes<T>(MemberInfo, Boolean)

Mengambil kumpulan atribut kustom dari jenis tertentu yang diterapkan ke anggota tertentu, dan secara opsional memeriksa leluhur anggota tersebut.

IsDefined(MemberInfo, Type)

Menunjukkan apakah atribut kustom dari jenis tertentu diterapkan ke anggota tertentu.

IsDefined(MemberInfo, Type, Boolean)

Menunjukkan apakah atribut kustom dari jenis tertentu diterapkan ke anggota tertentu, dan, secara opsional, diterapkan ke leluhurnya.

GetMetadataToken(MemberInfo)

Mendapatkan token metadata untuk anggota tertentu, jika tersedia.

HasMetadataToken(MemberInfo)

Mengembalikan nilai yang menunjukkan apakah token metadata tersedia untuk anggota yang ditentukan.

GetBaseDefinition(MethodInfo)

Mendefinisikan dan mewakili metode dinamis yang dapat dikompilasi, dijalankan, dan dibuang. Metode yang dibuang tersedia untuk pengumpulan sampah.

GetRuntimeBaseDefinition(MethodInfo)

Mengambil objek yang mewakili metode yang ditentukan pada kelas dasar langsung atau tidak langsung tempat metode pertama kali dideklarasikan.

Berlaku untuk

Lihat juga