예제 #1
0
 private bool Compare()
 {
     if (this.AssociatedObject != null)
     {
         return(ComparisonLogic.EvaluateImpl(this.Binding, this.Comparison, this.Value));
     }
     return(false);
 }
예제 #2
0
        /// <summary>
        /// This method evaluates operands.
        /// </summary>
        /// <param name="leftOperand">Left operand from the LeftOperand property.</param>
        /// <param name="operatorType">Operator from Operator property.</param>
        /// <param name="rightOperand">Right operand from the RightOperand property.</param>
        /// <returns>Returns true if the condition is met; otherwise, returns false.</returns>
        internal static bool EvaluateImpl(object leftOperand, ComparisonConditionType operatorType, object rightOperand)
        {
            bool result = false;

            if (leftOperand != null)
            {
                Type leftType = leftOperand.GetType();

                if (rightOperand != null)
                {
                    TypeConverter typeConverter = TypeConverterHelper.GetTypeConverter(leftType);
                    rightOperand = TypeConverterHelper.DoConversionFrom(typeConverter, rightOperand);
                }
            }

            IComparable leftComparableOperand  = leftOperand as IComparable;
            IComparable rightComparableOperand = rightOperand as IComparable;

            // If both operands are comparable, use arithmetic comparison
            if (leftComparableOperand != null && rightComparableOperand != null)
            {
                return(ComparisonLogic.EvaluateComparable(leftComparableOperand, operatorType, rightComparableOperand));
            }

            switch (operatorType)
            {
            case ComparisonConditionType.Equal:
                result = object.Equals(leftOperand, rightOperand);
                break;

            case ComparisonConditionType.NotEqual:
                result = !object.Equals(leftOperand, rightOperand);
                break;

            case ComparisonConditionType.GreaterThan:
            case ComparisonConditionType.GreaterThanOrEqual:
            case ComparisonConditionType.LessThan:
            case ComparisonConditionType.LessThanOrEqual:
                if (leftComparableOperand == null && rightComparableOperand == null)
                {
                    throw new ArgumentException();
                }
                else if (leftComparableOperand == null)
                {
                    throw new ArgumentException();
                }
                else
                {
                    throw new ArgumentException();
                }
            }
            return(result);
        }
예제 #3
0
        private void Evaluate()
        {
            if (this.TargetObject != null)
            {
                string stateName = null;
                if (ComparisonLogic.EvaluateImpl(this.Binding, ComparisonConditionType.Equal, this.Value))
                {
                    stateName = this.TrueState;
                }
                else
                {
                    stateName = this.FalseState;
                }

                VisualStateUtilities.GoToState(this.TargetObject, stateName, true);
            }
        }
 /// <summary>
 /// Method that evaluates the condition. Note that this method can throw ArgumentException if the operator is
 /// incompatible with the type. For instance, operators LessThan, LessThanOrEqual, GreaterThan, and GreaterThanOrEqual
 /// require both operators to implement IComparable.
 /// </summary>
 /// <returns>Returns true if the condition has been met; otherwise, returns false.</returns>
 public bool Evaluate()
 {
     this.EnsureBindingUpToDate();
     return(ComparisonLogic.EvaluateImpl(this.LeftOperand, this.Operator, this.RightOperand));
 }