DynamicMethod Costruttori

Definizione

Crea un metodo dinamico.

Overload

DynamicMethod(String, Type, Type[])

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

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

Inizializza un metodo dinamico ospitato anonimamente, specificando il nome del metodo, il tipo restituito, i tipi di parametro e se i controlli di visibilità JIT possono essere ignorati per i tipi e i membri cui accede il linguaggio MSIL (Microsoft Intermediate Language) del metodo dinamico.

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

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

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

Crea un metodo dinamico, specificando il nome del metodo, il tipo restituito, i parametri di tipo e il tipo a cui il metodo dinamico è associato dal punto di vista logico.

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 parametri e il modulo e indicando se deve essere ignorato il controllo di visibilità JIT per i tipi e i membri del metodo dinamico a cui accede MSIL (Microsoft Intermediate Language).

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 in modo logico e se i controlli di visibilità JIT possono essere ignorati per i tipi e i membri cui accede il linguaggio MSIL (Microsoft Intermediate Language) del metodo dinamico.

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

Crea un metodo dinamico globale per un metodo, 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 possono essere ignorati per i tipi e i membri cui accede il linguaggio MSIL (Microsoft Intermediate Language) 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 in modo logico e se i controlli di visibilità JIT possono essere ignorati per i tipi e i membri cui accede il linguaggio MSIL (Microsoft Intermediate Language) del metodo dinamico.

DynamicMethod(String, Type, Type[])

Source:
DynamicMethod.cs
Source:
DynamicMethod.cs
Source:
DynamicMethod.cs

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

public:
 DynamicMethod(System::String ^ name, Type ^ returnType, cli::array <Type ^> ^ parameterTypes);
public DynamicMethod (string name, Type? returnType, Type[]? parameterTypes);
public DynamicMethod (string name, Type returnType, Type[] parameterTypes);
new System.Reflection.Emit.DynamicMethod : string * Type * Type[] -> System.Reflection.Emit.DynamicMethod
Public Sub New (name As String, returnType As Type, parameterTypes As Type())

Parametri

name
String

Nome del metodo dinamico. Può essere una stringa di lunghezza zero, ma non può essere null.

returnType
Type

Oggetto Type che specifica il tipo restituito del metodo dinamico oppure null se per il metodo non esiste alcun tipo restituito.

parameterTypes
Type[]

Matrice di oggetti Type che specifica i tipi dei parametri del metodo dinamico oppure null se per il metodo non esistono parametri.

Eccezioni

Un elemento di parameterTypes è null o Void.

name è null.

.NET Framework e versioni di .NET Core precedenti alla 2.1: returnType è un tipo per il quale IsByRef restituisce true.

Commenti

Il metodo dinamico creato da questo costruttore è associato a un assembly anonimo anziché a un tipo o a un modulo esistente. L'assembly anonimo esiste solo per fornire un ambiente sandbox per i metodi dinamici, ovvero per isolarli da altro codice. Questo ambiente rende sicuro che il metodo dinamico venga generato ed eseguito da codice parzialmente attendibile.

Questo costruttore specifica che i controlli di visibilità JIT (Just-In-Time) verranno applicati per il linguaggio MSIL (Microsoft Intermediate Language) del metodo dinamico. Ovvero, il codice nel metodo dinamico ha accesso ai metodi pubblici delle classi pubbliche. Le eccezioni vengono generate se il metodo tenta di accedere a tipi o membri che sono private, protectedo internal (Friend in Visual Basic). Per creare un metodo dinamico con possibilità limitata di ignorare i controlli di visibilità JIT, usare il DynamicMethod(String, Type, Type[], Boolean) costruttore .

Quando viene costruito un metodo dinamico ospitato in modo anonimo, viene incluso lo stack di chiamate dell'assembly di creazione. Quando il metodo viene richiamato, vengono usate le autorizzazioni dell'assembly di creazione anziché le autorizzazioni del chiamante effettivo. Pertanto, il metodo dinamico non può essere eseguito a un livello di privilegio superiore a quello dell'assembly che lo ha generato, anche se viene passato ed eseguito da un assembly con un livello di attendibilità superiore.

Questo costruttore specifica gli attributi MethodAttributes.Public del metodo e MethodAttributes.Statice la convenzione di chiamata CallingConventions.Standard.

Nota

Questo costruttore è stato introdotto in .NET Framework 3.5 o versione successiva.

Vedi anche

Si applica a

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

Source:
DynamicMethod.cs
Source:
DynamicMethod.cs
Source:
DynamicMethod.cs

Inizializza un metodo dinamico ospitato anonimamente, specificando il nome del metodo, il tipo restituito, i tipi di parametro e se i controlli di visibilità JIT possono essere ignorati per i tipi e i membri cui accede il linguaggio MSIL (Microsoft Intermediate Language) del metodo dinamico.

public:
 DynamicMethod(System::String ^ name, Type ^ returnType, cli::array <Type ^> ^ parameterTypes, bool restrictedSkipVisibility);
public DynamicMethod (string name, Type? returnType, Type[]? parameterTypes, bool restrictedSkipVisibility);
public DynamicMethod (string name, Type returnType, Type[] parameterTypes, bool restrictedSkipVisibility);
new System.Reflection.Emit.DynamicMethod : string * Type * Type[] * bool -> System.Reflection.Emit.DynamicMethod
Public Sub New (name As String, returnType As Type, parameterTypes As Type(), restrictedSkipVisibility As Boolean)

Parametri

name
String

Nome del metodo dinamico. Può essere una stringa di lunghezza zero, ma non può essere null.

returnType
Type

Oggetto Type che specifica il tipo restituito del metodo dinamico oppure null se per il metodo non esiste alcun tipo restituito.

parameterTypes
Type[]

Matrice di oggetti Type che specifica i tipi dei parametri del metodo dinamico oppure null se per il metodo non esistono parametri.

restrictedSkipVisibility
Boolean

true per ignorare i controlli di visibilità JIT sui tipi e i membri a cui accede il linguaggio MSIL del metodo dinamico, con questa restrizione: il livello di attendibilità degli assembly che contengono questi tipi e membri deve essere uguale o minore di quello dello stack di chiamata che genera il metodo dinamico; in caso contrario, false.

Eccezioni

Un elemento di parameterTypes è null o Void.

name è null.

.NET Framework e versioni di .NET Core precedenti alla 2.1: returnType è un tipo per il quale IsByRef restituisce true.

Commenti

Il metodo dinamico creato da questo costruttore è associato a un assembly anonimo anziché a un tipo o a un modulo esistente. L'assembly anonimo esiste solo per fornire un ambiente sandbox per i metodi dinamici, ovvero per isolarli da altro codice. Questo ambiente rende sicuro che il metodo dinamico venga generato ed eseguito da codice parzialmente attendibile.

I metodi dinamici ospitati in modo anonimo non hanno accesso automatico ad alcun tipo o membro , privateprotectedo internal (Friend in Visual Basic). Ciò è diverso dai metodi dinamici associati a un tipo o a un modulo esistente, che hanno accesso ai membri nascosti nell'ambito associato.

Specificare true per restrictedSkipVisibility se il metodo dinamico deve accedere a tipi o membri che sono private, protectedo internal. In questo modo, il metodo dinamico ha accesso limitato a questi membri. Ovvero, è possibile accedere ai membri solo se vengono soddisfatte le condizioni seguenti:

  • I membri di destinazione appartengono a un assembly con un livello di attendibilità uguale o inferiore allo stack di chiamate che genera il metodo dinamico.

  • Lo stack di chiamate che genera il metodo dinamico viene concesso ReflectionPermission con il ReflectionPermissionFlag.RestrictedMemberAccess flag . Questo vale sempre quando il codice viene eseguito con attendibilità totale. Per il codice parzialmente attendibile, è true solo se l'host concede in modo esplicito l'autorizzazione.

    Importante

    Se l'autorizzazione non è stata concessa, viene generata un'eccezione di sicurezza quando CreateDelegate viene chiamata o quando viene richiamato il metodo dinamico, non quando viene chiamato questo costruttore. Non sono necessarie autorizzazioni speciali per generare il metodo dinamico.

Ad esempio, un metodo dinamico creato con restrictedSkipVisibility impostato su può accedere a true un membro privato di qualsiasi assembly nello stack di chiamate se allo stack di chiamate è stato concesso l'accesso ai membri con restrizioni. Se il metodo dinamico viene creato con codice parzialmente attendibile nello stack di chiamate, non può accedere a un membro privato di un tipo in un assembly .NET Framework, perché tali assembly sono completamente attendibili.

Se restrictedSkipVisibility è false, vengono applicati i controlli di visibilità JIT. Il codice nel metodo dinamico ha accesso ai metodi pubblici delle classi pubbliche e le eccezioni vengono generate se tenta di accedere a tipi o membri che sono private, protectedo internal.

Quando viene costruito un metodo dinamico ospitato in modo anonimo, viene incluso lo stack di chiamate dell'assembly di creazione. Quando il metodo viene richiamato, vengono usate le autorizzazioni dello stack di chiamate di emissione anziché le autorizzazioni del chiamante effettivo. Pertanto, il metodo dinamico non può essere eseguito a un livello di privilegio superiore a quello dell'assembly che lo ha generato, anche se viene passato ed eseguito da un assembly con un livello di attendibilità superiore.

Questo costruttore specifica gli attributi MethodAttributes.Public del metodo e MethodAttributes.Statice la convenzione di chiamata CallingConventions.Standard.

Nota

Questo costruttore è stato introdotto in .NET Framework 3.5 o versione successiva.

Vedi anche

Si applica a

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

Source:
DynamicMethod.cs
Source:
DynamicMethod.cs
Source:
DynamicMethod.cs

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

public:
 DynamicMethod(System::String ^ name, Type ^ returnType, cli::array <Type ^> ^ parameterTypes, System::Reflection::Module ^ m);
public DynamicMethod (string name, Type? returnType, Type[]? parameterTypes, System.Reflection.Module m);
public DynamicMethod (string name, Type returnType, Type[] parameterTypes, System.Reflection.Module m);
new System.Reflection.Emit.DynamicMethod : string * Type * Type[] * System.Reflection.Module -> System.Reflection.Emit.DynamicMethod
Public Sub New (name As String, returnType As Type, parameterTypes As Type(), m As Module)

Parametri

name
String

Nome del metodo dinamico. Può essere una stringa di lunghezza zero, ma non può essere null.

returnType
Type

Oggetto Type che specifica il tipo restituito del metodo dinamico oppure null se per il metodo non esiste alcun tipo restituito.

parameterTypes
Type[]

Matrice di oggetti Type che specifica i tipi dei parametri del metodo dinamico oppure null se per il metodo non esistono parametri.

m
Module

Oggetto Module che rappresenta il modulo a cui il metodo dinamico deve essere associato in modo logico.

Eccezioni

Un elemento di parameterTypes è null o Void.

-oppure-

m è un modulo che fornisce hosting anonimo per i metodi dinamici.

name è null.

-oppure-

m è null.

.NET Framework e versioni di .NET Core precedenti alla 2.1: returnType è un tipo per il quale IsByRef restituisce true.

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 nell'esempio viene usato 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(Object, BindingFlags, Binder, Object[], CultureInfo) metodo .

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

public ref class Test
{   
};

// Declare a delegate that will be used to execute the completed
// dynamic method.
delegate int HelloInvoker(String^ msg, int ret);

int main()
{
    // Create an array that specifies the types of the parameters
    // of the dynamic method. This method has a string parameter
    // and an int parameter.
    array<Type^>^ helloArgs = {String::typeid, int::typeid};

    // Create a dynamic method with the name "Hello", a return type
    // of int, and two parameters whose types are specified by the
    // array helloArgs. Create the method in the module that
    // defines the Test class.
    DynamicMethod^ hello = gcnew DynamicMethod("Hello", 
        int::typeid,
        helloArgs,
        Test::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.
    ILGenerator^ ilgen = hello->GetILGenerator();
    // Load the first argument, which is a string, onto the stack.
    ilgen->Emit(OpCodes::Ldarg_0);
    // Call the overload of Console.WriteLine that prints a string.
    ilgen->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.
    ilgen->Emit(OpCodes::Ldarg_1);
    ilgen->Emit(OpCodes::Ret);

    // Create a delegate that represents the dynamic method. This
    // action completes the method, and any further attempts to
    // change the method will cause an exception.
    HelloInvoker^ helloDelegate =
        (HelloInvoker^) hello->CreateDelegate(HelloInvoker::typeid);

    // Use the delegate to execute the dynamic method. Save and
    // print the return value.
    int returnValue = helloDelegate("\r\nHello, World!", 42);
    Console::WriteLine("helloDelegate(\"Hello, World!\", 42) returned {0}",
        returnValue);

    // Do it again, with different arguments.
    returnValue = helloDelegate("\r\nHi, Mom!", 5280);
    Console::WriteLine("helloDelegate(\"Hi, Mom!\", 5280) returned {0}",
        returnValue);

    // Create an array of arguments to use with the Invoke method.
    array<Object^>^ delegateArgs = {"\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 ValueType arguments
    // must be boxed.
    Object^ returnValueObject = hello->Invoke(nullptr, delegateArgs);
    Console::WriteLine("hello.Invoke returned {0}", returnValueObject);
}
using System;
using System.Reflection;
using System.Reflection.Emit;
using Microsoft.VisualBasic;

public class Test
{
    // Declare a delegate that will be used to execute the completed
    // dynamic method.
    private delegate int HelloInvoker(string msg, int ret);

    public static void Main()
    {
        // Create an array that specifies the types of the parameters
        // of the dynamic method. This method has a string parameter
        // and an int parameter.
        Type[] helloArgs = {typeof(string), typeof(int)};

        // Create a dynamic method with the name "Hello", a return type
        // of int, and two parameters whose types are specified by the
        // array helloArgs. Create the method in the module that
        // defines the Test class.
        DynamicMethod hello = new DynamicMethod("Hello",
            typeof(int),
            helloArgs,
            typeof(Test).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.
        ILGenerator il = hello.GetILGenerator();
        // 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);

        // Create a delegate that represents the dynamic method. This
        // action completes the method, and any further attempts to
        // change the method will cause an exception.
        HelloInvoker hi =
            (HelloInvoker) hello.CreateDelegate(typeof(HelloInvoker));

        // Use the delegate to execute the dynamic method. Save and
        // print the return value.
        int retval = hi("\r\nHello, World!", 42);
        Console.WriteLine("Executing delegate hi(\"Hello, World!\", 42) returned {0}",
            retval);

        // Do it again, with different arguments.
        retval = hi("\r\nHi, Mom!", 5280);
        Console.WriteLine("Executing delegate hi(\"Hi, Mom!\", 5280) returned {0}",
            retval);

        // 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 ValueType arguments
        // must be boxed.
        object objRet = hello.Invoke(null, invokeArgs);
        Console.WriteLine("hello.Invoke returned {0}", objRet);
    }
}
Imports System.Reflection
Imports System.Reflection.Emit

Public Class Test
    ' Declare a delegate that will be used to execute the completed
    ' dynamic method. 
    Private Delegate Function HelloInvoker(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 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 Test class.
        Dim hello As New DynamicMethod("Hello", _
            GetType(Integer), _
            helloArgs, _
            GetType(Test).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.
        Dim il As ILGenerator = hello.GetILGenerator()
        ' 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)

        ' Create a delegate that represents the dynamic method. This
        ' action completes the method, and any further attempts to
        ' change the method will cause an exception.
    Dim hi As HelloInvoker = _
            hello.CreateDelegate(GetType(HelloInvoker))

        ' Use the delegate to execute the dynamic method. Save and
        ' print the return value.
        Dim retval As Integer = hi(vbCrLf & "Hello, World!", 42)
        Console.WriteLine("Executing delegate hi(""Hello, World!"", 42) returned " _
            & retval)

        ' Do it again, with different arguments.
        retval = hi(vbCrLf & "Hi, Mom!", 5280)
        Console.WriteLine("Executing delegate hi(""Hi, Mom!"", 5280) returned " _
            & retval)

        ' 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 ValueType arguments
        ' must be boxed. Note that this overload of Invoke is 
        ' inherited from MethodBase, and simply calls the more 
        ' complete overload of Invoke.
        Dim objRet As Object = hello.Invoke(Nothing, invokeArgs)
        Console.WriteLine("hello.Invoke returned " & objRet)
    End Sub
End Class

' This code example produces the following output:
'
'Hello, World!
'Executing delegate hi("Hello, World!", 42) returned 42
'
'Hi, Mom!
'Executing delegate hi("Hi, Mom!", 5280) returned 5280
'
'Hello, World!
'hello.Invoke returned 42
'

Commenti

Questo costruttore specifica gli attributi del metodo e , la convenzione di chiamata e non ignora i controlli di visibilità JIT .This constructor specifies method attributes MethodAttributes.Public and MethodAttributes.Static, calling convention CallingConventions.Standard, and not skip just-in-time (JIT) visibility checks.

Il metodo dinamico creato con questo costruttore ha accesso a membri pubblici e internal (Friend in Visual Basic) di tutti i tipi contenuti nel modulo m.

Nota

Per la compatibilità con le versioni precedenti, questo costruttore richiede SecurityPermission il SecurityPermissionFlag.ControlEvidence flag se le condizioni seguenti sono entrambe vere: m è un modulo diverso dal modulo chiamante e la richiesta di ReflectionPermission con il ReflectionPermissionFlag.MemberAccess flag non è riuscita. Se la richiesta di SecurityPermission esito positivo, l'operazione è consentita.

Vedi anche

Si applica a

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

Source:
DynamicMethod.cs
Source:
DynamicMethod.cs
Source:
DynamicMethod.cs

Crea un metodo dinamico, specificando il nome del metodo, il tipo restituito, i parametri di tipo e il tipo a cui il metodo dinamico è associato dal punto di vista logico.

public:
 DynamicMethod(System::String ^ name, Type ^ returnType, cli::array <Type ^> ^ parameterTypes, Type ^ owner);
public DynamicMethod (string name, Type? returnType, Type[]? parameterTypes, Type owner);
public DynamicMethod (string name, Type returnType, Type[] parameterTypes, Type owner);
new System.Reflection.Emit.DynamicMethod : string * Type * Type[] * Type -> System.Reflection.Emit.DynamicMethod
Public Sub New (name As String, returnType As Type, parameterTypes As Type(), owner As Type)

Parametri

name
String

Nome del metodo dinamico. Può essere una stringa di lunghezza zero, ma non può essere null.

returnType
Type

Oggetto Type che specifica il tipo restituito del metodo dinamico oppure null se per il metodo non esiste alcun tipo restituito.

parameterTypes
Type[]

Matrice di oggetti Type che specifica i tipi dei parametri del metodo dinamico oppure null se per il metodo non esistono parametri.

owner
Type

Oggetto Type a cui il metodo dinamico è associato in modo logico. Il metodo dinamico ha accesso a tutti i membri del tipo.

Eccezioni

Un elemento di parameterTypes è null o Void.

-oppure-

owner è un'interfaccia, una matrice, un tipo generico aperto o un parametro di tipo di un tipo o un metodo generico.

name è null.

-oppure-

owner è null.

.NET Framework e versioni di .NET Core precedenti alla versione 2.1: returnType è un tipo per cui IsByRef restituisce true.

Esempio

Nell'esempio di codice seguente viene creato un oggetto DynamicMethod associato logicamente a un tipo. Questa associazione consente l'accesso ai membri privati di tale tipo.

L'esempio di codice definisce una classe denominata Example con un campo privato, una classe denominata che deriva dalla prima classe, un tipo delegato denominato che restituisce Int32 e ha parametri di tipo Example e Int32e un tipo delegato denominato DerivedFromExampleUseLikeInstanceUseLikeStatic che restituisce Int32 e ha un parametro di tipo .Int32

Il codice di esempio crea quindi un oggetto DynamicMethod che modifica il campo privato di un'istanza di Example e restituisce il valore precedente.

Nota

In generale, la modifica dei campi interni delle classi non è una buona pratica di codifica orientata agli oggetti.

Il codice di esempio crea un'istanza di Example e quindi crea due delegati. Il primo è di tipo UseLikeStatic, che ha gli stessi parametri del metodo dinamico. Il secondo è di tipo UseLikeInstance, che manca il primo parametro (di tipo Example). Questo delegato viene creato usando l'overload del CreateDelegate(Type, Object) metodo. Il secondo parametro di tale overload del metodo è un'istanza di Example, in questo caso l'istanza appena creata, associata al delegato appena creato. Ogni volta che viene richiamato il delegato, il metodo dinamico agisce sull'istanza associata di Example.

Nota

Si tratta di un esempio delle regole rilassate per l'associazione delega introdotta in .NET Framework 2.0, insieme ai nuovi overload del Delegate.CreateDelegate metodo. Per altre informazioni, vedere la classe Delegate.

Il UseLikeStatic delegato viene richiamato, passando l'istanza di Example che è associata al UseLikeInstance delegato. Viene quindi richiamato il UseLikeInstance delegato, in modo che entrambi i delegati agiscono sulla stessa istanza di Example. Le modifiche apportate ai valori del campo interno vengono visualizzate dopo ogni chiamata. Infine, un UseLikeInstance delegato è associato a un'istanza di DerivedFromExamplee le chiamate delegate vengono ripetute.

using System;
using System.Reflection;
using System.Reflection.Emit;

// These classes are for demonstration purposes.
//
public class Example
{
    private int id = 0;
    public Example(int id)
    {
        this.id = id;
    }
    public int ID { get { return id; }}
}

public class DerivedFromExample : Example
{
    public DerivedFromExample(int id) : base(id) {}
}

// Two delegates are declared: UseLikeInstance treats the dynamic
// method as if it were an instance method, and UseLikeStatic
// treats the dynamic method in the ordinary fashion.
//
public delegate int UseLikeInstance(int newID);
public delegate int UseLikeStatic(Example ex, int newID);

public class Demo
{
    public static void Main()
    {
        // This dynamic method changes the private id field. It has
        // no name; it returns the old id value (return type int);
        // it takes two parameters, an instance of Example and
        // an int that is the new value of id; and it is declared
        // with Example as the owner type, so it can access all
        // members, public and private.
        //
        DynamicMethod changeID = new DynamicMethod(
            "",
            typeof(int),
            new Type[] { typeof(Example), typeof(int) },
            typeof(Example)
        );

        // Get a FieldInfo for the private field 'id'.
        FieldInfo fid = typeof(Example).GetField(
            "id",
            BindingFlags.NonPublic | BindingFlags.Instance
        );

        ILGenerator ilg = changeID.GetILGenerator();

        // Push the current value of the id field onto the
        // evaluation stack. It's an instance field, so load the
        // instance of Example before accessing the field.
        ilg.Emit(OpCodes.Ldarg_0);
        ilg.Emit(OpCodes.Ldfld, fid);

        // Load the instance of Example again, load the new value
        // of id, and store the new field value.
        ilg.Emit(OpCodes.Ldarg_0);
        ilg.Emit(OpCodes.Ldarg_1);
        ilg.Emit(OpCodes.Stfld, fid);

        // The original value of the id field is now the only
        // thing on the stack, so return from the call.
        ilg.Emit(OpCodes.Ret);

        // Create a delegate that uses changeID in the ordinary
        // way, as a static method that takes an instance of
        // Example and an int.
        //
        UseLikeStatic uls =
            (UseLikeStatic) changeID.CreateDelegate(
                typeof(UseLikeStatic)
            );

        // Create an instance of Example with an id of 42.
        //
        Example ex = new Example(42);

        // Create a delegate that is bound to the instance of
        // of Example. This is possible because the first
        // parameter of changeID is of type Example. The
        // delegate has all the parameters of changeID except
        // the first.
        UseLikeInstance uli =
            (UseLikeInstance) changeID.CreateDelegate(
                typeof(UseLikeInstance),
                ex
            );

        // First, change the value of id by calling changeID as
        // a static method, passing in the instance of Example.
        //
        Console.WriteLine(
            "Change the value of id; previous value: {0}",
            uls(ex, 1492)
        );

        // Change the value of id again using the delegate bound
        // to the instance of Example.
        //
        Console.WriteLine(
            "Change the value of id; previous value: {0}",
            uli(2700)
        );

        Console.WriteLine("Final value of id: {0}", ex.ID);

        // Now repeat the process with a class that derives
        // from Example.
        //
        DerivedFromExample dfex = new DerivedFromExample(71);

        uli = (UseLikeInstance) changeID.CreateDelegate(
                typeof(UseLikeInstance),
                dfex
            );

        Console.WriteLine(
            "Change the value of id; previous value: {0}",
            uls(dfex, 73)
        );
        Console.WriteLine(
            "Change the value of id; previous value: {0}",
            uli(79)
        );
        Console.WriteLine("Final value of id: {0}", dfex.ID);
    }
}

/* This code example produces the following output:

Change the value of id; previous value: 42
Change the value of id; previous value: 1492
Final value of id: 2700
Change the value of id; previous value: 71
Change the value of id; previous value: 73
Final value of id: 79
 */
Imports System.Reflection
Imports System.Reflection.Emit

' These classes are for demonstration purposes.
'
Public Class Example
    Private _id As Integer = 0
    
    Public Sub New(ByVal newId As Integer) 
        _id = newId    
    End Sub
    
    Public ReadOnly Property ID() As Integer 
        Get
            Return _id
        End Get
    End Property 
End Class

Public Class DerivedFromExample
    Inherits Example
    
    Public Sub New(ByVal newId As Integer) 
        MyBase.New(newId)
    End Sub
End Class
 
' Two delegates are declared: UseLikeInstance treats the dynamic
' method as if it were an instance method, and UseLikeStatic
' treats the dynamic method in the ordinary fashion.
' 
Public Delegate Function UseLikeInstance(ByVal newID As Integer) _
    As Integer 
Public Delegate Function UseLikeStatic(ByVal ex As Example, _
    ByVal newID As Integer) As Integer 

Public Class Demo
    
    Public Shared Sub Main() 
        ' This dynamic method changes the private _id field. It 
        ' has no name; it returns the old _id value (return type 
        ' Integer); it takes two parameters, an instance of Example 
        ' and an Integer that is the new value of _id; and it is 
        ' declared with Example as the owner type, so it can 
        ' access all members, public and private.
        '
        Dim changeID As New DynamicMethod( _
            "", _
            GetType(Integer), _
            New Type() {GetType(Example), GetType(Integer)}, _
            GetType(Example) _
        )
        
        ' Get a FieldInfo for the private field '_id'.
        Dim fid As FieldInfo = GetType(Example).GetField( _
            "_id", _
            BindingFlags.NonPublic Or BindingFlags.Instance _
        )
        
        Dim ilg As ILGenerator = changeID.GetILGenerator()
        
        ' Push the current value of the id field onto the 
        ' evaluation stack. It's an instance field, so load the
        ' instance of Example before accessing the field.
        ilg.Emit(OpCodes.Ldarg_0)
        ilg.Emit(OpCodes.Ldfld, fid)
        
        ' Load the instance of Example again, load the new value 
        ' of id, and store the new field value. 
        ilg.Emit(OpCodes.Ldarg_0)
        ilg.Emit(OpCodes.Ldarg_1)
        ilg.Emit(OpCodes.Stfld, fid)
        
        ' The original value of the id field is now the only 
        ' thing on the stack, so return from the call.
        ilg.Emit(OpCodes.Ret)
        
        
        ' Create a delegate that uses changeID in the ordinary
        ' way, as a static method that takes an instance of
        ' Example and an Integer.
        '
        Dim uls As UseLikeStatic = CType( _
            changeID.CreateDelegate(GetType(UseLikeStatic)), _
            UseLikeStatic _
        )
        
        ' Create an instance of Example with an id of 42.
        '
        Dim ex As New Example(42)
        
        ' Create a delegate that is bound to the instance of 
        ' of Example. This is possible because the first 
        ' parameter of changeID is of type Example. The 
        ' delegate has all the parameters of changeID except
        ' the first.
        Dim uli As UseLikeInstance = CType( _
            changeID.CreateDelegate( _
                GetType(UseLikeInstance), _
                ex), _
            UseLikeInstance _
        )
        
        ' First, change the value of _id by calling changeID as
        ' a static method, passing in the instance of Example.
        '
        Console.WriteLine( _
            "Change the value of _id; previous value: {0}", _
            uls(ex, 1492) _
        )
        
        ' Change the value of _id again using the delegate 
        ' bound to the instance of Example.
        '
        Console.WriteLine( _
            "Change the value of _id; previous value: {0}", _
            uli(2700) _
        )
        
        Console.WriteLine("Final value of _id: {0}", ex.ID)
    

        ' Now repeat the process with a class that derives
        ' from Example.
        '
        Dim dfex As New DerivedFromExample(71)

        uli = CType( _
            changeID.CreateDelegate( _
                GetType(UseLikeInstance), _
                dfex), _
            UseLikeInstance _
        )

        Console.WriteLine( _
            "Change the value of _id; previous value: {0}", _
            uls(dfex, 73) _
        )
        Console.WriteLine( _
            "Change the value of _id; previous value: {0}", _
            uli(79) _
        )
        Console.WriteLine("Final value of _id: {0}", dfex.ID)

    End Sub
End Class

' This code example produces the following output:
'
'Change the value of _id; previous value: 42
'Change the value of _id; previous value: 1492
'Final value of _id: 2700
'Change the value of _id; previous value: 71
'Change the value of _id; previous value: 73
'Final value of _id: 79'

Commenti

Il metodo dinamico creato con questo costruttore ha accesso a tutti i membri del tipo ownere ai membri pubblici e internal (Friend in Visual Basic) di tutti gli altri tipi del modulo che contiene owner.

Questo costruttore specifica gli attributi MethodAttributes.Public del metodo e MethodAttributes.Static, la convenzione CallingConventions.Standarddi chiamata e non ignora i controlli di visibilità JIT (Just-In-Time).

Nota

Per la compatibilità con le versioni precedenti, questo costruttore richiede SecurityPermission il SecurityPermissionFlag.ControlEvidence flag se le condizioni seguenti sono entrambe vere: owner si trova in un modulo diverso dal modulo chiamante e la richiesta di ReflectionPermission con il ReflectionPermissionFlag.MemberAccess flag non è riuscita. Se la richiesta di SecurityPermission esito positivo, l'operazione è consentita.

Vedi anche

Si applica a

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

Source:
DynamicMethod.cs
Source:
DynamicMethod.cs
Source:
DynamicMethod.cs

Crea un metodo dinamico globale per un modulo, specificando il nome del metodo, il tipo restituito, i tipi di parametri e il modulo e indicando se deve essere ignorato il controllo di visibilità JIT per i tipi e i membri del metodo dinamico a cui accede MSIL (Microsoft Intermediate Language).

public:
 DynamicMethod(System::String ^ name, Type ^ returnType, cli::array <Type ^> ^ parameterTypes, System::Reflection::Module ^ m, bool skipVisibility);
public DynamicMethod (string name, Type? returnType, Type[]? parameterTypes, System.Reflection.Module m, bool skipVisibility);
public DynamicMethod (string name, Type returnType, Type[] parameterTypes, System.Reflection.Module m, bool skipVisibility);
new System.Reflection.Emit.DynamicMethod : string * Type * Type[] * System.Reflection.Module * bool -> System.Reflection.Emit.DynamicMethod
Public Sub New (name As String, returnType As Type, parameterTypes As Type(), m As Module, skipVisibility As Boolean)

Parametri

name
String

Nome del metodo dinamico. Può essere una stringa di lunghezza zero, ma non può essere null.

returnType
Type

Oggetto Type che specifica il tipo restituito del metodo dinamico oppure null se per il metodo non esiste alcun tipo restituito.

parameterTypes
Type[]

Matrice di oggetti Type che specifica i tipi dei parametri del metodo dinamico oppure null se per il metodo non esistono parametri.

m
Module

Oggetto Module che rappresenta il modulo a cui il metodo dinamico deve essere associato in modo logico.

skipVisibility
Boolean

true per ignorare i controlli di visibilità JIT su tipi e membri a cui accede il linguaggio MSIL del metodo dinamico.

Eccezioni

Un elemento di parameterTypes è null o Void.

-oppure-

m è un modulo che fornisce hosting anonimo per i metodi dinamici.

name è null.

-oppure-

m è null.

.NET Framework e versioni di .NET Core precedenti alla versione 2.1: returnType è un tipo per cui IsByRef restituisce true.

Commenti

Questo costruttore specifica gli attributi MethodAttributes.Public del metodo e e MethodAttributes.Staticla convenzione CallingConventions.Standardchiamante .

Il metodo dinamico creato con questo costruttore ha accesso ai membri pubblici e internal (Friend in Visual Basic) di tutti i tipi nel modulo mcontenuto . Ignorando i controlli di visibilità del compilatore JIT, il metodo dinamico consente anche di accedere ai membri privati e protetti di tutti gli altri tipi. Questo è utile, ad esempio, quando si scrive codice per serializzare gli oggetti.

Nota

Per la compatibilità con le versioni precedenti, questo costruttore richiede SecurityPermission il SecurityPermissionFlag.ControlEvidence flag se le condizioni seguenti sono entrambe vere: m è un modulo diverso dal modulo chiamante e la richiesta di ReflectionPermission con il ReflectionPermissionFlag.MemberAccess flag non è riuscita. Se la richiesta di SecurityPermission esito positivo, l'operazione è consentita.

Vedi anche

Si applica a

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

Source:
DynamicMethod.cs
Source:
DynamicMethod.cs
Source:
DynamicMethod.cs

Crea un metodo dinamico, specificando il nome del metodo, il tipo restituito, i tipi di parametro, il tipo a cui il metodo dinamico è associato in modo logico e se i controlli di visibilità JIT possono essere ignorati per i tipi e i membri cui accede il linguaggio MSIL (Microsoft Intermediate Language) del metodo dinamico.

public:
 DynamicMethod(System::String ^ name, Type ^ returnType, cli::array <Type ^> ^ parameterTypes, Type ^ owner, bool skipVisibility);
public DynamicMethod (string name, Type? returnType, Type[]? parameterTypes, Type owner, bool skipVisibility);
public DynamicMethod (string name, Type returnType, Type[] parameterTypes, Type owner, bool skipVisibility);
new System.Reflection.Emit.DynamicMethod : string * Type * Type[] * Type * bool -> System.Reflection.Emit.DynamicMethod
Public Sub New (name As String, returnType As Type, parameterTypes As Type(), owner As Type, skipVisibility As Boolean)

Parametri

name
String

Nome del metodo dinamico. Può essere una stringa di lunghezza zero, ma non può essere null.

returnType
Type

Oggetto Type che specifica il tipo restituito del metodo dinamico oppure null se per il metodo non esiste alcun tipo restituito.

parameterTypes
Type[]

Matrice di oggetti Type che specifica i tipi dei parametri del metodo dinamico oppure null se per il metodo non esistono parametri.

owner
Type

Oggetto Type a cui il metodo dinamico è associato in modo logico. Il metodo dinamico ha accesso a tutti i membri del tipo.

skipVisibility
Boolean

true per ignorare i controlli di visibilità JIT sui tipi e i membri cui accede il linguaggio MSIL del metodo dinamico; in caso contrario, false.

Eccezioni

Un elemento di parameterTypes è null o Void.

-oppure-

owner è un'interfaccia, una matrice, un tipo generico aperto o un parametro di tipo di un tipo o un metodo generico.

name è null.

-oppure-

owner è null.

.NET Framework e versioni di .NET Core precedenti alla versione 2.1: returnType è un tipo per cui IsByRef restituisce true.

Commenti

Il metodo dinamico creato con questo costruttore ha accesso a tutti i membri del tipo ownere ai membri pubblici e internal (Friend in Visual Basic) di tutti gli altri tipi del modulo che contiene owner. Ignorando i controlli di visibilità del compilatore JIT, il metodo dinamico consente anche di accedere ai membri privati e protetti di tutti gli altri tipi. Questo è utile, ad esempio, quando si scrive codice per serializzare gli oggetti.

Questo costruttore specifica gli attributi MethodAttributes.Public del metodo e e MethodAttributes.Staticla convenzione CallingConventions.Standardchiamante .

Nota

Per la compatibilità con le versioni precedenti, questo costruttore richiede SecurityPermission il SecurityPermissionFlag.ControlEvidence flag se le condizioni seguenti sono entrambe vere: owner si trova in un modulo diverso dal modulo chiamante e la richiesta di ReflectionPermission con il ReflectionPermissionFlag.MemberAccess flag non è riuscita. Se la richiesta di SecurityPermission esito positivo, l'operazione è consentita.

Vedi anche

Si applica a

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

Source:
DynamicMethod.cs
Source:
DynamicMethod.cs
Source:
DynamicMethod.cs

Crea un metodo dinamico globale per un metodo, 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 possono essere ignorati per i tipi e i membri cui accede il linguaggio MSIL (Microsoft Intermediate Language) del metodo dinamico.

public:
 DynamicMethod(System::String ^ name, System::Reflection::MethodAttributes attributes, System::Reflection::CallingConventions callingConvention, Type ^ returnType, cli::array <Type ^> ^ parameterTypes, System::Reflection::Module ^ m, bool skipVisibility);
public DynamicMethod (string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, Type? returnType, Type[]? parameterTypes, System.Reflection.Module m, bool skipVisibility);
public DynamicMethod (string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, Type returnType, Type[] parameterTypes, System.Reflection.Module m, bool skipVisibility);
new System.Reflection.Emit.DynamicMethod : string * System.Reflection.MethodAttributes * System.Reflection.CallingConventions * Type * Type[] * System.Reflection.Module * bool -> System.Reflection.Emit.DynamicMethod
Public Sub New (name As String, attributes As MethodAttributes, callingConvention As CallingConventions, returnType As Type, parameterTypes As Type(), m As Module, skipVisibility As Boolean)

Parametri

name
String

Nome del metodo dinamico. Può essere una stringa di lunghezza zero, ma non può essere null.

attributes
MethodAttributes

Combinazione bit per bit di valori di MethodAttributes che specifica gli attributi del metodo dinamico. L'unica combinazione consentita è Public e Static.

callingConvention
CallingConventions

Convenzione di chiamata per il metodo dinamico. Deve essere Standard.

returnType
Type

Oggetto Type che specifica il tipo restituito del metodo dinamico oppure null se per il metodo non esiste alcun tipo restituito.

parameterTypes
Type[]

Matrice di oggetti Type che specifica i tipi dei parametri del metodo dinamico oppure null se per il metodo non esistono parametri.

m
Module

Oggetto Module che rappresenta il modulo a cui il metodo dinamico deve essere associato in modo logico.

skipVisibility
Boolean

true per ignorare i controlli di visibilità JIT sui tipi e i membri cui accede il linguaggio MSIL del metodo dinamico; in caso contrario, false.

Eccezioni

Un elemento di parameterTypes è null o Void.

-oppure-

m è un modulo che fornisce hosting anonimo per i metodi dinamici.

name è null.

-oppure-

m è null.

attributes è una combinazione di flag diversa da Public e Static.

-oppure-

callingConvention non è Standard.

-oppure-

returnType è un tipo per cui IsByRef restituisce true.

Commenti

Il metodo dinamico creato con questo costruttore ha accesso ai membri pubblici e internal (Friend in Visual Basic) di tutti i tipi pubblici e interni contenuti nel modulo m.

Ignorando i controlli di visibilità del compilatore JIT, il metodo dinamico consente di accedere ai membri privati e protetti di tutti gli altri tipi nel modulo e in tutti gli altri assembly. Questo è utile, ad esempio, quando si scrive codice per serializzare gli oggetti.

Nota

Per la compatibilità con le versioni precedenti, questo costruttore richiede SecurityPermission il SecurityPermissionFlag.ControlEvidence flag se le condizioni seguenti sono entrambe vere: m è un modulo diverso dal modulo chiamante e la richiesta di ReflectionPermission con il ReflectionPermissionFlag.MemberAccess flag non è riuscita. Se la richiesta di SecurityPermission esito positivo, l'operazione è consentita.

Vedi anche

Si applica a

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

Source:
DynamicMethod.cs
Source:
DynamicMethod.cs
Source:
DynamicMethod.cs

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 in modo logico e se i controlli di visibilità JIT possono essere ignorati per i tipi e i membri cui accede il linguaggio MSIL (Microsoft Intermediate Language) del metodo dinamico.

public:
 DynamicMethod(System::String ^ name, System::Reflection::MethodAttributes attributes, System::Reflection::CallingConventions callingConvention, Type ^ returnType, cli::array <Type ^> ^ parameterTypes, Type ^ owner, bool skipVisibility);
public DynamicMethod (string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, Type? returnType, Type[]? parameterTypes, Type owner, bool skipVisibility);
public DynamicMethod (string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, Type returnType, Type[] parameterTypes, Type owner, bool skipVisibility);
new System.Reflection.Emit.DynamicMethod : string * System.Reflection.MethodAttributes * System.Reflection.CallingConventions * Type * Type[] * Type * bool -> System.Reflection.Emit.DynamicMethod
Public Sub New (name As String, attributes As MethodAttributes, callingConvention As CallingConventions, returnType As Type, parameterTypes As Type(), owner As Type, skipVisibility As Boolean)

Parametri

name
String

Nome del metodo dinamico. Può essere una stringa di lunghezza zero, ma non può essere null.

attributes
MethodAttributes

Combinazione bit per bit di valori di MethodAttributes che specifica gli attributi del metodo dinamico. L'unica combinazione consentita è Public e Static.

callingConvention
CallingConventions

Convenzione di chiamata per il metodo dinamico. Deve essere Standard.

returnType
Type

Oggetto Type che specifica il tipo restituito del metodo dinamico oppure null se per il metodo non esiste alcun tipo restituito.

parameterTypes
Type[]

Matrice di oggetti Type che specifica i tipi dei parametri del metodo dinamico oppure null se per il metodo non esistono parametri.

owner
Type

Oggetto Type a cui il metodo dinamico è associato in modo logico. Il metodo dinamico ha accesso a tutti i membri del tipo.

skipVisibility
Boolean

true per ignorare i controlli di visibilità JIT sui tipi e i membri cui accede il linguaggio MSIL del metodo dinamico; in caso contrario, false.

Eccezioni

Un elemento di parameterTypes è null o Void.

-oppure-

owner è un'interfaccia, una matrice, un tipo generico aperto o un parametro di tipo di un tipo o un metodo generico.

name è null.

-oppure-

owner è null.

attributes è una combinazione di flag diversa da Public e Static.

-oppure-

callingConvention non è Standard.

-oppure-

returnType è un tipo per cui IsByRef restituisce true.

Commenti

Il metodo dinamico è globale al modulo che contiene il tipo owner. Ha accesso a tutti i membri del tipo owner.

Il metodo dinamico creato con questo costruttore ha accesso a tutti i membri del tipo ownere ai membri pubblici e internal (Friend in Visual Basic) di tutti i tipi contenuti nel modulo contenente owner. Ignorando i controlli di visibilità del compilatore JIT, il metodo dinamico consente anche di accedere ai membri privati e protetti di tutti gli altri tipi. Questo è utile, ad esempio, quando si scrive codice per serializzare gli oggetti.

Nota

Per la compatibilità con le versioni precedenti, questo costruttore richiede SecurityPermission il SecurityPermissionFlag.ControlEvidence flag se le condizioni seguenti sono entrambe vere: owner si trova in un modulo diverso dal modulo chiamante e la richiesta di ReflectionPermission con il ReflectionPermissionFlag.MemberAccess flag non è riuscita. Se la richiesta di SecurityPermission esito positivo, l'operazione è consentita.

Vedi anche

Si applica a