CallingConventions Enumerazione

Definizione

Definisce le convenzioni di chiamata valide per un metodo.

Questa enumerazione supporta una combinazione bit per bit dei rispettivi valori dei membri.

public enum class CallingConventions
[System.Flags]
public enum CallingConventions
[System.Flags]
[System.Serializable]
public enum CallingConventions
[System.Flags]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum CallingConventions
[<System.Flags>]
type CallingConventions = 
[<System.Flags>]
[<System.Serializable>]
type CallingConventions = 
[<System.Flags>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type CallingConventions = 
Public Enum CallingConventions
Ereditarietà
CallingConventions
Attributi

Campi

Nome Valore Descrizione
Standard 1

Specifica la convenzione di chiamata predefinita determinata da Common Language Runtime. Usare questa convenzione di chiamata per i metodi statici. Ad esempio o metodi virtuali, usare HasThis.

VarArgs 2

Specifica la convenzione di chiamata per i metodi con argomenti variabili.

Any 3

Specifica che è possibile utilizzare la Standard convenzione di chiamata o VarArgs .

HasThis 32

Specifica un'istanza o un metodo virtuale (non un metodo statico). In fase di esecuzione, il metodo chiamato viene passato un puntatore all'oggetto di destinazione come primo argomento (puntatore this ). La firma archiviata nei metadati non include il tipo di questo primo argomento, perché il metodo è noto e la relativa classe proprietario può essere individuata dai metadati.

ExplicitThis 64

Specifica che la firma è una firma del puntatore a funzione, che rappresenta una chiamata a un'istanza o a un metodo virtuale (non un metodo statico). Se ExplicitThis è impostato, HasThis è necessario impostare anche . Il primo argomento passato al metodo chiamato è ancora un this puntatore, ma il tipo del primo argomento è ora sconosciuto. Pertanto, un token che descrive il tipo (o la this classe) del puntatore viene archiviato in modo esplicito nella firma dei metadati.

Esempio

using System;
using System.Reflection;
using System.Security;

public class MyClass3
{
    public MyClass3(int i) { }
    public static void Main()
    {
        try
        {
            Type myType = typeof(MyClass3);
            Type[] types = new Type[1];
            types[0] = typeof(int);
            // Get the public instance constructor that takes an integer parameter.
            ConstructorInfo constructorInfoObj = myType.GetConstructor(
                BindingFlags.Instance | BindingFlags.Public, null,
                CallingConventions.HasThis, types, null);
            if (constructorInfoObj != null)
            {
                Console.WriteLine("The constructor of MyClass3 that is a public " +
                    "instance method and takes an integer as a parameter is: ");
                Console.WriteLine(constructorInfoObj.ToString());
            }
            else
            {
                Console.WriteLine("The constructor of MyClass3 that is a public instance " +
                    "method and takes an integer as a parameter is not available.");
            }
        }
        catch (ArgumentNullException e)
        {
            Console.WriteLine("ArgumentNullException: " + e.Message);
        }
        catch (ArgumentException e)
        {
            Console.WriteLine("ArgumentException: " + e.Message);
        }
        catch (SecurityException e)
        {
            Console.WriteLine("SecurityException: " + e.Message);
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception: " + e.Message);
        }
    }
}
Public Class MyClass1
    Public Sub New(ByVal i As Integer)
    End Sub
    Public Shared Sub Main()
        Try
            Dim myType As Type = GetType(MyClass1)
            Dim types(0) As Type
            types(0) = GetType(Integer)
            ' Get the public instance constructor that takes an integer parameter.
            Dim constructorInfoObj As ConstructorInfo = _
                        myType.GetConstructor(BindingFlags.Instance Or _
                        BindingFlags.Public, Nothing, _
                        CallingConventions.HasThis, types, Nothing)
            If Not (constructorInfoObj Is Nothing) Then
                Console.WriteLine("The constructor of MyClass1 that " + _
                                  "is a public instance method and takes an " + _
                                  "integer as a parameter is: ")
                Console.WriteLine(constructorInfoObj.ToString())
            Else
                Console.WriteLine("The constructor MyClass1 that " + _
                                  "is a public instance method and takes an " + _
                                  "integer as a parameter is not available.")
            End If
        Catch e As ArgumentNullException
            Console.WriteLine("ArgumentNullException: " + e.Message)
        Catch e As ArgumentException
            Console.WriteLine("ArgumentException: " + e.Message)
        Catch e As SecurityException
            Console.WriteLine("SecurityException: " + e.Message)
        Catch e As Exception
            Console.WriteLine("Exception: " + e.Message)
        End Try
    End Sub
End Class

Commenti

La convenzione di chiamata nativa è il set di regole che regolano l'ordine e il layout degli argomenti passati ai metodi compilati. Determina anche come passare il valore restituito, i registri da usare per gli argomenti e se il metodo chiamato o chiamante rimuove gli argomenti dallo stack.

Si applica a