DynamicMethod Třída

Definice

Definuje a představuje dynamickou metodu, kterou lze zkompilovat, spustit a zahodit. Pro uvolňování paměti jsou k dispozici zahozené metody.

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
Dědičnost
Atributy

Příklady

Následující příklad kódu vytvoří dynamickou metodu, která přijímá dva parametry. Příklad vygeneruje jednoduché tělo funkce, která vytiskne první parametr do konzoly, a příklad používá druhý parametr jako návratovou hodnotu metody. Příklad dokončí metodu vytvořením delegáta, vyvolá delegáta s různými parametry a nakonec vyvolá dynamickou metodu Invoke pomocí 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

Poznámky

Další informace o tomto rozhraní API najdete v tématu Doplňkové poznámky k rozhraní API pro DynamicMethod.

Konstruktory

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

Vytvoří dynamickou metodu, která je globální pro modul a určuje název metody, atributy, konvenci volání, návratový typ, typy parametrů, modul a zda mají být vynechány kontroly viditelnosti za běhu (JIT) pro typy a členy, ke kterým přistupuje jazyk MSIL (Microsoft Intermediate Language) dynamické metody.

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

Vytvoří dynamickou metodu s určením názvu metody, atributů, konvence volání, návratového typu, typů parametrů, typu, se kterým je dynamická metoda logicky přidružena, a zda mají být vynechány kontroly viditelnosti za běhu (JIT) pro typy a členy, ke kterým přistupuje jazyk MSIL (Microsoft Intermediate Language) dynamické metody.

DynamicMethod(String, Type, Type[])

Inicializuje anonymně hostované dynamické metody zadáním názvu metody, návratového typu a typů parametrů.

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

Inicializuje anonymně hostovanou dynamickou metodu zadáním názvu metody, návratového typu, typů parametrů a toho, zda mají být vynechány kontroly viditelnosti za běhu (JIT) pro typy a členy, ke které přistupuje jazyk MSIL (Microsoft Intermediate Language) dynamické metody.

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

Vytvoří dynamickou metodu, která je globální pro modul a určuje název metody, návratový typ, typy parametrů a modul.

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

Vytvoří dynamickou metodu, která je globální pro modul a určuje název metody, návratový typ, typy parametrů, modul a zda mají být vynechány kontroly viditelnosti za běhu (JIT) pro typy a členy, ke kterým přistupuje jazyk MSIL (Microsoft Intermediate Language) dynamické metody.

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

Vytvoří dynamickou metodu určující název metody, návratový typ, typy parametrů a typ, se kterým je dynamická metoda logicky přidružena.

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

Vytvoří dynamickou metodu s určením názvu metody, návratového typu, typů parametrů, typu, se kterým je dynamická metoda logicky přidružena, a zda by měly být vynechány kontroly viditelnosti za běhu (JIT) pro typy a členy, ke kterým přistupuje jazyk MSIL (Microsoft Intermediate Language) dynamické metody.

Vlastnosti

Attributes

Získá atributy zadané při vytvoření dynamické metody.

CallingConvention

Získá konvenci volání zadanou při vytvoření dynamické metody.

ContainsGenericParameters

Získá hodnotu, která označuje, zda obecná metoda obsahuje nepřiřazené parametry obecného typu.

(Zděděno od MethodInfo)
CustomAttributes

Získá kolekci, která obsahuje vlastní atributy tohoto člena.

(Zděděno od MemberInfo)
DeclaringType

Získá typ, který deklaruje metodu , která je vždy null pro dynamické metody.

InitLocals

Získá nebo nastaví hodnotu označující, zda místní proměnné v metodě jsou inicializovány nulou.

IsAbstract

Získá hodnotu označující, zda je metoda abstraktní.

(Zděděno od MethodBase)
IsAssembly

Získá hodnotu označující, zda potenciální viditelnost této metody nebo konstruktoru je popsána ; Assemblyto znamená, že metoda nebo konstruktor je viditelné nejvýše pro jiné typy ve stejném sestavení a není viditelné pro odvozené typy mimo sestavení.

(Zděděno od MethodBase)
IsCollectible

Získá hodnotu, která označuje, zda je tento MemberInfo objekt součástí sestavení uchovávaného v collectible AssemblyLoadContext.

(Zděděno od MemberInfo)
IsConstructedGenericMethod

Definuje a představuje dynamickou metodu, kterou lze zkompilovat, spustit a zahodit. Pro uvolňování paměti jsou k dispozici zahozené metody.

(Zděděno od MethodBase)
IsConstructor

Získá hodnotu označující, zda je metoda konstruktor.

(Zděděno od MethodBase)
IsFamily

Získá hodnotu označující, zda viditelnost této metody nebo konstruktoru je popsána ; Familyto znamená, že metoda nebo konstruktor je viditelná pouze v rámci své třídy a odvozené třídy.

(Zděděno od MethodBase)
IsFamilyAndAssembly

Získá hodnotu označující, zda viditelnost této metody nebo konstruktoru je popsána ; FamANDAssemto znamená, že metodu nebo konstruktor lze volat odvozenými třídami, ale pouze pokud jsou ve stejném sestavení.

(Zděděno od MethodBase)
IsFamilyOrAssembly

Získá hodnotu označující, zda potenciální viditelnost této metody nebo konstruktoru je popsána ; FamORAssemto znamená, že metoda nebo konstruktor mohou být volány odvozenými třídami bez ohledu na to, kde jsou, a třídami ve stejném sestavení.

(Zděděno od MethodBase)
IsFinal

Získá hodnotu označující, zda je finaltato metoda .

(Zděděno od MethodBase)
IsGenericMethod

Získá hodnotu označující, zda aktuální metoda je obecná metoda.

(Zděděno od MethodInfo)
IsGenericMethodDefinition

Získá hodnotu označující, zda aktuální MethodInfo představuje definici obecné metody.

(Zděděno od MethodInfo)
IsHideBySig

Získá hodnotu označující, zda je v odvozené třídě skrytý pouze člen stejného druhu s přesně stejným podpisem.

(Zděděno od MethodBase)
IsPrivate

Získá hodnotu označující, zda je tento člen soukromý.

(Zděděno od MethodBase)
IsPublic

Získá hodnotu označující, zda se jedná o veřejnou metodu.

(Zděděno od MethodBase)
IsSecurityCritical

Získá hodnotu, která označuje, zda aktuální dynamická metoda je kritické zabezpečení nebo zabezpečení-bezpečné-kritické, a proto může provádět kritické operace.

IsSecurityCritical

Získá hodnotu, která označuje, zda aktuální metoda nebo konstruktor je kritické zabezpečení nebo zabezpečení-bezpečné-kritické na aktuální úrovni důvěryhodnosti, a proto může provádět kritické operace.

(Zděděno od MethodBase)
IsSecuritySafeCritical

Získá hodnotu, která označuje, zda aktuální dynamická metoda je zabezpečení-bezpečné-kritické na aktuální úroveň důvěryhodnosti; to znamená, zda může provádět kritické operace a může být přístupný transparentním kódem.

IsSecuritySafeCritical

Získá hodnotu, která označuje, zda aktuální metoda nebo konstruktor je zabezpečení-bezpečné-kritické na aktuální úroveň důvěryhodnosti; to znamená, zda může provádět kritické operace a může být přístupný transparentním kódem.

(Zděděno od MethodBase)
IsSecurityTransparent

Získá hodnotu, která označuje, zda aktuální dynamická metoda je transparentní na aktuální úrovni důvěryhodnosti, a proto nelze provádět kritické operace.

IsSecurityTransparent

Získá hodnotu, která označuje, zda aktuální metoda nebo konstruktor je transparentní na aktuální úrovni důvěryhodnosti, a proto nelze provést kritické operace.

(Zděděno od MethodBase)
IsSpecialName

Získá hodnotu označující, zda má tato metoda zvláštní název.

(Zděděno od MethodBase)
IsStatic

Získá hodnotu označující, zda je staticmetoda .

(Zděděno od MethodBase)
IsVirtual

Získá hodnotu označující, zda je virtualmetoda .

(Zděděno od MethodBase)
MemberType

MemberTypes Získá hodnotu označující, že tento člen je metoda.

(Zděděno od MethodInfo)
MetadataToken

Získá hodnotu, která identifikuje prvek metadat.

(Zděděno od MemberInfo)
MethodHandle

Nepodporuje se pro dynamické metody.

MethodHandle

Získá popisovač pro reprezentaci interních metadat metody.

(Zděděno od MethodBase)
MethodImplementationFlags

Definuje a představuje dynamickou metodu, kterou lze zkompilovat, spustit a zahodit. Pro uvolňování paměti jsou k dispozici zahozené metody.

MethodImplementationFlags

MethodImplAttributes Získá příznaky, které určují atributy implementace metody.

(Zděděno od MethodBase)
Module

Získá modul, se kterým je dynamická metoda logicky přidružena.

Module

Získá modul, ve kterém je definován typ, který deklaruje člen reprezentovaný aktuální MemberInfo .

(Zděděno od MemberInfo)
Name

Získá název dynamické metody.

ReflectedType

Získá třídu, která byla použita v reflexi k získání metody.

ReflectedType

Získá objekt třídy, který byl použit k získání této instance .MemberInfo

(Zděděno od MemberInfo)
ReturnParameter

Získá návratové parametr dynamické metody.

ReturnType

Získá typ návratové hodnoty pro dynamickou metodu.

ReturnTypeCustomAttributes

Získá vlastní atributy návratového typu pro dynamickou metodu.

ReturnTypeCustomAttributes

Získá vlastní atributy návratového typu.

(Zděděno od MethodInfo)

Metody

CreateDelegate(Type)

Dokončí dynamickou metodu a vytvoří delegáta, který lze použít k jejímu spuštění.

CreateDelegate(Type, Object)

Dokončí dynamickou metodu a vytvoří delegáta, který lze použít k jejímu spuštění, a určí typ delegáta a objekt, ke kterému je delegát vázán.

CreateDelegate<T>()

Vytvoří delegáta typu T z této metody.

(Zděděno od MethodInfo)
CreateDelegate<T>(Object)

Vytvoří delegáta typu T se zadaným cílem z této metody.

(Zděděno od MethodInfo)
DefineParameter(Int32, ParameterAttributes, String)

Definuje parametr dynamické metody.

Equals(Object)

Vrací hodnotu, která určuje, zda je tato instance rovna zadanému objektu.

(Zděděno od MethodInfo)
GetBaseDefinition()

Vrátí základní implementaci pro metodu .

GetBaseDefinition()

Při přepsání v odvozené třídě vrátí MethodInfo objekt pro metodu na přímé nebo nepřímé základní třídě, ve které byla metoda reprezentovaná touto instancí poprvé deklarována.

(Zděděno od MethodInfo)
GetCustomAttributes(Boolean)

Vrátí všechny vlastní atributy definované pro metodu .

GetCustomAttributes(Boolean)

Při přepsání v odvozené třídě vrátí pole všech vlastních atributů použitých pro tento člen.

(Zděděno od MemberInfo)
GetCustomAttributes(Type, Boolean)

Vrátí vlastní atributy zadaného typu, které byly použity pro metodu .

GetCustomAttributes(Type, Boolean)

Při přepsání v odvozené třídě vrátí pole vlastních atributů použitých u tohoto člena a identifikovaných pomocí Type.

(Zděděno od MemberInfo)
GetCustomAttributesData()

Vrátí seznam CustomAttributeData objektů představujících data o atributech, které byly použity na cílového člena.

(Zděděno od MemberInfo)
GetDynamicILInfo()

DynamicILInfo Vrátí objekt, který lze použít k vygenerování těla metody z tokenů metadat, oborů a datových proudů jazyka MSIL (Microsoft Intermediate Language).

GetGenericArguments()

Vrátí pole Type objektů, které představují argumenty typu obecné metody nebo parametry typu definice obecné metody.

(Zděděno od MethodInfo)
GetGenericMethodDefinition()

MethodInfo Vrátí objekt, který představuje obecnou definici metody, ze které lze vytvořit aktuální metodu.

(Zděděno od MethodInfo)
GetHashCode()

Vrátí hodnotu hash pro tuto instanci.

(Zděděno od MethodInfo)
GetILGenerator()

Vrátí generátor jazyka MSIL (Microsoft Intermediate Language) pro metodu s výchozí velikostí streamu MSIL 64 bajtů.

GetILGenerator(Int32)

Vrátí generátor jazyka MSIL (Microsoft Intermediate Language) pro metodu se zadanou velikostí streamu MSIL.

GetMethodBody()

Při přepsání v odvozené třídě získá MethodBody objekt, který poskytuje přístup k datovému proudu MSIL, místní proměnné a výjimky pro aktuální metodu.

(Zděděno od MethodBase)
GetMethodImplementationFlags()

Vrátí příznaky implementace pro metodu .

GetMethodImplementationFlags()

Při přepsání v odvozené třídě vrátí MethodImplAttributes příznaky.

(Zděděno od MethodBase)
GetParameters()

Vrátí parametry dynamické metody.

GetType()

Zjistí atributy metody a poskytuje přístup k metadatům metody.

(Zděděno od MethodInfo)
HasSameMetadataDefinitionAs(MemberInfo)

Definuje a představuje dynamickou metodu, kterou lze zkompilovat, spustit a zahodit. Pro uvolňování paměti jsou k dispozici zahozené metody.

(Zděděno od MemberInfo)
Invoke(Object, BindingFlags, Binder, Object[], CultureInfo)

Vyvolá dynamickou metodu pomocí zadaných parametrů v rámci omezení zadaného pořadače se zadanými informacemi o jazykové verzi.

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

Při přepsání v odvozené třídě vyvolá reflektované metody nebo konstruktoru s danými parametry.

(Zděděno od MethodBase)
Invoke(Object, Object[])

Vyvolá metodu nebo konstruktor reprezentovaný aktuální instancí pomocí zadaných parametrů.

(Zděděno od MethodInfo)
IsDefined(Type, Boolean)

Určuje, jestli je definovaný typ vlastního atributu.

IsDefined(Type, Boolean)

Při přepsání v odvozené třídě, označuje, zda jeden nebo více atributů zadaného typu nebo jeho odvozených typů je použito na tento člen.

(Zděděno od MemberInfo)
MakeGenericMethod(Type[])

Nahradí prvky pole typů parametry typu aktuální definice obecné metody a vrátí MethodInfo objekt představující výslednou vytvořenou metodu.

(Zděděno od MethodInfo)
MemberwiseClone()

Vytvoří mělkou kopii aktuálního Objectsouboru .

(Zděděno od Object)
ToString()

Vrátí signaturu metody reprezentovanou jako řetězec.

Explicitní implementace rozhraní

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

Mapuje sadu názvů na odpovídající sadu identifikátorů pro rozesílání.

(Zděděno od MemberInfo)
_MemberInfo.GetType()

Type Získá objekt představující MemberInfo třídu .

(Zděděno od MemberInfo)
_MemberInfo.GetTypeInfo(UInt32, UInt32, IntPtr)

Načte informace o typu objektu, který lze použít k získání informací o typu pro rozhraní.

(Zděděno od MemberInfo)
_MemberInfo.GetTypeInfoCount(UInt32)

Získá počet rozhraní typu informací, které objekt poskytuje (0 nebo 1).

(Zděděno od MemberInfo)
_MemberInfo.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Poskytuje přístup k vlastnostem a metodám vystaveným objektem.

(Zděděno od MemberInfo)
_MethodBase.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Mapuje sadu názvů na odpovídající sadu identifikátorů pro rozesílání.

(Zděděno od MethodBase)
_MethodBase.GetType()

Popis tohoto člena najdete v tématu GetType().

(Zděděno od MethodBase)
_MethodBase.GetTypeInfo(UInt32, UInt32, IntPtr)

Načte informace o typu objektu, který lze použít k získání informací o typu pro rozhraní.

(Zděděno od MethodBase)
_MethodBase.GetTypeInfoCount(UInt32)

Získá počet rozhraní typu informací, které objekt poskytuje (0 nebo 1).

(Zděděno od MethodBase)
_MethodBase.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Poskytuje přístup k vlastnostem a metodám vystaveným objektem.

(Zděděno od MethodBase)
_MethodBase.IsAbstract

Popis tohoto člena najdete v tématu IsAbstract.

(Zděděno od MethodBase)
_MethodBase.IsAssembly

Popis tohoto člena najdete v tématu IsAssembly.

(Zděděno od MethodBase)
_MethodBase.IsConstructor

Popis tohoto člena najdete v tématu IsConstructor.

(Zděděno od MethodBase)
_MethodBase.IsFamily

Popis tohoto člena najdete v tématu IsFamily.

(Zděděno od MethodBase)
_MethodBase.IsFamilyAndAssembly

Popis tohoto člena najdete v tématu IsFamilyAndAssembly.

(Zděděno od MethodBase)
_MethodBase.IsFamilyOrAssembly

Popis tohoto člena najdete v tématu IsFamilyOrAssembly.

(Zděděno od MethodBase)
_MethodBase.IsFinal

Popis tohoto člena najdete v tématu IsFinal.

(Zděděno od MethodBase)
_MethodBase.IsHideBySig

Popis tohoto člena najdete v tématu IsHideBySig.

(Zděděno od MethodBase)
_MethodBase.IsPrivate

Popis tohoto člena najdete v tématu IsPrivate.

(Zděděno od MethodBase)
_MethodBase.IsPublic

Popis tohoto člena najdete v tématu IsPublic.

(Zděděno od MethodBase)
_MethodBase.IsSpecialName

Popis tohoto člena najdete v tématu IsSpecialName.

(Zděděno od MethodBase)
_MethodBase.IsStatic

Popis tohoto člena najdete v tématu IsStatic.

(Zděděno od MethodBase)
_MethodBase.IsVirtual

Popis tohoto člena najdete v tématu IsVirtual.

(Zděděno od MethodBase)
_MethodInfo.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Mapuje sadu názvů na odpovídající sadu identifikátorů pro rozesílání.

(Zděděno od MethodInfo)
_MethodInfo.GetType()

Poskytuje přístup k GetType() metodě z modelu COM.

(Zděděno od MethodInfo)
_MethodInfo.GetTypeInfo(UInt32, UInt32, IntPtr)

Načte informace o typu objektu, které lze použít k získání informací o typu pro rozhraní.

(Zděděno od MethodInfo)
_MethodInfo.GetTypeInfoCount(UInt32)

Získá počet rozhraní typu informací, které objekt poskytuje (0 nebo 1).

(Zděděno od MethodInfo)
_MethodInfo.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Poskytuje přístup k vlastnostem a metodám vystaveným objektem.

(Zděděno od MethodInfo)
ICustomAttributeProvider.GetCustomAttributes(Boolean)

Vrátí pole všech vlastních atributů definovaných v tomto členu, s výjimkou pojmenovaných atributů, nebo prázdné pole, pokud neexistují žádné vlastní atributy.

(Zděděno od MemberInfo)
ICustomAttributeProvider.GetCustomAttributes(Type, Boolean)

Vrátí pole vlastních atributů definovaných v tomto členu, identifikované typem nebo prázdné pole, pokud neexistují žádné vlastní atributy tohoto typu.

(Zděděno od MemberInfo)
ICustomAttributeProvider.IsDefined(Type, Boolean)

Určuje, zda je u tohoto člena attributeType definována jedna nebo více instancí.

(Zděděno od MemberInfo)

Metody rozšíření

GetCustomAttribute(MemberInfo, Type)

Načte vlastní atribut zadaného typu, který je použit na zadaný člen.

GetCustomAttribute(MemberInfo, Type, Boolean)

Načte vlastní atribut zadaného typu, který je použit na zadaný člen, a volitelně zkontroluje předky tohoto člena.

GetCustomAttribute<T>(MemberInfo)

Načte vlastní atribut zadaného typu, který je použit na zadaný člen.

GetCustomAttribute<T>(MemberInfo, Boolean)

Načte vlastní atribut zadaného typu, který je použit na zadaný člen, a volitelně zkontroluje předky tohoto člena.

GetCustomAttributes(MemberInfo)

Načte kolekci vlastních atributů, které jsou použity na zadaného člena.

GetCustomAttributes(MemberInfo, Boolean)

Načte kolekci vlastních atributů, které jsou použity na zadaného člena, a volitelně zkontroluje předky tohoto člena.

GetCustomAttributes(MemberInfo, Type)

Načte kolekci vlastních atributů zadaného typu, které jsou použity na zadaného člena.

GetCustomAttributes(MemberInfo, Type, Boolean)

Načte kolekci vlastních atributů zadaného typu, které jsou použity na zadaného člena, a volitelně zkontroluje předky tohoto člena.

GetCustomAttributes<T>(MemberInfo)

Načte kolekci vlastních atributů zadaného typu, které jsou použity na zadaného člena.

GetCustomAttributes<T>(MemberInfo, Boolean)

Načte kolekci vlastních atributů zadaného typu, které jsou použity na zadaného člena, a volitelně zkontroluje předky tohoto člena.

IsDefined(MemberInfo, Type)

Určuje, zda jsou na zadaný člen použity vlastní atributy zadaného typu.

IsDefined(MemberInfo, Type, Boolean)

Určuje, zda vlastní atributy zadaného typu jsou použity na zadaného člena a volitelně použity na jeho nadřazené položky.

GetMetadataToken(MemberInfo)

Získá token metadat pro daný člen, pokud je k dispozici.

HasMetadataToken(MemberInfo)

Vrátí hodnotu, která označuje, zda je token metadat k dispozici pro zadaného člena.

GetBaseDefinition(MethodInfo)

Definuje a představuje dynamickou metodu, kterou lze zkompilovat, spustit a zahodit. Pro uvolňování paměti jsou k dispozici zahozené metody.

GetRuntimeBaseDefinition(MethodInfo)

Načte objekt, který představuje zadanou metodu na přímé nebo nepřímé základní třídě, kde byla metoda poprvé deklarována.

Platí pro

Viz také