[feat] Abyssctl Basic functions
This commit is contained in:
28
abyssctl/App/Attributes/ModuleAttribute.cs
Normal file
28
abyssctl/App/Attributes/ModuleAttribute.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Reflection;
|
||||
using abyssctl.App.Interfaces;
|
||||
using CommandLine;
|
||||
|
||||
namespace abyssctl.App.Attributes;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
|
||||
public class ModuleAttribute(int head) : Attribute
|
||||
{
|
||||
public int Head { get; } = head;
|
||||
|
||||
public static Type[] Modules
|
||||
{
|
||||
get
|
||||
{
|
||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||
const string targetNamespace = "abyssctl.App.Modules";
|
||||
|
||||
return assembly.GetTypes()
|
||||
.Where(t => t is { IsClass: true, IsAbstract: false, IsInterface: false })
|
||||
.Where(t => t.Namespace == targetNamespace)
|
||||
.Where(t => typeof(IOptions).IsAssignableFrom(t))
|
||||
.Where(t => t.IsDefined(typeof(VerbAttribute), inherit: true))
|
||||
.Where(t => t.IsDefined(typeof(ModuleAttribute), inherit: false))
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user