Beispiel #1
0
        /// <summary>
        /// Execute a task if the predicate returns true.
        /// </summary>
        /// <param name="host">The host that will be used to execute the method.</param>
        /// <param name="method">The method to execute if the predicate returns true.</param>
        /// <returns>A task that represents the asynchronous operation.</returns>
        public static async Task <IHost> Else(this ElseExecuteHost host, Func <IHost, Task <IHost> > method)
        {
            if (!host.CanElseExecute)
            {
                return(host.Unwrap());
            }

            return(await method(host));
        }
Beispiel #2
0
        /// <summary>
        /// Execute a task if the predicate returns true.
        /// </summary>
        /// <param name="host">The host that will be used to execute the method.</param>
        /// <param name="method">The method to execute if the predicate returns true.</param>
        /// <returns>The host.</returns>
        public static IHost Else(this ElseExecuteHost host, Func <IHost, IHost> method)
        {
            if (!host.CanElseExecute)
            {
                return(host.Unwrap());
            }

            return(method(host));
        }
Beispiel #3
0
        /// <summary>
        /// Execute a task if the predicate returns true.
        /// </summary>
        /// <param name="host">The host that will be used to execute the method.</param>
        /// <param name="predicate">The predicate.</param>
        /// <param name="method">The method to execute if the predicate returns true.</param>
        /// <returns>A task that represents the asynchronous operation.</returns>
        public static async Task <ElseExecuteHost> ElseIf(this ElseExecuteHost host, Func <IHost, Task <bool> > predicate, Func <IHost, Task <IHost> > method)
        {
            if (!host.CanElseExecute)
            {
                return(host);
            }

            return(await predicate(host)
                ? new ElseExecuteHost(await method(host), false)
                : new ElseExecuteHost(host, true));
        }
Beispiel #4
0
        /// <summary>
        /// Execute a task if the predicate returns true.
        /// </summary>
        /// <param name="host">The host that will be used to execute the method.</param>
        /// <param name="predicate">The predicate.</param>
        /// <param name="method">The method to execute if the predicate returns true.</param>
        /// <returns>The host.</returns>
        public static ElseExecuteHost ElseIf(this ElseExecuteHost host, Func <IHost, bool> predicate, Func <IHost, IHost> method)
        {
            if (!host.CanElseExecute)
            {
                return(host);
            }

            return(predicate(host)
                ? new ElseExecuteHost(method(host), false)
                : new ElseExecuteHost(host, true));
        }