namespace Caliburn.Micro.Core { using System; /// /// Extension methods for instances. /// public static class ResultExtensions { /// /// Adds behavior to the result which is executed when the was cancelled. /// /// The result to decorate. /// The coroutine to execute when was canceled. /// public static IResult WhenCancelled(this IResult result, Func coroutine) { return new ContinueResultDecorator(result, coroutine); } /// /// Overrides of the decorated instance. /// /// The result to decorate. /// public static IResult OverrideCancel(this IResult result) { return new OverrideCancelResultDecorator(result); } /// /// Rescues from the decorated by executing a coroutine. /// /// The type of the exception we want to perform the rescue on. /// The result to decorate. /// The rescue coroutine. /// Set to true to cancel the result after executing rescue. /// public static IResult Rescue(this IResult result, Func rescue, bool cancelResult = true) where TException : Exception { return new RescueResultDecorator(result, rescue, cancelResult); } /// /// Rescues any exception from the decorated by executing a coroutine. /// /// The result to decorate. /// The rescue coroutine. /// Set to true to cancel the result after executing rescue. /// public static IResult Rescue(this IResult result, Func rescue, bool cancelResult = true) { return Rescue(result, rescue, cancelResult); } } }