Added Dynamic Enum TypeParsing, to support all enums

This commit is contained in:
Khionu Terabite
2016-07-20 20:54:29 -04:00
parent 63fdd67413
commit 523b862525
2 changed files with 64 additions and 5 deletions

View File

@@ -75,19 +75,24 @@ namespace Discord.Commands
continue;
}
var typeInfo = type.GetTypeInfo();
if (typeInfo.IsEnum)
Module.Service.AddTypeReader(type, new EnumTypeReader(type));
var reader = Module.Service.GetTypeReader(type);
if (reader == null)
{
var typeInfo = type.GetTypeInfo();
if (typeInfo.IsEnum)
{
type = Enum.GetUnderlyingType(type);
reader = Module.Service.GetTypeReader(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?");
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)