CallingConventions 枚举

定义

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

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

C#
[System.Flags]
public enum CallingConventions
C#
[System.Flags]
[System.Serializable]
public enum CallingConventions
C#
[System.Flags]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum CallingConventions
继承
CallingConventions
属性

字段

名称 说明
Any 3

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

ExplicitThis 64

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

HasThis 32

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

Standard 1

指定公共语言运行时确定的默认调用约定。 对静态方法使用此调用约定。 对实例或虚方法使用 HasThis

VarArgs 2

指定包含变量参数的方法的调用约定。

示例

C#
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);
        }
    }
}

注解

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

适用于

产品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0