Table of Contents

Parameters

Variable number of parameters

You can use params keyword to accept a variable number of parameters, example:

[Command("average")]
public static string Average(params double[] numbers) => $"Average: {numbers.Average()}";

Optional parameters

To mark parameters as optional, give them a default value, example:

[Command("power")]
public static string Power(double @base, double power = 2) => $"Result: {Math.Pow(@base, power)}";

Remainder

You can set Remainder to true to accept rest of an input as a one parameter, example:

[Command("reverse")]
public static string Reverse([CommandParameter(Remainder = true)] string toReverse)
{
    var array = toReverse.ToCharArray();
    Array.Reverse(array);
    return new string(array);
}

Command overloading

You can overload commands to accept different parameter types, you can specify Priority to set a priority for each command overload, example:

[Command("multiply", Priority = 0)]
public static string Multiply(int times, [CommandParameter(Remainder = true)] string text)
{
    return string.Concat(Enumerable.Repeat(text, times));
}

[Command("multiply", Priority = 1)]
public static string Multiply(int times, BigInteger number) => (number * times).ToString();
Note

By default, command overloads are selected from the one with the most parameters to that with the fewest parameters.