artiso-solutions / CoVoX

MIT License
1 stars 1 forks source link

Support custom command types #68

Open tommasobertoni opened 3 years ago

tommasobertoni commented 3 years ago

A consumer may add additional properties to a command, like:

class MyCommand : Command { /* ... */ }

var myCmd = new MyCommand
{
    Id = "FindYellowBox",
    VoiceTriggers = new[] { "Find yellow box" },
    Object = "box",
    Color = "yellow",
};

At the moment in order to get this info back, the consumer needs to cast the command to its type:

covox.Recognized += (Command command, _) =>
{
    var myCmd = (MyCommand)command;
    // ...
};

Proposal: Allow to create a typed instance of the engine, and accept/return only typed commands:

var covox = new CovoxEngine<MyCommand>(config);

var cmds = new[] { new MyCommand() };
covox.RegisterCommands(cmds);

covox.Recognized += (MyCommand command, _) => { /* ... */ };