SCSF/CAB 以编程方式添加 CommandHandler
有没有办法做到这一点:
[CommandHandler("ACommand")]
public void DoACommand(object sender, EventArgs e)
{
//DoSomething
}
以编程方式?
我不想使用属性,因为在这种情况下“ACommand”会发生变化,因为它是基类中的一般实现。 谢谢 伊恩
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当我开始使用 SCSF 进行开发时,我对命令/事件做了相当多的研究,但我还没有找到一种方法来做到这一点。在 WorkItem 加载时运行的方法中注册所有命令处理程序非常有用,而不是使用属性将它们分散在整个应用程序中。
在您的情况下,我唯一可以建议的是使用一个静态类,其中包含所有命令处理程序名称作为常量,例如 [CommandHandler(CommandNames.CreateEmployeeCommand)]。这种方法有几个好处: 1. 如果您的命令名称发生更改,您只需在静态类中更改它; 2. 您可以创建一个可以继承的 CommandNames 基类(当您使用 SCSF 时,这是为您完成的)由单个模块 CommandNames 类允许您拥有全局命令和模块特定命令。
我想知道您是否确实找到了一种方法来将此功能添加到您的解决方案中,因为这会非常有帮助。
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.
您可以使用全局命令集合(可通过任何工作项实例访问),选择命令并为 ExeceuteAction 事件注册事件处理程序。
示例(VB 语法):
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):