Example #1
0
        public static bool Compare(IComparable operand1, IComparable operand2, Func <IComparable, IComparable, bool> compareFunc)
        {
            if (operand1 == null || operand2 == null)
            {
                return(false);
            }
            if (!OperationComparer.IsNumeric(operand1) || !OperationComparer.IsNumeric(operand2))
            {
                return(compareFunc(operand1, operand2));
            }
            Type type  = operand1.GetType();
            Type type2 = operand2.GetType();
            int  num;
            int  num2;

            if (!OperationComparer._typePrecedence.TryGetValue(type, out num) || !OperationComparer._typePrecedence.TryGetValue(type2, out num2))
            {
                return(compareFunc(operand1, operand2));
            }
            if (num < num2)
            {
                object obj;
                if (!OperationComparer.TryConvertOperand(operand1, type2, out obj))
                {
                    SharedObject.Instance.Output(SharedObject.enOutputType.Error, "FilterTypeWarning operand:" + operand1 + "type:" + type2);
                    return(false);
                }
                return(compareFunc((IComparable)obj, operand2));
            }
            else
            {
                if (num <= num2)
                {
                    object obj2;
                    OperationComparer.TryConvertOperand(operand1, typeof(double), out obj2);
                    object obj3;
                    OperationComparer.TryConvertOperand(operand2, typeof(double), out obj3);
                    return(compareFunc((IComparable)obj2, (IComparable)obj3));
                }
                object obj4;
                if (!OperationComparer.TryConvertOperand(operand2, type, out obj4))
                {
                    SharedObject.Instance.Output(SharedObject.enOutputType.Error, "FilterTypeWarning operand:" + operand1 + "type:" + type2);
                    return(false);
                }
                return(compareFunc(operand1, (IComparable)obj4));
            }
        }
Example #2
0
        public new static bool Equals(object operand1, object operand2)
        {
            if (operand1 == null && operand2 == null)
            {
                return(true);
            }
            if (operand1 == null || operand2 == null)
            {
                return(false);
            }
            if (!OperationComparer.IsNumeric(operand1) && !OperationComparer.IsNumeric(operand2))
            {
                return(operand1.Equals(operand2));
            }
            Type type  = operand1.GetType();
            Type type2 = operand2.GetType();
            int  num;
            int  num2;

            if (!OperationComparer._typePrecedence.TryGetValue(type, out num) || !OperationComparer._typePrecedence.TryGetValue(type2, out num2))
            {
                return(operand1.Equals(operand2));
            }
            if (num < num2)
            {
                object obj;
                if (!OperationComparer.TryConvertOperand(operand1, type2, out obj))
                {
                    SharedObject.Instance.Output(SharedObject.enOutputType.Error, "FilterTypeWarning operand:" + operand1 + "type:" + type2);
                    return(false);
                }
                return(operand2.Equals(obj));
            }
            else
            {
                if (num <= num2)
                {
                    return(operand1.Equals(operand2));
                }
                object obj2;
                if (!OperationComparer.TryConvertOperand(operand2, type, out obj2))
                {
                    SharedObject.Instance.Output(SharedObject.enOutputType.Error, "FilterTypeWarning operand:" + operand1 + "type:" + type2);
                    return(false);
                }
                return(operand1.Equals(obj2));
            }
        }