Exclude abstract types from being loaded as modules.

This commit is contained in:
Joe4evr
2016-10-14 18:41:13 +02:00
parent 75fb31e939
commit bc45c0b6a4

View File

@@ -70,13 +70,16 @@ namespace Discord.Commands
await _moduleLock.WaitAsync().ConfigureAwait(false); await _moduleLock.WaitAsync().ConfigureAwait(false);
try try
{ {
if (_moduleDefs.ContainsKey(typeof(T)))
throw new ArgumentException($"This module has already been added.");
var typeInfo = typeof(T).GetTypeInfo(); var typeInfo = typeof(T).GetTypeInfo();
if (!_moduleTypeInfo.IsAssignableFrom(typeInfo)) if (!_moduleTypeInfo.IsAssignableFrom(typeInfo))
throw new ArgumentException($"Modules must inherit ModuleBase."); throw new ArgumentException($"Modules must inherit ModuleBase.");
if (typeInfo.IsAbstract)
throw new InvalidOperationException("Modules must not be abstract.");
if (_moduleDefs.ContainsKey(typeof(T)))
throw new ArgumentException($"This module has already been added.");
return AddModuleInternal(typeInfo, dependencyMap); return AddModuleInternal(typeInfo, dependencyMap);
} }
finally finally
@@ -98,7 +101,7 @@ namespace Discord.Commands
if (_moduleTypeInfo.IsAssignableFrom(typeInfo)) if (_moduleTypeInfo.IsAssignableFrom(typeInfo))
{ {
var dontAutoLoad = typeInfo.GetCustomAttribute<DontAutoLoadAttribute>(); var dontAutoLoad = typeInfo.GetCustomAttribute<DontAutoLoadAttribute>();
if (dontAutoLoad == null) if (dontAutoLoad == null && !typeInfo.IsAbstract)
moduleDefs.Add(AddModuleInternal(typeInfo, dependencyMap)); moduleDefs.Add(AddModuleInternal(typeInfo, dependencyMap));
} }
} }