Pregunta

Is there a way to do this:

[CommandHandler("ACommand")]
public void DoACommand(object sender, EventArgs e)
{
    //DoSomething
}

programmatically ?

I don't want to use an attribute as "ACommand" in this case will change as it's a general implementation in a base class. Thanks Ian

¿Fue útil?

Solución

I did quite a bit of research in regards to the commands/events when I started developing with SCSF and I have not found a way to do this yet. It would be quite useful to register all your command handlers inside a method that runs when your WorkItem loads, instead of having them scattered throughout the application using attributes.

The only thing that I can suggest in your case is using a static class that contains all your Command handler names as constants such as [CommandHandler(CommandNames.CreateEmployeeCommand)]. This approach provides a couple benefits: 1. If your command name changes, you only have to change it in the static class and 2. you can create a base CommandNames class (this is done for you when you use SCSF) which can be inherited by the individual module CommandNames class allowing you to have global commands and module specific commands.

I would like to know if you did indeed find a way to add this functionality to your solution as it would be quite helpful.

Otros consejos

You can use the global command collection (accessible via any work item instance), pick your command and register an event handler for the ExeceuteAction event.

Example (VB-Syntax):

AddHandler workItem.Commands("ACommand").ExecuteAction, AddressOf DoACommand
RemoveHandlerHandler workItem.Commands("ACommand").ExecuteAction, AddressOf DoACommand
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top