From 6e42acba687083d772790c3bc84e3e8f9f9d31da Mon Sep 17 00:00:00 2001 From: Christopher F Date: Wed, 20 Jul 2016 17:20:37 -0400 Subject: [PATCH] Add Autoload to Module Attribute [UNTESTED] Adds an optional parameter to the Module attribute, "autoload", which defaults to true. Specifies whether or not the assembly crawler should load this module. --- src/Discord.Net.Commands/Attributes/ModuleAttribute.cs | 7 +++++-- src/Discord.Net.Commands/CommandService.cs | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Discord.Net.Commands/Attributes/ModuleAttribute.cs b/src/Discord.Net.Commands/Attributes/ModuleAttribute.cs index 59e6a6aca..57f525389 100644 --- a/src/Discord.Net.Commands/Attributes/ModuleAttribute.cs +++ b/src/Discord.Net.Commands/Attributes/ModuleAttribute.cs @@ -6,13 +6,16 @@ namespace Discord.Commands public class ModuleAttribute : Attribute { public string Prefix { get; } - public ModuleAttribute() + public bool Autoload { get; } + public ModuleAttribute(bool autoload = true) { Prefix = null; + Autoload = autoload; } - public ModuleAttribute(string prefix) + public ModuleAttribute(string prefix, bool autoload = true) { Prefix = prefix; + Autoload = autoload; } } } diff --git a/src/Discord.Net.Commands/CommandService.cs b/src/Discord.Net.Commands/CommandService.cs index f762ae366..9fd8aecc9 100644 --- a/src/Discord.Net.Commands/CommandService.cs +++ b/src/Discord.Net.Commands/CommandService.cs @@ -174,7 +174,7 @@ namespace Discord.Commands { var typeInfo = type.GetTypeInfo(); var moduleAttr = typeInfo.GetCustomAttribute(); - if (moduleAttr != null) + if (moduleAttr != null && moduleAttr.Autoload) { var moduleInstance = ReflectionUtils.CreateObject(typeInfo); modules.Add(LoadInternal(moduleInstance, moduleAttr, typeInfo));