Browse Source

Use type constraints which actually compile

:hash:BlameFoxbot
pull/535/head
FiniteReality 8 years ago
parent
commit
57e0f78803
3 changed files with 9 additions and 4 deletions
  1. +2
    -2
      src/Discord.Net.Commands/CommandService.cs
  2. +6
    -1
      src/Discord.Net.Commands/IModuleBase.cs
  3. +1
    -1
      src/Discord.Net.Commands/ModuleBase.cs

+ 2
- 2
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>() where T : IModuleBase
public async Task<ModuleInfo> AddModuleAsync<T>() where T : IModuleBase<ICommandContext>
{ {
await _moduleLock.WaitAsync().ConfigureAwait(false); await _moduleLock.WaitAsync().ConfigureAwait(false);
try try
@@ -143,7 +143,7 @@ namespace Discord.Commands
_moduleLock.Release(); _moduleLock.Release();
} }
} }
public async Task<bool> RemoveModuleAsync<T>() where T : IModuleBase
public async Task<bool> RemoveModuleAsync<T>() where T : IModuleBase<ICommandContext>
{ {
await _moduleLock.WaitAsync().ConfigureAwait(false); await _moduleLock.WaitAsync().ConfigureAwait(false);
try try


+ 6
- 1
src/Discord.Net.Commands/IModuleBase.cs View File

@@ -1,5 +1,10 @@
namespace Discord.Commands
namespace Discord.Commands
{ {
public interface IModuleBase<out T>
where T : ICommandContext
{
}

internal interface IModuleBase internal interface IModuleBase
{ {
void SetContext(ICommandContext context); void SetContext(ICommandContext context);


+ 1
- 1
src/Discord.Net.Commands/ModuleBase.cs View File

@@ -5,7 +5,7 @@ namespace Discord.Commands
{ {
public abstract class ModuleBase : ModuleBase<CommandContext> { } public abstract class ModuleBase : ModuleBase<CommandContext> { }


public abstract class ModuleBase<T> : IModuleBase
public abstract class ModuleBase<T> : IModuleBase, IModuleBase<T>
where T : class, ICommandContext where T : class, ICommandContext
{ {
public T Context { get; private set; } public T Context { get; private set; }


Loading…
Cancel
Save