Browse Source

Add type constraints for Add/RemoveModuleAsync

pull/535/head
FiniteReality 8 years ago
parent
commit
7ffb8ed8c4
1 changed files with 3 additions and 3 deletions
  1. +3
    -3
      src/Discord.Net.Commands/CommandService.cs

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

@@ -73,7 +73,7 @@ namespace Discord.Commands
_moduleLock.Release(); _moduleLock.Release();
} }
} }
public async Task<ModuleInfo> AddModuleAsync<T>()
public async Task<ModuleInfo> AddModuleAsync<T>() where T : ModuleBase
{ {
await _moduleLock.WaitAsync().ConfigureAwait(false); await _moduleLock.WaitAsync().ConfigureAwait(false);
try try
@@ -86,7 +86,7 @@ namespace Discord.Commands
var module = ModuleClassBuilder.Build(this, typeInfo).FirstOrDefault(); var module = ModuleClassBuilder.Build(this, typeInfo).FirstOrDefault();


if (module.Value == default(ModuleInfo)) if (module.Value == default(ModuleInfo))
throw new InvalidOperationException($"Could not build the module {typeof(T).FullName}, did you pass an invalid type?");
throw new InvalidOperationException($"Could not build the module {typeof(T).FullName}");


_typedModuleDefs[module.Key] = module.Value; _typedModuleDefs[module.Key] = module.Value;


@@ -143,7 +143,7 @@ namespace Discord.Commands
_moduleLock.Release(); _moduleLock.Release();
} }
} }
public async Task<bool> RemoveModuleAsync<T>()
public async Task<bool> RemoveModuleAsync<T>() where T : ModuleBase
{ {
await _moduleLock.WaitAsync().ConfigureAwait(false); await _moduleLock.WaitAsync().ConfigureAwait(false);
try try


Loading…
Cancel
Save