Example #1
0
        private static object EvalSubtract(object a, object b)
        {
            if (a == null)
            {
                throw new ArgumentNullException(nameof(a));
            }

            if (b == null)
            {
                throw new ArgumentNullException(nameof(b));
            }

            if (a.IsInteger() && b.IsInteger())
            {
                return(Convert.ToInt64(a, CultureInfo.InvariantCulture) - Convert.ToInt64(b, CultureInfo.InvariantCulture));
            }

            return(FunctionUtils.CultureInvariantDoubleConvert(a) - FunctionUtils.CultureInvariantDoubleConvert(b));
        }
Example #2
0
        private static object EvalMax(object a, object b)
        {
            if (a == null)
            {
                throw new ArgumentNullException(nameof(a));
            }

            if (b == null)
            {
                throw new ArgumentNullException(nameof(b));
            }

            if (FunctionUtils.CultureInvariantDoubleConvert(a) > FunctionUtils.CultureInvariantDoubleConvert(b))
            {
                return(a);
            }

            return(b);
        }
        private static bool Function(IReadOnlyList <object> args)
        {
            if (args[0] == null || args[1] == null)
            {
                // null will only equals to null
                return(args[0] == null && args[1] == null);
            }

            if (FunctionUtils.TryParseList(args[0], out IList l0) && l0.Count == 0 && (FunctionUtils.TryParseList(args[1], out IList l1) && l1.Count == 0))
            {
                return(true);
            }

            if (GetPropertyCount(args[0]) == 0 && GetPropertyCount(args[1]) == 0)
            {
                return(true);
            }

            if (args[0].IsNumber() && args[0].IsNumber())
            {
                if (Math.Abs(FunctionUtils.CultureInvariantDoubleConvert(args[0]) - FunctionUtils.CultureInvariantDoubleConvert(args[1])) < double.Epsilon)
                {
                    return(true);
                }
            }

            try
            {
                return(args[0] == args[1] || (args[0] != null && args[0].Equals(args[1])));
            }
#pragma warning disable CA1031 // Do not catch general exception types (we return false if it fails for whatever reason)
            catch
#pragma warning restore CA1031 // Do not catch general exception types
            {
                return(false);
            }
        }
 private static bool Function(IReadOnlyList <object> args)
 {
     return(FunctionUtils.CultureInvariantDoubleConvert(args[0]) >= FunctionUtils.CultureInvariantDoubleConvert(args[1]));
 }
Example #5
0
 private static EvaluateExpressionDelegate Evaluator()
 {
     return(FunctionUtils.Apply(args => FunctionUtils.CultureInvariantDoubleConvert(args[0])));
 }
Example #6
0
 private static EvaluateExpressionDelegate Evaluator()
 {
     return(FunctionUtils.Apply(args => Extensions.IsNumber(args[0]) && FunctionUtils.CultureInvariantDoubleConvert(args[0]) % 1 != 0));
 }
Example #7
0
 private static object Evaluator(IReadOnlyList <object> args)
 {
     return(Math.Pow(FunctionUtils.CultureInvariantDoubleConvert(args[0]), FunctionUtils.CultureInvariantDoubleConvert(args[1])));
 }