Added support for non-int enums

This commit is contained in:
RogueException
2016-07-20 23:16:06 -03:00
parent c101c44c04
commit b407c71567
2 changed files with 66 additions and 43 deletions

View File

@@ -18,7 +18,7 @@ namespace Discord.Commands
public string Text { get; }
public Module Module { get; }
public IReadOnlyList<CommandParameter> Parameters { get; }
internal Command(Module module, object instance, CommandAttribute attribute, MethodInfo methodInfo, string groupPrefix)
{
Module = module;
@@ -76,24 +76,17 @@ namespace Discord.Commands
}
var typeInfo = type.GetTypeInfo();
if (typeInfo.IsEnum)
Module.Service.AddTypeReader(type, new EnumTypeReader(type));
var reader = Module.Service.GetTypeReader(type);
if (reader == null)
if (reader == null && typeInfo.IsEnum)
{
if (typeInfo.IsEnum)
{
type = Enum.GetUnderlyingType(type);
reader = Module.Service.GetTypeReader(type);
}
if (reader == null)
throw new InvalidOperationException($"{type.FullName} is not supported as a command parameter, are you missing a TypeReader?");
reader = EnumTypeReader.GetReader(type);
Module.Service.AddTypeReader(type, reader);
}
if (reader == null)
throw new InvalidOperationException($"{type.FullName} is not supported as a command parameter, are you missing a TypeReader?");
bool isUnparsed = parameter.GetCustomAttribute<UnparsedAttribute>() != null;
if (isUnparsed)
{