Browse Source

Merge pull request #308 from Joe4evr/AutoLoadFix

Exclude abstract types from being loaded as modules.
tags/1.0-rc
RogueException GitHub 8 years ago
parent
commit
8c8ac47887
1 changed files with 7 additions and 4 deletions
  1. +7
    -4
      src/Discord.Net.Commands/CommandService.cs

+ 7
- 4
src/Discord.Net.Commands/CommandService.cs View File

@@ -70,13 +70,16 @@ namespace Discord.Commands
await _moduleLock.WaitAsync().ConfigureAwait(false);
try
{
if (_moduleDefs.ContainsKey(typeof(T)))
throw new ArgumentException($"This module has already been added.");

var typeInfo = typeof(T).GetTypeInfo();
if (!_moduleTypeInfo.IsAssignableFrom(typeInfo))
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);
}
finally
@@ -98,7 +101,7 @@ namespace Discord.Commands
if (_moduleTypeInfo.IsAssignableFrom(typeInfo))
{
var dontAutoLoad = typeInfo.GetCustomAttribute<DontAutoLoadAttribute>();
if (dontAutoLoad == null)
if (dontAutoLoad == null && !typeInfo.IsAbstract)
moduleDefs.Add(AddModuleInternal(typeInfo, dependencyMap));
}
}


Loading…
Cancel
Save