Skip to content

Commit

Permalink
🐛 Resolve #16 by adding specific check for Enums
Browse files Browse the repository at this point in the history
  • Loading branch information
decaprime committed Jul 27, 2023
1 parent 41394c5 commit d715af8
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions VCF.Core/Registry/CommandRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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($"<color=red>[error]</color> Invalid value {val} for {param.ParameterType.Name}");
return CommandResult.UsageError;
}
}

commandArgs[i + 1] = val;
}
catch (Exception e)
{
Expand Down

0 comments on commit d715af8

Please sign in to comment.