DynamicMethod Klasa

Definicja

Definiuje i reprezentuje metodę dynamiczną, którą można skompilować, wykonać i odrzucić. Metody odrzucone są dostępne w przypadku odzyskiwania pamięci.

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
Dziedziczenie
Atrybuty

Przykłady

Poniższy przykład kodu tworzy metodę dynamiczną, która przyjmuje dwa parametry. Przykład emituje prostą treść funkcji, która wyświetla pierwszy parametr w konsoli, a w przykładzie użyto drugiego parametru jako wartości zwracanej metody. Przykład kończy metodę, tworząc delegata, wywołuje delegata z różnymi parametrami, a na koniec wywołuje metodę dynamiczną przy użyciu Invoke metody .

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

Uwagi

Aby uzyskać więcej informacji na temat tego interfejsu API, zobacz Uwagi dotyczące dodatkowego interfejsu API dla elementu DynamicMethod.

Konstruktory

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

Tworzy metodę dynamiczną, która jest globalna dla modułu, określając nazwę metody, atrybuty, konwencję wywoływania, typ zwracany, typy parametrów, moduł i czy kontrole widoczności just in time (JIT) powinny być pomijane dla typów i elementów członkowskich, do których uzyskuje dostęp język pośredni microsoft (MSIL) metody dynamicznej.

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

Tworzy metodę dynamiczną, określając nazwę metody, atrybuty, konwencję wywoływania, typ zwracany, typy parametrów, typ, z którym metoda dynamiczna jest logicznie skojarzona i czy kontrole widoczności just in time (JIT) powinny zostać pominięte dla typów i elementów członkowskich, do których uzyskuje dostęp język pośredni microsoft (MSIL) metody dynamicznej.

DynamicMethod(String, Type, Type[])

Inicjuje anonimowo hostowaną metodę dynamiczną, określając nazwę metody, typ zwracany i typy parametrów.

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

Inicjuje anonimowo hostowaną metodę dynamiczną, określając nazwę metody, typ zwracany, typy parametrów oraz czy kontrole widoczności just in time (JIT) powinny być pomijane dla typów i elementów członkowskich, do których uzyskuje dostęp język pośredni Microsoft (MSIL) metody dynamicznej.

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

Tworzy metodę dynamiczną, która jest globalna dla modułu, określając nazwę metody, typ zwracany, typy parametrów i moduł.

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

Tworzy metodę dynamiczną, która jest globalna dla modułu, określając nazwę metody, typ zwracany, typy parametrów, moduł oraz to, czy kontrole widoczności just in time (JIT) powinny być pomijane dla typów i elementów członkowskich dostępnych przez język microsoft intermediate language (MSIL) metody dynamicznej.

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

Tworzy metodę dynamiczną, określając nazwę metody, typ zwracany, typy parametrów i typ, z którym metoda dynamiczna jest logicznie skojarzona.

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

Tworzy metodę dynamiczną, określając nazwę metody, typ zwracany, typy parametrów, typ, z którym metoda dynamiczna jest logicznie skojarzona i czy kontrole widoczności just in time (JIT) powinny być pomijane dla typów i elementów członkowskich, do których uzyskuje dostęp język pośredni microsoft (MSIL) metody dynamicznej.

Właściwości

Attributes

Pobiera atrybuty określone podczas tworzenia metody dynamicznej.

CallingConvention

Pobiera konwencję wywoływania określoną podczas tworzenia metody dynamicznej.

ContainsGenericParameters

Pobiera wartość wskazującą, czy metoda ogólna zawiera nieprzypisane parametry typu ogólnego.

(Odziedziczone po MethodInfo)
CustomAttributes

Pobiera kolekcję zawierającą atrybuty niestandardowe tego elementu członkowskiego.

(Odziedziczone po MemberInfo)
DeclaringType

Pobiera typ, który deklaruje metodę , która jest zawsze null dla metod dynamicznych.

InitLocals

Pobiera lub ustawia wartość wskazującą, czy zmienne lokalne w metodzie są inicjowane zero.

IsAbstract

Pobiera wartość wskazującą, czy metoda jest abstrakcyjna.

(Odziedziczone po MethodBase)
IsAssembly

Pobiera wartość wskazującą, czy potencjalna widoczność tej metody lub konstruktora jest opisana przez Assemblyprogram ; czyli metoda lub konstruktor jest widoczna co najwyżej dla innych typów w tym samym zestawie i nie jest widoczna dla typów pochodnych poza zestawem.

(Odziedziczone po MethodBase)
IsCollectible

Pobiera wartość wskazującą, czy ten MemberInfo obiekt jest częścią zestawu przechowywanego w obiekcie zbieralnym AssemblyLoadContext.

(Odziedziczone po MemberInfo)
IsConstructedGenericMethod

Definiuje i reprezentuje metodę dynamiczną, którą można skompilować, wykonać i odrzucić. Metody odrzucone są dostępne w przypadku odzyskiwania pamięci.

(Odziedziczone po MethodBase)
IsConstructor

Pobiera wartość wskazującą, czy metoda jest konstruktorem.

(Odziedziczone po MethodBase)
IsFamily

Pobiera wartość wskazującą, czy widoczność tej metody lub konstruktora jest opisana przez Family, czyli metoda lub konstruktor jest widoczna tylko w jej klasach i klasach pochodnych.

(Odziedziczone po MethodBase)
IsFamilyAndAssembly

Pobiera wartość wskazującą, czy widoczność tej metody lub konstruktora jest opisana przez FamANDAssemmetodę , czyli metodę lub konstruktor może być wywoływana przez klasy pochodne, ale tylko wtedy, gdy znajdują się w tym samym zestawie.

(Odziedziczone po MethodBase)
IsFamilyOrAssembly

Pobiera wartość wskazującą, czy potencjalna widoczność tej metody lub konstruktora jest opisana przez FamORAssemmetodę , czyli metodę lub konstruktor może być wywoływana przez klasy pochodne wszędzie tam, gdzie są, i przez klasy w tym samym zestawie.

(Odziedziczone po MethodBase)
IsFinal

Pobiera wartość wskazującą, czy ta metoda to final.

(Odziedziczone po MethodBase)
IsGenericMethod

Pobiera wartość wskazującą, czy bieżąca metoda jest metodą ogólną.

(Odziedziczone po MethodInfo)
IsGenericMethodDefinition

Pobiera wartość wskazującą, czy bieżący MethodInfo reprezentuje definicję metody ogólnej.

(Odziedziczone po MethodInfo)
IsHideBySig

Pobiera wartość wskazującą, czy tylko składowa tego samego rodzaju z dokładnie tym samym podpisem jest ukryta w klasie pochodnej.

(Odziedziczone po MethodBase)
IsPrivate

Pobiera wartość wskazującą, czy ten element członkowski jest prywatny.

(Odziedziczone po MethodBase)
IsPublic

Pobiera wartość wskazującą, czy jest to metoda publiczna.

(Odziedziczone po MethodBase)
IsSecurityCritical

Pobiera wartość wskazującą, czy bieżąca metoda dynamiczna jest krytyczna pod względem zabezpieczeń, czy bezpieczna pod względem zabezpieczeń, i w związku z tym może wykonywać operacje krytyczne.

IsSecurityCritical

Pobiera wartość wskazującą, czy bieżąca metoda lub konstruktor ma krytyczne znaczenie dla zabezpieczeń, czy bezpieczeństwo krytyczne dla bezpieczeństwa na bieżącym poziomie zaufania, a zatem może wykonywać operacje krytyczne.

(Odziedziczone po MethodBase)
IsSecuritySafeCritical

Pobiera wartość wskazującą, czy bieżąca metoda dynamiczna ma krytyczne znaczenie dla bezpieczeństwa na bieżącym poziomie zaufania; oznacza to, czy może wykonywać operacje krytyczne i można uzyskiwać do niego dostęp za pomocą przezroczystego kodu.

IsSecuritySafeCritical

Pobiera wartość wskazującą, czy bieżąca metoda lub konstruktor ma krytyczne znaczenie dla zabezpieczeń na bieżącym poziomie zaufania; oznacza to, czy może wykonywać operacje krytyczne i można uzyskiwać do niego dostęp za pomocą przezroczystego kodu.

(Odziedziczone po MethodBase)
IsSecurityTransparent

Pobiera wartość wskazującą, czy bieżąca metoda dynamiczna jest przezroczysta na bieżącym poziomie zaufania i dlatego nie może wykonywać operacji krytycznych.

IsSecurityTransparent

Pobiera wartość wskazującą, czy bieżąca metoda lub konstruktor jest przezroczysta na bieżącym poziomie zaufania i dlatego nie może wykonywać operacji krytycznych.

(Odziedziczone po MethodBase)
IsSpecialName

Pobiera wartość wskazującą, czy ta metoda ma specjalną nazwę.

(Odziedziczone po MethodBase)
IsStatic

Pobiera wartość wskazującą, czy metoda to static.

(Odziedziczone po MethodBase)
IsVirtual

Pobiera wartość wskazującą, czy metoda to virtual.

(Odziedziczone po MethodBase)
MemberType

Pobiera wartość wskazującą MemberTypes , że ten element członkowski jest metodą.

(Odziedziczone po MethodInfo)
MetadataToken

Pobiera wartość identyfikującą element metadanych.

(Odziedziczone po MemberInfo)
MethodHandle

Nieobsługiwane w przypadku metod dynamicznych.

MethodHandle

Pobiera dojście do wewnętrznej reprezentacji metadanych metody.

(Odziedziczone po MethodBase)
MethodImplementationFlags

Definiuje i reprezentuje metodę dynamiczną, którą można skompilować, wykonać i odrzucić. Metody odrzucone są dostępne w przypadku odzyskiwania pamięci.

MethodImplementationFlags

MethodImplAttributes Pobiera flagi określające atrybuty implementacji metody.

(Odziedziczone po MethodBase)
Module

Pobiera moduł, z którym jest logicznie skojarzona metoda dynamiczna.

Module

Pobiera moduł, w którym typ, który deklaruje element członkowski reprezentowany przez bieżący MemberInfo jest zdefiniowany.

(Odziedziczone po MemberInfo)
Name

Pobiera nazwę metody dynamicznej.

ReflectedType

Pobiera klasę użytą w odbiciu w celu uzyskania metody .

ReflectedType

Pobiera obiekt klasy, który został użyty do uzyskania tego wystąpienia klasy MemberInfo.

(Odziedziczone po MemberInfo)
ReturnParameter

Pobiera parametr zwrotny metody dynamicznej.

ReturnType

Pobiera typ wartości zwracanej dla metody dynamicznej.

ReturnTypeCustomAttributes

Pobiera atrybuty niestandardowe typu zwracanego dla metody dynamicznej.

ReturnTypeCustomAttributes

Pobiera atrybuty niestandardowe dla typu zwracanego.

(Odziedziczone po MethodInfo)

Metody

CreateDelegate(Type)

Kończy metodę dynamiczną i tworzy delegata, którego można użyć do jego wykonania.

CreateDelegate(Type, Object)

Kończy metodę dynamiczną i tworzy delegata, którego można użyć do jego wykonania, określając typ delegata i obiekt, z którego jest powiązany delegat.

CreateDelegate<T>()

Tworzy delegata typu T z tej metody.

(Odziedziczone po MethodInfo)
CreateDelegate<T>(Object)

Tworzy delegata typu T z określonym obiektem docelowym z tej metody.

(Odziedziczone po MethodInfo)
DefineParameter(Int32, ParameterAttributes, String)

Definiuje parametr metody dynamicznej.

Equals(Object)

Zwraca wartość wskazującą, czy to wystąpienie jest równe podanemu obiektowi.

(Odziedziczone po MethodInfo)
GetBaseDefinition()

Zwraca podstawową implementację metody .

GetBaseDefinition()

Po zastąpieniu w klasie pochodnej zwraca MethodInfo obiekt metody w bezpośrednich lub pośrednich klasach bazowych, w których metoda reprezentowana przez to wystąpienie została po raz pierwszy zadeklarowana.

(Odziedziczone po MethodInfo)
GetCustomAttributes(Boolean)

Zwraca wszystkie atrybuty niestandardowe zdefiniowane dla metody .

GetCustomAttributes(Boolean)

Po zastąpieniu w klasie pochodnej zwraca tablicę wszystkich atrybutów niestandardowych zastosowanych do tego elementu członkowskiego.

(Odziedziczone po MemberInfo)
GetCustomAttributes(Type, Boolean)

Zwraca atrybuty niestandardowe określonego typu, które zostały zastosowane do metody .

GetCustomAttributes(Type, Boolean)

Po przesłonięciu w klasie pochodnej zwraca tablicę atrybutów niestandardowych zastosowanych do tego elementu członkowskiego i zidentyfikowaną przez Typeelement .

(Odziedziczone po MemberInfo)
GetCustomAttributesData()

Zwraca listę CustomAttributeData obiektów reprezentujących dane dotyczące atrybutów, które zostały zastosowane do elementu docelowego.

(Odziedziczone po MemberInfo)
GetDynamicILInfo()

DynamicILInfo Zwraca obiekt, który może służyć do generowania treści metody na podstawie tokenów metadanych, zakresów i strumieni języka microsoft intermediate language (MSIL).

GetGenericArguments()

Zwraca tablicę Type obiektów reprezentujących argumenty typu metody ogólnej lub parametry typu definicji metody ogólnej.

(Odziedziczone po MethodInfo)
GetGenericMethodDefinition()

MethodInfo Zwraca obiekt reprezentujący ogólną definicję metody, z której można utworzyć bieżącą metodę.

(Odziedziczone po MethodInfo)
GetHashCode()

Zwraca wartość skrótu dla tego wystąpienia.

(Odziedziczone po MethodInfo)
GetILGenerator()

Zwraca generator języka microsoft intermediate language (MSIL) dla metody z domyślnym rozmiarem strumienia MSIL o rozmiarze 64 bajtów.

GetILGenerator(Int32)

Zwraca generator języka Microsoft Intermediate Language (MSIL) dla metody o określonym rozmiarze strumienia MSIL.

GetMethodBody()

Po zastąpieniu w klasie pochodnej pobiera MethodBody obiekt, który zapewnia dostęp do strumienia MSIL, zmiennych lokalnych i wyjątków dla bieżącej metody.

(Odziedziczone po MethodBase)
GetMethodImplementationFlags()

Zwraca flagi implementacji dla metody .

GetMethodImplementationFlags()

Po przesłonięciu MethodImplAttributes w klasie pochodnej zwraca flagi.

(Odziedziczone po MethodBase)
GetParameters()

Zwraca parametry metody dynamicznej.

GetType()

Odnajduje atrybuty metody i zapewnia dostęp do metadanych metody.

(Odziedziczone po MethodInfo)
HasSameMetadataDefinitionAs(MemberInfo)

Definiuje i reprezentuje metodę dynamiczną, którą można skompilować, wykonać i odrzucić. Metody odrzucone są dostępne w przypadku odzyskiwania pamięci.

(Odziedziczone po MemberInfo)
Invoke(Object, BindingFlags, Binder, Object[], CultureInfo)

Wywołuje metodę dynamiczną przy użyciu określonych parametrów w ramach ograniczeń określonego powiązania z określonymi informacjami o kulturze.

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

Podczas zastępowania w klasie pochodnej wywołuje odbitą metodę lub konstruktor z podanymi parametrami.

(Odziedziczone po MethodBase)
Invoke(Object, Object[])

Wywołuje metodę lub konstruktor reprezentowany przez bieżące wystąpienie przy użyciu określonych parametrów.

(Odziedziczone po MethodInfo)
IsDefined(Type, Boolean)

Wskazuje, czy określony typ atrybutu niestandardowego jest zdefiniowany.

IsDefined(Type, Boolean)

Po przesłonięciu w klasie pochodnej wskazuje, czy do tego elementu członkowskiego zastosowano co najmniej jeden atrybut określonego typu lub jego typów pochodnych.

(Odziedziczone po MemberInfo)
MakeGenericMethod(Type[])

Zastępuje elementy tablicy typów dla parametrów typu bieżącej definicji metody ogólnej i zwraca obiekt reprezentujący wynikową skonstruowaną metodę MethodInfo .

(Odziedziczone po MethodInfo)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca podpis metody reprezentowanej jako ciąg.

Jawne implementacje interfejsu

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

Zestaw nazw jest mapowany na odpowiedni zestaw identyfikatorów wysyłania.

(Odziedziczone po MemberInfo)
_MemberInfo.GetType()

Type Pobiera obiekt reprezentujący klasęMemberInfo.

(Odziedziczone po MemberInfo)
_MemberInfo.GetTypeInfo(UInt32, UInt32, IntPtr)

Pobiera informacje o typie dla obiektu, których następnie można użyć do uzyskania informacji o typie interfejsu.

(Odziedziczone po MemberInfo)
_MemberInfo.GetTypeInfoCount(UInt32)

Pobiera informację o liczbie typów interfejsów, jakie zawiera obiekt (0 lub 1).

(Odziedziczone po MemberInfo)
_MemberInfo.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Umożliwia dostęp do właściwości i metod udostępnianych przez obiekt.

(Odziedziczone po MemberInfo)
_MethodBase.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Zestaw nazw jest mapowany na odpowiedni zestaw identyfikatorów wysyłania.

(Odziedziczone po MethodBase)
_MethodBase.GetType()

Aby uzyskać opis tego elementu członkowskiego, zobacz GetType().

(Odziedziczone po MethodBase)
_MethodBase.GetTypeInfo(UInt32, UInt32, IntPtr)

Pobiera informacje o typie dla obiektu, których następnie można użyć do uzyskania informacji o typie interfejsu.

(Odziedziczone po MethodBase)
_MethodBase.GetTypeInfoCount(UInt32)

Pobiera informację o liczbie typów interfejsów, jakie zawiera obiekt (0 lub 1).

(Odziedziczone po MethodBase)
_MethodBase.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Umożliwia dostęp do właściwości i metod udostępnianych przez obiekt.

(Odziedziczone po MethodBase)
_MethodBase.IsAbstract

Aby uzyskać opis tego elementu członkowskiego, zobacz IsAbstract.

(Odziedziczone po MethodBase)
_MethodBase.IsAssembly

Aby uzyskać opis tego elementu członkowskiego, zobacz IsAssembly.

(Odziedziczone po MethodBase)
_MethodBase.IsConstructor

Aby uzyskać opis tego elementu członkowskiego, zobacz IsConstructor.

(Odziedziczone po MethodBase)
_MethodBase.IsFamily

Aby uzyskać opis tego elementu członkowskiego, zobacz IsFamily.

(Odziedziczone po MethodBase)
_MethodBase.IsFamilyAndAssembly

Aby uzyskać opis tego elementu członkowskiego, zobacz IsFamilyAndAssembly.

(Odziedziczone po MethodBase)
_MethodBase.IsFamilyOrAssembly

Aby uzyskać opis tego elementu członkowskiego, zobacz IsFamilyOrAssembly.

(Odziedziczone po MethodBase)
_MethodBase.IsFinal

Aby uzyskać opis tego elementu członkowskiego, zobacz IsFinal.

(Odziedziczone po MethodBase)
_MethodBase.IsHideBySig

Aby uzyskać opis tego elementu członkowskiego, zobacz IsHideBySig.

(Odziedziczone po MethodBase)
_MethodBase.IsPrivate

Aby uzyskać opis tego elementu członkowskiego, zobacz IsPrivate.

(Odziedziczone po MethodBase)
_MethodBase.IsPublic

Aby uzyskać opis tego elementu członkowskiego, zobacz IsPublic.

(Odziedziczone po MethodBase)
_MethodBase.IsSpecialName

Aby uzyskać opis tego elementu członkowskiego, zobacz IsSpecialName.

(Odziedziczone po MethodBase)
_MethodBase.IsStatic

Aby uzyskać opis tego elementu członkowskiego, zobacz IsStatic.

(Odziedziczone po MethodBase)
_MethodBase.IsVirtual

Aby uzyskać opis tego elementu członkowskiego, zobacz IsVirtual.

(Odziedziczone po MethodBase)
_MethodInfo.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Zestaw nazw jest mapowany na odpowiedni zestaw identyfikatorów wysyłania.

(Odziedziczone po MethodInfo)
_MethodInfo.GetType()

Zapewnia dostęp do GetType() metody z modelu COM.

(Odziedziczone po MethodInfo)
_MethodInfo.GetTypeInfo(UInt32, UInt32, IntPtr)

Pobiera informacje o typie obiektu, którego można użyć do pobrania informacji o typie interfejsu.

(Odziedziczone po MethodInfo)
_MethodInfo.GetTypeInfoCount(UInt32)

Pobiera informację o liczbie typów interfejsów, jakie zawiera obiekt (0 lub 1).

(Odziedziczone po MethodInfo)
_MethodInfo.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Umożliwia dostęp do właściwości i metod udostępnianych przez obiekt.

(Odziedziczone po MethodInfo)
ICustomAttributeProvider.GetCustomAttributes(Boolean)

Zwraca tablicę wszystkich atrybutów niestandardowych zdefiniowanych w tym elemencie członkowskim, z wyłączeniem nazwanych atrybutów lub pustą tablicą, jeśli nie ma atrybutów niestandardowych.

(Odziedziczone po MemberInfo)
ICustomAttributeProvider.GetCustomAttributes(Type, Boolean)

Zwraca tablicę atrybutów niestandardowych zdefiniowanych na tym elemencie członkowskim, identyfikowaną przez typ lub pustą tablicę, jeśli nie ma atrybutów niestandardowych tego typu.

(Odziedziczone po MemberInfo)
ICustomAttributeProvider.IsDefined(Type, Boolean)

Wskazuje, czy na tym elemencie członkowskim zdefiniowano jedno lub więcej wystąpień attributeType .

(Odziedziczone po MemberInfo)

Metody rozszerzania

GetCustomAttribute(MemberInfo, Type)

Pobiera atrybut niestandardowy określonego typu, który jest stosowany do określonego elementu członkowskiego.

GetCustomAttribute(MemberInfo, Type, Boolean)

Pobiera atrybut niestandardowy określonego typu, który jest stosowany do określonego elementu członkowskiego, i opcjonalnie sprawdza przodków tego elementu członkowskiego.

GetCustomAttribute<T>(MemberInfo)

Pobiera atrybut niestandardowy określonego typu, który jest stosowany do określonego elementu członkowskiego.

GetCustomAttribute<T>(MemberInfo, Boolean)

Pobiera atrybut niestandardowy określonego typu, który jest stosowany do określonego elementu członkowskiego, i opcjonalnie sprawdza przodków tego elementu członkowskiego.

GetCustomAttributes(MemberInfo)

Pobiera kolekcję atrybutów niestandardowych, które są stosowane do określonego elementu członkowskiego.

GetCustomAttributes(MemberInfo, Boolean)

Pobiera kolekcję atrybutów niestandardowych, które są stosowane do określonego elementu członkowskiego, i opcjonalnie sprawdza przodków tego elementu członkowskiego.

GetCustomAttributes(MemberInfo, Type)

Pobiera kolekcję atrybutów niestandardowych określonego typu, które są stosowane do określonego elementu członkowskiego.

GetCustomAttributes(MemberInfo, Type, Boolean)

Pobiera kolekcję atrybutów niestandardowych określonego typu, które są stosowane do określonego elementu członkowskiego, i opcjonalnie sprawdza przodków tego elementu członkowskiego.

GetCustomAttributes<T>(MemberInfo)

Pobiera kolekcję atrybutów niestandardowych określonego typu, które są stosowane do określonego elementu członkowskiego.

GetCustomAttributes<T>(MemberInfo, Boolean)

Pobiera kolekcję atrybutów niestandardowych określonego typu, które są stosowane do określonego elementu członkowskiego, i opcjonalnie sprawdza przodków tego elementu członkowskiego.

IsDefined(MemberInfo, Type)

Wskazuje, czy atrybuty niestandardowe określonego typu są stosowane do określonego elementu członkowskiego.

IsDefined(MemberInfo, Type, Boolean)

Wskazuje, czy atrybuty niestandardowe określonego typu są stosowane do określonego elementu członkowskiego i, opcjonalnie, stosowane do jego elementów nadrzędnych.

GetMetadataToken(MemberInfo)

Pobiera token metadanych dla danego elementu członkowskiego, jeśli jest dostępny.

HasMetadataToken(MemberInfo)

Zwraca wartość wskazującą, czy token metadanych jest dostępny dla określonego elementu członkowskiego.

GetBaseDefinition(MethodInfo)

Definiuje i reprezentuje metodę dynamiczną, którą można skompilować, wykonać i odrzucić. Metody odrzucone są dostępne w przypadku odzyskiwania pamięci.

GetRuntimeBaseDefinition(MethodInfo)

Pobiera obiekt reprezentujący określoną metodę w klasie bazowej bezpośredniej lub pośredniej, w której metoda została najpierw zadeklarowana.

Dotyczy

Zobacz też