예제 #1
0
        /// <summary>
        /// Builds an operation that throws a <see cref="OpExecutionAbortedException"/>.
        /// </summary>
        /// <typeparam name="TResult">The type of result.</typeparam>
        /// <param name="condition">The condition.</param>
        /// <param name="statement">The statement to execute if the condition is true.</param>
        /// <param name="elseStatement">The statement to execute if the condition is false.</param>
        /// <returns>
        /// The operation.
        /// </returns>
        public static IfThenElseOp <TResult> IfThenElse <TResult>(
            IReturningOperation <bool> condition,
            IReturningOperation <TResult> statement,
            IReturningOperation <TResult> elseStatement)
        {
            var result = new IfThenElseOp <TResult>(condition, statement, elseStatement);

            return(result);
        }
예제 #2
0
        protected override OperationBase DeepCloneInternal()
        {
            var result = new IfThenElseOp <TResult>(
                this.Condition?.DeepClone(),
                this.Statement?.DeepClone(),
                this.ElseStatement?.DeepClone());

            return(result);
        }
예제 #3
0
        public IfThenElseOp <TResult> DeepCloneWithElseStatement(IReturningOperation <TResult> elseStatement)
        {
            var result = new IfThenElseOp <TResult>(
                this.Condition?.DeepClone(),
                this.Statement?.DeepClone(),
                elseStatement);

            return(result);
        }
예제 #4
0
        public IfThenElseOp <TResult> DeepCloneWithCondition(IReturningOperation <bool> condition)
        {
            var result = new IfThenElseOp <TResult>(
                condition,
                this.Statement?.DeepClone(),
                this.ElseStatement?.DeepClone());

            return(result);
        }
예제 #5
0
        /// <inheritdoc />
        public bool Equals(IfThenElseOp <TResult> other)
        {
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            if (ReferenceEquals(other, null))
            {
                return(false);
            }

            var result = this.Condition.IsEqualTo(other.Condition) &&
                         this.Statement.IsEqualTo(other.Statement) &&
                         this.ElseStatement.IsEqualTo(other.ElseStatement);

            return(result);
        }
예제 #6
0
        /// <inheritdoc />
        public async Task <TResult> ExecuteAsync(
            IfThenElseOp <TResult> operation)
        {
            if (operation == null)
            {
                throw new ArgumentNullException(nameof(operation));
            }

            TResult result;

            // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
            if (await this.protocolFactory.GetProtocolAndExecuteViaReflectionAsync <bool>(operation.Condition))
            {
                result = await this.protocolFactory.GetProtocolAndExecuteViaReflectionAsync <TResult>(operation.Statement);
            }
            else
            {
                result = await this.protocolFactory.GetProtocolAndExecuteViaReflectionAsync <TResult>(operation.ElseStatement);
            }

            return(result);
        }