DynamicMethod Classe

Definizione

Definisce e rappresenta un metodo dinamico che può essere compilato, eseguito e rimosso. I metodi eliminati sono disponibili per l'operazione di Garbage Collection.

public ref class DynamicMethod sealed : System::Reflection::MethodInfo
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class DynamicMethod : System.Reflection.MethodInfo
public sealed class DynamicMethod : System.Reflection.MethodInfo
[<System.Runtime.InteropServices.ComVisible(true)>]
type DynamicMethod = class
    inherit MethodInfo
type DynamicMethod = class
    inherit MethodInfo
Public NotInheritable Class DynamicMethod
Inherits MethodInfo
Ereditarietà
Attributi

Esempio

Nell'esempio di codice seguente viene creato un metodo dinamico che accetta due parametri. Nell'esempio viene generato un corpo di funzione semplice che stampa il primo parametro nella console e l'esempio usa il secondo parametro come valore restituito del metodo. L'esempio completa il metodo creando un delegato, richiama il delegato con parametri diversi e infine richiama il metodo dinamico usando il Invoke metodo .

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

Commenti

Per altre informazioni su questa API, vedere Osservazioni supplementari sull'API per DynamicMethod.

Costruttori

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

Crea un metodo dinamico globale per un modulo, specificando il nome del metodo, gli attributi, la convenzione di chiamata, il tipo restituito, i tipi di parametro, il modulo e se i controlli di visibilità JIT (Just-In-Time) devono essere ignorati per i tipi e i membri a cui accede il Microsoft linguaggio intermedio (MSIL) del metodo dinamico.

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

Crea un metodo dinamico, specificando il nome del metodo, gli attributi, la convenzione di chiamata, il tipo restituito, i tipi di parametro, il tipo a cui il metodo dinamico è associato logicamente e se i controlli di visibilità JIT (Just-In-Time) devono essere ignorati per i tipi e i membri a cui accede il linguaggio intermedio Microsoft del metodo dinamico.

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

Inizializza un metodo dinamico ospitato in modo anonimo, specificando il nome del metodo, il tipo restituito, i tipi di parametro e se i controlli di visibilità JIT (Just-In-Time) devono essere ignorati per i tipi e i membri a cui accede il Microsoft linguaggio intermedio (MSIL) del metodo dinamico.

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

Crea un metodo dinamico globale per un modulo, specificando il nome del metodo, il tipo restituito, i tipi di parametro, il modulo e se i controlli di visibilità JIT (Just-In-Time) devono essere ignorati per i tipi e i membri a cui accede il Microsoft linguaggio intermedio (MSIL) del metodo dinamico.

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

Crea un metodo dinamico globale per un modulo, specificando il nome del metodo, il tipo restituito, i tipi di parametro e il modulo.

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

Crea un metodo dinamico, specificando il nome del metodo, il tipo restituito, i tipi di parametro, il tipo a cui il metodo dinamico è associato logicamente e se i controlli di visibilità JIT (Just-In-Time) devono essere ignorati per i tipi e i membri a cui accede il Microsoft linguaggio intermedio (MSIL) del metodo dinamico.

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

Crea un metodo dinamico, specificando il nome del metodo, il tipo restituito, i tipi di parametro e il tipo con cui il metodo dinamico è associato logicamente.

DynamicMethod(String, Type, Type[])

Inizializza un metodo dinamico ospitato in modo anonimo, specificando il nome del metodo, il tipo restituito e i tipi di parametro.

Proprietà

Nome Descrizione
Attributes

Ottiene gli attributi specificati al momento della creazione del metodo dinamico.

CallingConvention

Ottiene la convenzione di chiamata specificata al momento della creazione del metodo dinamico.

ContainsGenericParameters

Ottiene un valore che indica se un metodo generico contiene parametri di tipo generico non assegnati.

(Ereditato da MethodInfo)
CustomAttributes

Ottiene una raccolta contenente gli attributi personalizzati di questo membro.

(Ereditato da MemberInfo)
DeclaringType

Ottiene il tipo che dichiara il metodo , che è sempre null per i metodi dinamici.

InitLocals

Ottiene o imposta un valore che indica se le variabili locali nel metodo sono inizializzate zero.

IsAbstract

Ottiene un valore che indica se il metodo è astratto.

(Ereditato da MethodBase)
IsAssembly

Ottiene un valore che indica se la visibilità potenziale di questo metodo o costruttore è descritta da Assembly, ovvero il metodo o il costruttore è visibile al massimo ad altri tipi nello stesso assembly e non è visibile ai tipi derivati all'esterno dell'assembly.

(Ereditato da MethodBase)
IsConstructedGenericMethod

Definisce e rappresenta un metodo dinamico che può essere compilato, eseguito e rimosso. I metodi eliminati sono disponibili per l'operazione di Garbage Collection.

(Ereditato da MethodBase)
IsConstructor

Ottiene un valore che indica se il metodo è un costruttore.

(Ereditato da MethodBase)
IsFamily

Ottiene un valore che indica se la visibilità di questo metodo o costruttore è descritta da Family, ovvero il metodo o il costruttore è visibile solo all'interno della classe e delle classi derivate.

(Ereditato da MethodBase)
IsFamilyAndAssembly

Ottiene un valore che indica se la visibilità di questo metodo o costruttore è descritta da FamANDAssem, ovvero il metodo o il costruttore può essere chiamato da classi derivate, ma solo se si trovano nello stesso assembly.

(Ereditato da MethodBase)
IsFamilyOrAssembly

Ottiene un valore che indica se la visibilità potenziale di questo metodo o costruttore è descritta da FamORAssem, ovvero il metodo o il costruttore può essere chiamato da classi derivate ovunque si trovino e da classi nello stesso assembly.

(Ereditato da MethodBase)
IsFinal

Ottiene un valore che indica se questo metodo è final.

(Ereditato da MethodBase)
IsGenericMethod

Ottiene un valore che indica se il metodo corrente è un metodo generico.

(Ereditato da MethodInfo)
IsGenericMethodDefinition

Ottiene un valore che indica se l'oggetto corrente MethodInfo rappresenta la definizione di un metodo generico.

(Ereditato da MethodInfo)
IsHideBySig

Ottiene un valore che indica se solo un membro dello stesso tipo con esattamente la stessa firma è nascosto nella classe derivata.

(Ereditato da MethodBase)
IsPrivate

Ottiene un valore che indica se il membro è privato.

(Ereditato da MethodBase)
IsPublic

Ottiene un valore che indica se si tratta di un metodo pubblico.

(Ereditato da MethodBase)
IsSecurityCritical

Ottiene un valore che indica se il metodo dinamico corrente è critico per la sicurezza o critico per la sicurezza e pertanto può eseguire operazioni critiche.

IsSecurityCritical

Ottiene un valore che indica se il metodo o il costruttore corrente è critico per la sicurezza o per la sicurezza a livello di attendibilità corrente e pertanto può eseguire operazioni critiche.

(Ereditato da MethodBase)
IsSecuritySafeCritical

Ottiene un valore che indica se il metodo dinamico corrente è critico per la sicurezza a livello di attendibilità corrente; ovvero se può eseguire operazioni critiche e può essere accessibile tramite codice trasparente.

IsSecuritySafeCritical

Ottiene un valore che indica se il metodo o il costruttore corrente è critico per la sicurezza a livello di attendibilità corrente; ovvero se può eseguire operazioni critiche e può essere accessibile tramite codice trasparente.

(Ereditato da MethodBase)
IsSecurityTransparent

Ottiene un valore che indica se il metodo dinamico corrente è trasparente a livello di trust corrente e pertanto non può eseguire operazioni critiche.

IsSecurityTransparent

Ottiene un valore che indica se il metodo o il costruttore corrente è trasparente a livello di trust corrente e pertanto non può eseguire operazioni critiche.

(Ereditato da MethodBase)
IsSpecialName

Ottiene un valore che indica se questo metodo ha un nome speciale.

(Ereditato da MethodBase)
IsStatic

Ottiene un valore che indica se il metodo è static.

(Ereditato da MethodBase)
IsVirtual

Ottiene un valore che indica se il metodo è virtual.

(Ereditato da MethodBase)
MemberType

Ottiene un MemberTypes valore che indica che questo membro è un metodo.

(Ereditato da MethodInfo)
MetadataToken

Ottiene un valore che identifica un elemento di metadati.

(Ereditato da MemberInfo)
MethodHandle

Non supportato per i metodi dinamici.

MethodImplementationFlags

Ottiene i MethodImplAttributes flag che specificano gli attributi di un'implementazione di un metodo.

(Ereditato da MethodBase)
Module

Ottiene il modulo a cui il metodo dinamico è associato logicamente.

Module

Ottiene il modulo in cui è definito il tipo che dichiara il membro rappresentato dall'oggetto corrente MemberInfo .

(Ereditato da MemberInfo)
Name

Ottiene il nome del metodo dinamico.

ReflectedType

Ottiene la classe utilizzata nella reflection per ottenere il metodo .

ReturnParameter

Ottiene il parametro restituito del metodo dinamico.

ReturnType

Ottiene il tipo di valore restituito per il metodo dinamico.

ReturnTypeCustomAttributes

Ottiene gli attributi personalizzati del tipo restituito per il metodo dinamico.

Metodi

Nome Descrizione
CreateDelegate(Type, Object)

Completa il metodo dinamico e crea un delegato che può essere usato per eseguirlo, specificando il tipo delegato e un oggetto a cui è associato il delegato.

CreateDelegate(Type)

Completa il metodo dinamico e crea un delegato che può essere usato per eseguirlo.

DefineParameter(Int32, ParameterAttributes, String)

Definisce un parametro del metodo dinamico.

Equals(Object)

Restituisce un valore che indica se questa istanza è uguale a un oggetto specificato.

(Ereditato da MethodInfo)
GetBaseDefinition()

Restituisce l'implementazione di base per il metodo .

GetCustomAttributes(Boolean)

Restituisce tutti gli attributi personalizzati definiti per il metodo .

GetCustomAttributes(Type, Boolean)

Restituisce gli attributi personalizzati del tipo specificato applicati al metodo .

GetCustomAttributesData()

Restituisce un elenco di CustomAttributeData oggetti che rappresentano i dati sugli attributi applicati al membro di destinazione.

(Ereditato da MemberInfo)
GetDynamicILInfo()

Restituisce un oggetto DynamicILInfo che può essere usato per generare un corpo del metodo da token di metadati, ambiti e Microsoft flussi MSIL (Intermediate Language).

GetGenericArguments()

Restituisce una matrice di Type oggetti che rappresentano gli argomenti di tipo di un metodo generico o i parametri di tipo di una definizione di metodo generico.

(Ereditato da MethodInfo)
GetGenericMethodDefinition()

Restituisce un MethodInfo oggetto che rappresenta una definizione di metodo generica da cui è possibile costruire il metodo corrente.

(Ereditato da MethodInfo)
GetHashCode()

Restituisce il codice hash per questa istanza.

(Ereditato da MethodInfo)
GetILGenerator()

Restituisce un generatore MSIL (Intermediate Language) Microsoft per il metodo con dimensioni predefinite del flusso MSIL di 64 byte.

GetILGenerator(Int32)

Restituisce un generatore MSIL (Intermediate Language) Microsoft per il metodo con le dimensioni del flusso MSIL specificate.

GetMethodBody()

In caso di override in una classe derivata, ottiene un MethodBody oggetto che fornisce l'accesso al flusso MSIL, alle variabili locali e alle eccezioni per il metodo corrente.

(Ereditato da MethodBase)
GetMethodImplementationFlags()

Restituisce i flag di implementazione per il metodo .

GetParameters()

Restituisce i parametri del metodo dinamico.

HasSameMetadataDefinitionAs(MemberInfo)

Definisce e rappresenta un metodo dinamico che può essere compilato, eseguito e rimosso. I metodi eliminati sono disponibili per l'operazione di Garbage Collection.

(Ereditato da MemberInfo)
Invoke(Object, BindingFlags, Binder, Object[], CultureInfo)

Richiama il metodo dinamico usando i parametri specificati, sotto i vincoli del binder specificato, con le informazioni sulle impostazioni cultura specificate.

IsDefined(Type, Boolean)

Indica se è definito il tipo di attributo personalizzato specificato.

MakeGenericMethod(Type[])

Sostituisce gli elementi di una matrice di tipi per i parametri di tipo della definizione del metodo generico corrente e restituisce un MethodInfo oggetto che rappresenta il metodo costruito risultante.

(Ereditato da MethodInfo)
MemberwiseClone()

Crea una copia superficiale del Objectcorrente.

(Ereditato da Object)
ToString()

Restituisce la firma del metodo, rappresentato come stringa.

Implementazioni dell'interfaccia esplicita

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

Esegue il mapping di un set di nomi a un set corrispondente di identificatori dispatch.

(Ereditato da MemberInfo)
_MemberInfo.GetType()

Ottiene un Type oggetto che rappresenta la MemberInfo classe .

(Ereditato da MemberInfo)
_MemberInfo.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera le informazioni sul tipo relative a un oggetto che può quindi essere usato per ottenere informazioni sul tipo relative a un'interfaccia.

(Ereditato da MemberInfo)
_MemberInfo.GetTypeInfoCount(UInt32)

Recupera il numero di interfacce di informazioni sul tipo fornite da un oggetto (0 o 1).

(Ereditato da MemberInfo)
_MemberInfo.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Fornisce l'accesso alle proprietà e ai metodi esposti da un oggetto .

(Ereditato da MemberInfo)
_MethodBase.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Esegue il mapping di un set di nomi a un set corrispondente di identificatori dispatch.

(Ereditato da MethodBase)
_MethodBase.GetType()

Per una descrizione di questo membro, vedere GetType().

(Ereditato da MethodBase)
_MethodBase.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera le informazioni sul tipo relative a un oggetto che può quindi essere usato per ottenere informazioni sul tipo relative a un'interfaccia.

(Ereditato da MethodBase)
_MethodBase.GetTypeInfoCount(UInt32)

Recupera il numero di interfacce di informazioni sul tipo fornite da un oggetto (0 o 1).

(Ereditato da MethodBase)
_MethodBase.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Fornisce l'accesso alle proprietà e ai metodi esposti da un oggetto .

(Ereditato da MethodBase)
_MethodBase.IsAbstract

Per una descrizione di questo membro, vedere IsAbstract.

(Ereditato da MethodBase)
_MethodBase.IsAssembly

Per una descrizione di questo membro, vedere IsAssembly.

(Ereditato da MethodBase)
_MethodBase.IsConstructor

Per una descrizione di questo membro, vedere IsConstructor.

(Ereditato da MethodBase)
_MethodBase.IsFamily

Per una descrizione di questo membro, vedere IsFamily.

(Ereditato da MethodBase)
_MethodBase.IsFamilyAndAssembly

Per una descrizione di questo membro, vedere IsFamilyAndAssembly.

(Ereditato da MethodBase)
_MethodBase.IsFamilyOrAssembly

Per una descrizione di questo membro, vedere IsFamilyOrAssembly.

(Ereditato da MethodBase)
_MethodBase.IsFinal

Per una descrizione di questo membro, vedere IsFinal.

(Ereditato da MethodBase)
_MethodBase.IsHideBySig

Per una descrizione di questo membro, vedere IsHideBySig.

(Ereditato da MethodBase)
_MethodBase.IsPrivate

Per una descrizione di questo membro, vedere IsPrivate.

(Ereditato da MethodBase)
_MethodBase.IsPublic

Per una descrizione di questo membro, vedere IsPublic.

(Ereditato da MethodBase)
_MethodBase.IsSpecialName

Per una descrizione di questo membro, vedere IsSpecialName.

(Ereditato da MethodBase)
_MethodBase.IsStatic

Per una descrizione di questo membro, vedere IsStatic.

(Ereditato da MethodBase)
_MethodBase.IsVirtual

Per una descrizione di questo membro, vedere IsVirtual.

(Ereditato da MethodBase)
_MethodInfo.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Esegue il mapping di un set di nomi a un set corrispondente di identificatori dispatch.

(Ereditato da MethodInfo)
_MethodInfo.GetType()

Fornisce l'accesso GetType() al metodo da COM.

(Ereditato da MethodInfo)
_MethodInfo.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera le informazioni sul tipo per un oggetto, che può essere utilizzato per ottenere le informazioni sul tipo per un'interfaccia.

(Ereditato da MethodInfo)
_MethodInfo.GetTypeInfoCount(UInt32)

Recupera il numero di interfacce di informazioni sul tipo fornite da un oggetto (0 o 1).

(Ereditato da MethodInfo)
_MethodInfo.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Fornisce l'accesso alle proprietà e ai metodi esposti da un oggetto .

(Ereditato da MethodInfo)

Metodi di estensione

Nome Descrizione
GetCustomAttribute(MemberInfo, Type, Boolean)

Recupera un attributo personalizzato di un tipo specificato applicato a un membro specificato e, facoltativamente, controlla i predecessori di tale membro.

GetCustomAttribute(MemberInfo, Type)

Recupera un attributo personalizzato di un tipo specificato applicato a un membro specificato.

GetCustomAttribute<T>(MemberInfo, Boolean)

Recupera un attributo personalizzato di un tipo specificato applicato a un membro specificato e, facoltativamente, controlla i predecessori di tale membro.

GetCustomAttribute<T>(MemberInfo)

Recupera un attributo personalizzato di un tipo specificato applicato a un membro specificato.

GetCustomAttributes(MemberInfo, Boolean)

Recupera una raccolta di attributi personalizzati applicati a un membro specificato e, facoltativamente, controlla i predecessori di tale membro.

GetCustomAttributes(MemberInfo, Type, Boolean)

Recupera una raccolta di attributi personalizzati di un tipo specificato applicato a un membro specificato e, facoltativamente, controlla i predecessori di tale membro.

GetCustomAttributes(MemberInfo, Type)

Recupera una raccolta di attributi personalizzati di un tipo specificato applicato a un membro specificato.

GetCustomAttributes(MemberInfo)

Recupera una raccolta di attributi personalizzati applicati a un membro specificato.

GetCustomAttributes<T>(MemberInfo, Boolean)

Recupera una raccolta di attributi personalizzati di un tipo specificato applicato a un membro specificato e, facoltativamente, controlla i predecessori di tale membro.

GetCustomAttributes<T>(MemberInfo)

Recupera una raccolta di attributi personalizzati di un tipo specificato applicato a un membro specificato.

GetRuntimeBaseDefinition(MethodInfo)

Recupera un oggetto che rappresenta il metodo specificato nella classe base diretta o indiretta in cui il metodo è stato dichiarato per la prima volta.

IsDefined(MemberInfo, Type, Boolean)

Indica se gli attributi personalizzati di un tipo specificato vengono applicati a un membro specificato e, facoltativamente, applicati ai relativi predecessori.

IsDefined(MemberInfo, Type)

Indica se gli attributi personalizzati di un tipo specificato vengono applicati a un membro specificato.

Si applica a

Vedi anche