fix: Add type reader when entity type reader exists (#1486)

When adding a type reader that replaces a default type reader,
CommandService checks that it replaces a type in its default type
readers or entity type readers (IMessage, IChannel, IRole, IUser). For
entity types, it checks that the target type is the same as the entity
type or it implements its type reader. Adding a type reader for a
default type reader doesn't make much sense and the original intent was
likely to check that the target type is or implements the entity type.
This commit is contained in:
Adam Gauthier
2021-04-28 10:30:16 -04:00
committed by GitHub
parent df23d57458
commit c46daaad19

View File

@@ -408,7 +408,7 @@ namespace Discord.Commands
var typeInfo = type.GetTypeInfo(); var typeInfo = type.GetTypeInfo();
if (typeInfo.IsEnum) if (typeInfo.IsEnum)
return true; return true;
return _entityTypeReaders.Any(x => type == x.EntityType || typeInfo.ImplementedInterfaces.Contains(x.TypeReaderType)); return _entityTypeReaders.Any(x => type == x.EntityType || typeInfo.ImplementedInterfaces.Contains(x.EntityType));
} }
internal void AddNullableTypeReader(Type valueType, TypeReader valueTypeReader) internal void AddNullableTypeReader(Type valueType, TypeReader valueTypeReader)
{ {