namespace Caliburn.Micro.Core { using System; /// /// Base class for all decorators. /// public abstract class ResultDecoratorBase : IResult { readonly IResult innerResult; CoroutineExecutionContext context; /// /// Initializes a new instance of the class. /// /// The result to decorate. protected ResultDecoratorBase(IResult result) { if (result == null) throw new ArgumentNullException("result"); innerResult = result; } /// /// Executes the result using the specified context. /// /// The context. public void Execute(CoroutineExecutionContext context) { this.context = context; try { innerResult.Completed += InnerResultCompleted; IoC.BuildUp(innerResult); innerResult.Execute(this.context); } catch (Exception ex) { InnerResultCompleted(innerResult, new ResultCompletionEventArgs { Error = ex }); } } void InnerResultCompleted(object sender, ResultCompletionEventArgs args) { innerResult.Completed -= InnerResultCompleted; OnInnerResultCompleted(context, innerResult, args); context = null; } /// /// Called when the execution of the decorated result has completed. /// /// The context. /// The decorated result. /// The instance containing the event data. protected abstract void OnInnerResultCompleted(CoroutineExecutionContext context, IResult innerResult, ResultCompletionEventArgs args); /// /// Occurs when execution has completed. /// public event EventHandler Completed = delegate { }; /// /// Raises the event. /// /// The instance containing the event data. protected void OnCompleted(ResultCompletionEventArgs args) { Completed(this, args); } } }