public override ExpressionResult Evaluate(MemberExpression left, string op, ConstantExpression right)
        {
            if (!op.Is(SearchOperator.Contains))
            {
                return(base.Evaluate(left, op, right));
            }

            var searchTerm = IngredientSearchTerm.Parse(right?.Value?.ToString());

            var result = new ExpressionResult();

            if (searchTerm == null)
            {
                return(result);
            }

            result.ServerSide = GenerateContainsExpression(left, searchTerm.Name);

            if (searchTerm.Quantity == null || right == null)
            {
                return(result);
            }

            var genericType = left.Type.GetGenericArguments()[0];

            result.ClientSide = Expression.Call(
                typeof(IngredientExtensions),
                nameof(IngredientExtensions.IsMatch),
                new[] { genericType }, left, right);

            return(result);
        }
Exemple #2
0
        public static IngredientSearchTerm?Parse(string?criteria)
        {
            if (string.IsNullOrWhiteSpace(criteria))
            {
                return(null);
            }

            var result = new IngredientSearchTerm
            {
                Name = criteria
            };

            // First, check if the last but one token is any recognized search operator for this
            var    parts            = criteria.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            string?quantityAndUnits = null;

            if (parts.Length > 2)
            {
                foreach (var op in ValidSearchOperators)
                {
                    if (!parts[^ 2].Is(op))