From d715af8b8950c757174be7f37f0c93eb98ad5807 Mon Sep 17 00:00:00 2001 From: deca Date: Thu, 27 Jul 2023 09:27:24 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Resolve=20#16=20by=20adding=20sp?= =?UTF-8?q?ecific=20check=20for=20Enums?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VCF.Core/Registry/CommandRegistry.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/VCF.Core/Registry/CommandRegistry.cs b/VCF.Core/Registry/CommandRegistry.cs index 4d6960f..05961e8 100644 --- a/VCF.Core/Registry/CommandRegistry.cs +++ b/VCF.Core/Registry/CommandRegistry.cs @@ -164,13 +164,25 @@ static void HandleAfterExecute(ICommandContext ctx, CommandMetadata command) return CommandResult.InternalError; } } + // Default Converter else { - // default convertet - var builtinConverter = TypeDescriptor.GetConverter(param.ParameterType); + var defaultConverter = TypeDescriptor.GetConverter(param.ParameterType); try { - commandArgs[i + 1] = builtinConverter.ConvertFromInvariantString(arg); + var val = defaultConverter.ConvertFromInvariantString(arg); + + // ensure enums are valid for #16 + if (defaultConverter is EnumConverter) + { + if (!Enum.IsDefined(param.ParameterType, val)) + { + ctx.Reply($"[error] Invalid value {val} for {param.ParameterType.Name}"); + return CommandResult.UsageError; + } + } + + commandArgs[i + 1] = val; } catch (Exception e) {