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
| Member | Value | Description |
|---|---|---|
Standard | 0 | Default calling convention for most .NET methods. |
VarArgs | 1 | Method supports a variable number of arguments (C style varargs). |
Any | 2 | Any calling convention (used for filter operations). |
HasThis | 4 | Instance method with an implicit this pointer. |
ExplicitThis | 8 | Instance 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.