protected virtual object Execute(TContext context) { if (context == null) { throw new ArgumentNullException("context"); } //创建事件参数对象 var executingArgs = new CommandExecutorExecutingEventArgs(context); //激发“Executing”事件 this.OnExecuting(executingArgs); if (executingArgs.Cancel) { return(executingArgs.Result); } //执行命令 this.OnExecute(context); //创建事件参数对象 var executedArgs = new CommandExecutorExecutedEventArgs(context); //激发“Executed”事件 this.OnExecuted(executedArgs); //返回最终的执行结果 return(context.Result); }
protected virtual void OnExecuting(CommandExecutorExecutingEventArgs args) { var executing = this.Executing; if (executing != null) { executing(this, args); } }