CallingConventions Výčet

Definice

Definuje platné konvence volání pro metodu.

Tento výčet podporuje bitové kombinace hodnot jeho členů.

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

Pole

Name Hodnota Description
Standard 1

Určuje výchozí konvenci volání určenou modulem CLR (Common Language Runtime). Tuto konvenci volání použijte pro statické metody. Například nebo virtuální metody používají HasThis.

VarArgs 2

Určuje konvenci volání pro metody s proměnnými argumenty.

Any 3

Určuje, že StandardVarArgs lze použít konvenci volání.

HasThis 32

Určuje instanci nebo virtuální metodu (ne statickou metodu). V době běhu je volána metoda předán ukazatel na cílový objekt jako první argument ( this ukazatel). Podpis uložený v metadatech neobsahuje typ tohoto prvního argumentu, protože metoda je známá a její třída vlastníka lze zjistit z metadat.

ExplicitThis 64

Určuje, že podpis je podpis ukazatelem funkce, který představuje volání instance nebo virtuální metody (nikoli statické metody). Pokud ExplicitThis je nastavená, HasThis musí být také nastavena. První argument předaný volané metodě je stále this ukazatel, ale typ prvního argumentu je nyní neznámý. Token, který popisuje typ (nebo třídu) this ukazatele je proto explicitně uložen do podpisu metadat.

Příklady

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

Poznámky

Nativní konvence volání je sada pravidel, která řídí pořadí a rozložení argumentů předaných kompilovaným metodám. Také určuje, jak předat návratovou hodnotu, co se registruje použít pro argumenty a zda volána nebo volající metoda odebere argumenty ze zásobníku.

Platí pro