Cocona icon indicating copy to clipboard operation
Cocona copied to clipboard

Enable interface-wide command registration

Open DavidL344 opened this issue 10 months ago • 0 comments

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>();
}

DavidL344 avatar Feb 26 '25 12:02 DavidL344