public static FilterProperty Parse(string text) { using (var properties = text.Split('.').Cast <string>().GetEnumerator()) { properties.MoveNext(); var property = new FilterProperty(properties.Current); while (properties.MoveNext()) { property = new FilterProperty(properties.Current, property); } return(property); } }
private MemberExpression GetProperty(FilterProperty property) { Expression expression = Parameter; var type = Type; foreach (var name in property.GetProperties().Select(info => info.Name)) { var info = type.GetTypeInfo().GetProperty(name); if (info == null) { throw new InvalidOperationException($"Couldn't determine path '{name}' from type '${type.Name}'."); } expression = Expression.Property(expression, info); type = info.PropertyType; } return(expression as MemberExpression); }
private FilterExpressionBuilder <T> Contains(MethodInfo method, FilterProperty property, FilterValue value) { var member = GetProperty(property); var collection = member.Type.Name == typeof(ICollection <>).Name ? member.Type : member.Type.GetTypeInfo().GetInterface(typeof(ICollection <>).Name); if (collection == null) { throw new InvalidOperationException($"Property '{property}' does not implement '{typeof(ICollection<>)}'."); } var type = collection.GetTypeInfo().GetGenericArguments().Single(); var item = Expression.Parameter(type); var contains = Expression.Lambda(Expression.Call(null, FilterInfo.Contains.MakeGenericMethod(type), member, item), item); var call = Expression.Call(null, method.MakeGenericMethod(type), GetVectorValue(value, type), contains); _expressions.Push(call); return(this); }
public static Filter Parse(string text) { var or = Or.Match(text); if (or.Success) { return(new LogicalFilter ( Parse(or.Groups["Left"].Value), LogicalOperator.Or, Parse(or.Groups["Right"].Value) )); } var and = And.Match(text); if (and.Success) { return(new LogicalFilter ( Parse(and.Groups["Left"].Value), LogicalOperator.And, Parse(and.Groups["Right"].Value) )); } var predicate = Predicate.Match(text); if (predicate.Success) { return(new PredicateFilter ( FilterProperty.Parse(predicate.Groups["Property"].Value), PredicateOperator.Parse(predicate.Groups["Predicate"].Value), FilterValue.Parse(predicate.Groups["Value"].Value) )); } throw new ArgumentException($"Couldn't parse filter '{text}'."); }
public void NotEqual(FilterProperty property, FilterValue value) => _filter.Append($"{property}{PredicateOperatorString.NotEqual}{value}");
public void LessThan(FilterProperty property, FilterValue value) => _filter.Append($"{property}{PredicateOperatorString.LessThan}{value}");
public void Equal(FilterProperty left, FilterValue value) => _filter.Append($"{left}{PredicateOperatorString.Equal}{value}");
public void Any(FilterProperty property, FilterValue value) => _filter.Append($"{property}{PredicateOperatorString.Contains}{value}");
public FilterExpressionBuilder <T> NotEqual(FilterProperty property, FilterValue value) => Predicate(Expression.NotEqual, property, value, () => Expression.Constant(true));
public FilterExpressionBuilder <T> LessThanOrEqual(FilterProperty property, FilterValue value) => Predicate(Expression.LessThanOrEqual, property, value);
public FilterExpressionBuilder <T> GreaterThan(FilterProperty property, FilterValue value) => Predicate(Expression.GreaterThan, property, value);
public FilterExpressionBuilder <T> Any(FilterProperty property, FilterValue value) => Contains(FilterInfo.Any, property, value);
private FilterExpressionBuilder <T> Predicate(Func <Expression, Expression, Expression> factory, FilterProperty property, FilterValue value, Func <Expression> fallback = null) => Predicate(factory, GetProperty(property), value, fallback);
public PredicateFilter(FilterProperty property, PredicateOperator predicate, FilterValue value) { Property = property; Predicate = predicate; Value = value; }
public FilterProperty(string name, FilterProperty caller = null) { Name = name; Caller = caller; }