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.
This commit is contained in:
@@ -6,13 +6,16 @@ namespace Discord.Commands
|
|||||||
public class ModuleAttribute : Attribute
|
public class ModuleAttribute : Attribute
|
||||||
{
|
{
|
||||||
public string Prefix { get; }
|
public string Prefix { get; }
|
||||||
public ModuleAttribute()
|
public bool Autoload { get; }
|
||||||
|
public ModuleAttribute(bool autoload = true)
|
||||||
{
|
{
|
||||||
Prefix = null;
|
Prefix = null;
|
||||||
|
Autoload = autoload;
|
||||||
}
|
}
|
||||||
public ModuleAttribute(string prefix)
|
public ModuleAttribute(string prefix, bool autoload = true)
|
||||||
{
|
{
|
||||||
Prefix = prefix;
|
Prefix = prefix;
|
||||||
|
Autoload = autoload;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ namespace Discord.Commands
|
|||||||
{
|
{
|
||||||
var typeInfo = type.GetTypeInfo();
|
var typeInfo = type.GetTypeInfo();
|
||||||
var moduleAttr = typeInfo.GetCustomAttribute<ModuleAttribute>();
|
var moduleAttr = typeInfo.GetCustomAttribute<ModuleAttribute>();
|
||||||
if (moduleAttr != null)
|
if (moduleAttr != null && moduleAttr.Autoload)
|
||||||
{
|
{
|
||||||
var moduleInstance = ReflectionUtils.CreateObject(typeInfo);
|
var moduleInstance = ReflectionUtils.CreateObject(typeInfo);
|
||||||
modules.Add(LoadInternal(moduleInstance, moduleAttr, typeInfo));
|
modules.Add(LoadInternal(moduleInstance, moduleAttr, typeInfo));
|
||||||
|
|||||||
Reference in New Issue
Block a user