Cocona
Cocona copied to clipboard
Enable interface-wide command registration
This PR enables registering all command classes inheriting from a shared interface.
// Rather than adding all command classes individually...
app.AddCommands<MyCommand1>();
app.AddCommands<MyCommand2>();
app.AddCommands<MyCommand3>();
// ...you can add an interface the command classes inherit from!
interface ICommands { }
class MyCommand1 : ICommands { ... }
class MyCommand2 : ICommands { ... }
class MyCommand3 : ICommands { ... }
app.AddCommands<ICommands>();
This could also be potentially useful for command registration branching, where certain requirements need to be met for a specific set of commands to work:
// For debugging
if (Debugger.IsAttached)
{
app.AddCommands<IDebugCommands>();
}
// For Windows-specific features of a cross-platform tool
if (OperatingSystem.IsWindows())
{
app.AddCommands<IWindowsCommands>();
}