feature: add a way to remove type readers from the interaction/command service. (#2210)

* Add remove methods

* add inline docs

Co-authored-by: Cenngo <cenk.ergen1@gmail.com>
This commit is contained in:
Quin Lynch
2022-03-26 16:21:26 -03:00
committed by GitHub
parent 91d8fabb70
commit 73399459ea
3 changed files with 99 additions and 0 deletions

View File

@@ -74,6 +74,18 @@ namespace Discord.Interactions
_generics[targetType] = converterType;
}
public bool TryRemoveConcrete<TTarget>(out TConverter converter)
=> TryRemoveConcrete(typeof(TTarget), out converter);
public bool TryRemoveConcrete(Type type, out TConverter converter)
=> _concretes.TryRemove(type, out converter);
public bool TryRemoveGeneric<TTarget>(out Type converterType)
=> TryRemoveGeneric(typeof(TTarget), out converterType);
public bool TryRemoveGeneric(Type targetType, out Type converterType)
=> _generics.TryRemove(targetType, out converterType);
private Type GetMostSpecific(Type type)
{
if (_generics.TryGetValue(type, out var matching))