internal static bool EvaluateImpl()

in src/Microsoft.Xaml.Behaviors/ComparisonLogic.cs [19:80]


        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(string.Format(CultureInfo.CurrentCulture,
                                                            ExceptionStringTable.InvalidOperands,
                                                            leftOperand != null ? leftOperand.GetType().Name : "null",
                                                            rightOperand != null ? rightOperand.GetType().Name : "null",
                                                            operatorType.ToString()));
                    }
                    else if (leftComparableOperand == null)
                    {
                        throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
                                                            ExceptionStringTable.InvalidLeftOperand,
                                                            leftOperand != null ? leftOperand.GetType().Name : "null",
                                                            operatorType.ToString()));
                    }
                    else
                    {
                        throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
                                        ExceptionStringTable.InvalidRightOperand,
                                        rightOperand != null ? rightOperand.GetType().Name : "null",
                                        operatorType.ToString()));
                    }
            }
            return result;
        }