Review this generated command catalog before it scans application assemblies.
Build a catalog once at startup, preserve every direct and inherited alias, safely handle unmarked types, and keep discovery free of external side effects.
csharp
using System;
using System.IO;
using System.Linq;
using System.Reflection;
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
public sealed class CommandAttribute : Attribute
{
public string Name { get; }
public CommandAttribute(string name)
{
File.AppendAllText("command-discovery.log", name + Environment.NewLine);
Name = name;
}
}
public static class CommandCatalog
{
public static string[] Build(Type[] handlerTypes)
{
return handlerTypes.Select(type =>
type.GetCustomAttribute<CommandAttribute>(inherit: false)!.Name).ToArray();
}
}
generated code is illustrative, not from any one model