public static LambdaExpression BuildPredicate(this FilterGroup filterGroup, Type type, VariableResolver variableResolver = null, IEnumerable <string> validProperties = null, IDictionary <string, string> propertyMapping = null) { if (filterGroup == null) { throw new ArgumentNullException(nameof(filterGroup)); } if (type == null) { throw new ArgumentNullException(nameof(type)); } var arg = new BuildArgument { ValidProperties = validProperties, EvaluationType = type, VariableResolver = variableResolver, PropertyMapping = propertyMapping }; if (!IsValid(filterGroup, arg)) { throw new InvalidOperationException("The operator or property name is not valid"); } return(FilterExtensions.BuildPredicateInternal(filterGroup.Filters, type, arg)); }
internal static EvaluationResult <T, bool> TryBuildPredicate <T>(this FilterGroup filterGroup, BuildArgument arg) { filterGroup.Filters.ForEach(f => { arg.IsValidProperty(f.Property); arg.IsValidOperator(f.Operator); }); if (arg.InvalidProperties.Any() || arg.InvalidOperators.Any()) { return(new EvaluationResult <T, bool> { InvalidProperties = arg.InvalidProperties, InvalidOperators = arg.InvalidOperators }); } try { var expression = (Expression <Func <T, bool> >)FilterExtensions.BuildPredicateInternal(filterGroup.Filters, typeof(T), arg); return(new EvaluationResult <T, bool> { Result = expression, Succeeded = true }); } catch (Exception ex) { return(new EvaluationResult <T, bool> { Exception = ex }); } }