CallingConventions 枚举

定义

定义方法的有效调用约定。

此枚举支持其成员值的按位组合。

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
继承
CallingConventions
属性

字段

名称 说明
Standard 1

指定由公共语言运行时确定的默认调用约定。 将此调用约定用于静态方法。 例如,或虚拟方法使用 HasThis

VarArgs 2

指定具有变量参数的方法的调用约定。

Any 3

指定 Standard 可以使用调用约定或 VarArgs 调用约定。

HasThis 32

指定实例或虚拟方法(而不是静态方法)。 在运行时,调用的方法作为第一个参数(指针 this )传递给目标对象的指针。 存储在元数据中的签名不包括此第一个参数的类型,因为该方法是已知的,并且可以从元数据中发现其所有者类。

ExplicitThis 64

指定签名是函数指针签名,表示对实例或虚拟方法(而不是静态方法)的调用。 如果 ExplicitThis 已设置, HasThis 还必须设置。 传递给调用方法的第一个参数仍然是一个指针,但第一个 this 参数的类型现在未知。 因此,描述指针的类型(或类)的 this 标记显式存储在其元数据签名中。

示例

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

注解

本机调用约定是一组规则,用于控制传递给已编译方法的参数的顺序和布局。 它还控制如何传递返回值、要用于参数的寄存器,以及调用方法是否从堆栈中删除参数。

适用于