From 65a9a0e1e3beae6ae1e42c155c0935e6fc7adb53 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sat, 6 May 2023 16:00:41 +0100 Subject: [PATCH] feat(commands): add support for optional args --- VpSharp.Commands/CommandsExtension.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/VpSharp.Commands/CommandsExtension.cs b/VpSharp.Commands/CommandsExtension.cs index 3bb6949..b4897ee 100644 --- a/VpSharp.Commands/CommandsExtension.cs +++ b/VpSharp.Commands/CommandsExtension.cs @@ -253,7 +253,7 @@ public sealed class CommandsExtension : VirtualParadiseClientExtension } ParameterInfo[] parameters = commandMethod.GetParameters(); - if (parameters.Length != arguments.Length) + if (parameters.Length != arguments.Length || parameters[arguments.Length..].Any(p => !p.IsOptional)) { return base.OnMessageReceived(args); } @@ -286,6 +286,11 @@ public sealed class CommandsExtension : VirtualParadiseClientExtension } } + for (int index = arguments.Length; index < parameters.Length; index++) + { + arguments[index] = parameters[index].DefaultValue; + } + object? returnValue = commandMethod.Invoke(command.Module, arguments); if (returnValue is Task task) {