From c64d6cdd7c2b166dc89bdc52ed0e32ec63f22381 Mon Sep 17 00:00:00 2001 From: Joe4evr Date: Thu, 26 Jan 2017 18:02:04 +0100 Subject: [PATCH 1/2] Add indicator that a modules CommandContext has been set. --- src/Discord.Net.Commands/ModuleBase.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Discord.Net.Commands/ModuleBase.cs b/src/Discord.Net.Commands/ModuleBase.cs index 4b8e1727d..808a26caa 100644 --- a/src/Discord.Net.Commands/ModuleBase.cs +++ b/src/Discord.Net.Commands/ModuleBase.cs @@ -8,12 +8,25 @@ namespace Discord.Commands public abstract class ModuleBase : IModuleBase where T : class, ICommandContext { - public T Context { get; private set; } + public T Context + { + get { return _context; } + private set + { + _context = value; + ContextSet(); + } + } + private T _context; protected virtual async Task ReplyAsync(string message, bool isTTS = false, Embed embed = null, RequestOptions options = null) { return await Context.Channel.SendMessageAsync(message, isTTS, embed, options).ConfigureAwait(false); } + + protected virtual void ContextSet() + { + } //IModuleBase void IModuleBase.SetContext(ICommandContext context) From ba8fbdb9164483d94a343c5eacc80c273a4a1708 Mon Sep 17 00:00:00 2001 From: Joe4evr Date: Thu, 26 Jan 2017 20:02:24 +0100 Subject: [PATCH 2/2] Revert back to auto property, fire method at end of SetContext(). --- src/Discord.Net.Commands/ModuleBase.cs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/Discord.Net.Commands/ModuleBase.cs b/src/Discord.Net.Commands/ModuleBase.cs index 808a26caa..9be7d1aeb 100644 --- a/src/Discord.Net.Commands/ModuleBase.cs +++ b/src/Discord.Net.Commands/ModuleBase.cs @@ -8,23 +8,14 @@ namespace Discord.Commands public abstract class ModuleBase : IModuleBase where T : class, ICommandContext { - public T Context - { - get { return _context; } - private set - { - _context = value; - ContextSet(); - } - } - private T _context; + public T Context { get; private set; } protected virtual async Task ReplyAsync(string message, bool isTTS = false, Embed embed = null, RequestOptions options = null) { return await Context.Channel.SendMessageAsync(message, isTTS, embed, options).ConfigureAwait(false); } - protected virtual void ContextSet() + protected virtual void OnContextSet() { } @@ -35,6 +26,7 @@ namespace Discord.Commands if (newValue == null) throw new InvalidOperationException($"Invalid context type. Expected {typeof(T).Name}, got {context.GetType().Name}"); Context = newValue; + OnContextSet(); } } }