Split typechecks into their own conditions
This commit is contained in:
@@ -38,8 +38,10 @@ namespace Discord.Commands
|
|||||||
public void AddFactory<T>(Func<T> factory) where T : class
|
public void AddFactory<T>(Func<T> factory) where T : class
|
||||||
{
|
{
|
||||||
var t = typeof(T);
|
var t = typeof(T);
|
||||||
if (typeof(T) == typeof(IDependencyMap) || typeof(T) == typeof(CommandService))
|
if (typeof(T) == typeof(IDependencyMap))
|
||||||
throw new InvalidOperationException("The dependency map cannot contain services directly added as IDependencyMap or CommandService. Only Implimentations and Derivatives are permitted");
|
throw new InvalidOperationException("IDependencyMap is used internally and cannot be added as a dependency");
|
||||||
|
if (typeof(T) == typeof(CommandService))
|
||||||
|
throw new InvalidOperationException("CommandService is used internally and cannot be added as a dependency");
|
||||||
if (map.ContainsKey(t))
|
if (map.ContainsKey(t))
|
||||||
throw new InvalidOperationException($"The dependency map already contains \"{t.FullName}\"");
|
throw new InvalidOperationException($"The dependency map already contains \"{t.FullName}\"");
|
||||||
map.Add(t, factory);
|
map.Add(t, factory);
|
||||||
@@ -50,8 +52,10 @@ namespace Discord.Commands
|
|||||||
var t = typeof(T);
|
var t = typeof(T);
|
||||||
if (map.ContainsKey(t))
|
if (map.ContainsKey(t))
|
||||||
return false;
|
return false;
|
||||||
if (typeof(T) == typeof(IDependencyMap) || typeof(T) == typeof(CommandService))
|
if (typeof(T) == typeof(IDependencyMap))
|
||||||
throw new InvalidOperationException("The dependency map cannot contain services directly added as IDependencyMap or CommandService. Only Implimentations and Derivatives are permitted");
|
throw new InvalidOperationException("IDependencyMap is used internally and cannot be added as a dependency");
|
||||||
|
if (typeof(T) == typeof(CommandService))
|
||||||
|
throw new InvalidOperationException("CommandService is used internally and cannot be added as a dependency");
|
||||||
map.Add(t, factory);
|
map.Add(t, factory);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user