private FilterExpression CreateFilterByIds <TId>(ICollection <TId> ids, AttrAttribute idAttribute, FilterExpression existingFilter) { var idChain = new ResourceFieldChainExpression(idAttribute); FilterExpression filter = null; if (ids.Count == 1) { var constant = new LiteralConstantExpression(ids.Single().ToString()); filter = new ComparisonExpression(ComparisonOperator.Equals, idChain, constant); } else if (ids.Count > 1) { var constants = ids.Select(id => new LiteralConstantExpression(id.ToString())).ToList(); filter = new EqualsAnyOfExpression(idChain, constants); } // @formatter:keep_existing_linebreaks true return(filter == null ? existingFilter : existingFilter == null ? filter : new LogicalExpression(LogicalOperator.And, ArrayFactory.Create(filter, existingFilter))); // @formatter:keep_existing_linebreaks restore }
public override QueryExpression VisitEqualsAnyOf(EqualsAnyOfExpression expression, object argument) { PropertyInfo property = expression.TargetAttribute.Fields.Last().Property; if (IsCarId(property)) { string[] carStringIds = expression.Constants.Select(constant => constant.Value).ToArray(); return(RewriteFilterOnCarStringIds(expression.TargetAttribute, carStringIds)); } return(base.VisitEqualsAnyOf(expression, argument)); }
public override Expression VisitEqualsAnyOf(EqualsAnyOfExpression expression, Type argument) { Expression property = Visit(expression.TargetAttribute, argument); var valueList = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(property.Type)); foreach (LiteralConstantExpression constant in expression.Constants) { object value = ConvertTextToTargetType(constant.Value, property.Type); valueList !.Add(value); } ConstantExpression collection = Expression.Constant(valueList); return(ContainsExtensionMethodCall(collection, property)); }