Esempio n. 1
0
        /// <summary>
        /// Evaluates the expression given a variable resolver.
        /// </summary>
        /// <param name="resolver">An object used to resolve variables that appear in the expression</param>
        /// <returns>True if the expression was true, false otherwise</returns>
        public bool Evaluate(IBooleanVariableResolver resolver)
        {
            if (Operands.Count == 0)
            {
                throw new ArgumentException("Nothing to evaluate");
            }

            if (Operators.Count != Operands.Count - 1)
            {
                throw new ArgumentException("Unexpected number of operators");
            }

            int operatorIndex = 0;

            foreach (var operand in Operands)
            {
                var currentValue = operand.Evaluate(resolver);

                if (operatorIndex <= Operators.Count - 1)
                {
                    var currentOperator = Operators[operatorIndex++];

                    if (currentValue == true && currentOperator == BooleanOperator.Or)
                    {
                        return(Not ? false : true);
                    }
                    else if (currentValue == false && currentOperator == BooleanOperator.And)
                    {
                        return(Not ? true : false);
                    }
                }
                else
                {
                    return(Not ? !currentValue : currentValue);
                }
            }

            throw new ArgumentException("This should never happen :)");
        }
 /// <summary>
 /// Uses the given resolver to resolve the target boolean variable
 /// </summary>
 /// <param name="resolver">The object used to resolve boolean variables</param>
 /// <returns>the result of the resolver</returns>
 public bool Evaluate(IBooleanVariableResolver resolver)
 {
     bool val = resolver.ResolveBoolean(this.VariableName);
     return Not ? !val : val;
 }
Esempio n. 3
0
        /// <summary>
        /// Uses the given resolver to resolve the target boolean variable
        /// </summary>
        /// <param name="resolver">The object used to resolve boolean variables</param>
        /// <returns>the result of the resolver</returns>
        public bool Evaluate(IBooleanVariableResolver resolver)
        {
            bool val = resolver.ResolveBoolean(this.VariableName);

            return(Not ? !val : val);
        }
        /// <summary>
        /// Evaluates the expression given a variable resolver.
        /// </summary>
        /// <param name="resolver">An object used to resolve variables that appear in the expression</param>
        /// <returns>True if the expression was true, false otherwise</returns>
        public bool Evaluate(IBooleanVariableResolver resolver)
        {
            if (Operands.Count == 0)
            {
                throw new ArgumentException("Nothing to evaluate");
            }

            if (Operators.Count != Operands.Count - 1)
            {
                throw new ArgumentException("Unexpected number of operators");
            }

            int operatorIndex = 0;
            foreach (var operand in Operands)
            {
                var currentValue = operand.Evaluate(resolver);

                if (operatorIndex <= Operators.Count - 1)
                {
                    var currentOperator = Operators[operatorIndex++];

                    if (currentValue == true && currentOperator == BooleanOperator.Or)
                    {
                        return Not ? false : true;
                    }
                    else if (currentValue == false && currentOperator == BooleanOperator.And)
                    {
                        return Not ? true : false;
                    }
                }
                else
                {
                    return Not ? !currentValue : currentValue;
                }
            }

            throw new ArgumentException("This should never happen :)");
        }