Microsoft Docs

System.Reflection.CallingConventions

Namespace: System.Reflection

Assembly: System.Reflection.dll

Summary

Specifies the calling convention of a method. Used with reflection to describe how arguments are passed to a method and how the method returns a value.

Enum Values

MemberValueDescription
Standard0Default calling convention for most .NET methods.
VarArgs1Method supports a variable number of arguments (C style varargs).
Any2Any calling convention (used for filter operations).
HasThis4Instance method with an implicit this pointer.
ExplicitThis8Instance method where the this pointer is explicitly passed as the first argument.

Usage

The CallingConventions enumeration is typically accessed via MethodInfo.CallingConvention or ConstructorInfo.CallingConvention.

Example: Filter Methods by Calling Convention

using System;
using System.Reflection;

class Demo
{
    static void Main()
    {
        var type = typeof(Console);
        foreach (MethodInfo mi in type.GetMethods(BindingFlags.Public | BindingFlags.Static))
        {
            if ((mi.CallingConvention & CallingConventions.VarArgs) != 0)
            {
                Console.WriteLine($"\{mi.Name\} uses VarArgs");
            }
        }
    }
}

This code enumerates static public methods on System.Console and prints those that support variable arguments.

Related Topics