Exemplo n.º 1
0
        private bool _PerformComparison(string query, object target, string operation)
        {
            var evaluator = string.IsNullOrEmpty(operation)
                                                                ? Evaluators.FirstOrDefault()
                                                                : Evaluators.FirstOrDefault(e => e.Operation == operation);

            if (evaluator == null)
            {
                return(false);
            }

            if (target is bool b)
            {
                return(bool.TryParse(query, out var boolQuery) && evaluator.Match(boolQuery, b));
            }

            if (target is sbyte || target is byte || target is char ||
                target is short || target is ushort ||
                target is int || target is uint ||
                target is long || target is ulong ||
                target is float || target is double ||
                target is decimal)
            {
                return(double.TryParse(query, out var doubleQuery) && evaluator.Match(doubleQuery, Convert.ToDouble(target)));
            }

            return(evaluator.Match(query, target?.ToString(), IsCaseSensitive));
        }