public IFilterOperation GenerateOperation <TData, TParam, TFilterLhs>(FilterOperationGeneratorData data, Filter <TData, TParam, TFilterLhs> filter, int operatorIndex, List <QueryError> errors) { Func <TData, TParam, bool> operation = (o, p) => false; var filterValue = ((ParseResult <TFilterRhs>)data.filterValueParseResult).parsedValue; var stringComparisonOptions = filter.overrideStringComparison ? filter.stringComparison : data.globalStringComparison; var handlerFound = false; var typedHandler = data.op.GetHandler <TFilterLhs, TFilterRhs>(); if (typedHandler != null) { operation = (o, p) => typedHandler(filter.GetData(o, p), filterValue, stringComparisonOptions); handlerFound = true; } if (!handlerFound) { var genericHandler = data.op.GetHandler <object, object>(); if (genericHandler != null) { operation = (o, p) => genericHandler(filter.GetData(o, p), filterValue, stringComparisonOptions); handlerFound = true; } } if (!handlerFound) { var error = $"No handler of type ({typeof(TFilterLhs)}, {typeof(TFilterRhs)}) or (object, object) found for operator {data.op.token}"; errors.Add(new QueryError(operatorIndex, data.op.token.Length, error)); } return(new FilterOperation <TData, TParam, TFilterLhs>(filter, data.op, data.filterValue, data.paramValue, operation)); }
public override IFilterOperation GenerateOperation(FilterOperationGeneratorData data, int operatorIndex, List <QueryError> errors) { if (resolver) { var filterValue = ((ParseResult <TFilter>)data.filterValueParseResult).parsedValue; // ReSharper disable once ConvertToLocalFunction Func <TData, bool> operation = o => Resolve(o, data.op, filterValue); return(new FilterOperation <TData, TFilter>(this, data.op, data.filterValue, operation)); } else { return(data.generator.GenerateOperation(data, this, operatorIndex, errors)); } }
private BaseFilterOperation <T> GenerateFilterOperation <T>(FilterNode node, QueryEngine <T> engine, ICollection <QueryError> errors) { var operatorIndex = node.token.position + node.filter.token.Length + (string.IsNullOrEmpty(node.paramValue) ? 0 : node.paramValue.Length); var filterValueIndex = operatorIndex + node.op.token.Length; Type filterValueType; IParseResult parseResult = null; if (QueryEngineUtils.IsNestedQueryToken(node.filterValue)) { if (node.filter?.queryHandlerTransformer == null) { errors.Add(new QueryError(filterValueIndex, node.filterValue.Length, $"No nested query handler transformer set on filter \"{node.filter.token}\".")); return(null); } filterValueType = node.filter.queryHandlerTransformer.rightHandSideType; } else { parseResult = engine.ParseFilterValue(node.filterValue, node.filter, node.op, out filterValueType); if (!parseResult.success) { errors.Add(new QueryError(filterValueIndex, node.filterValue.Length, $"The value \"{node.filterValue}\" could not be converted to any of the supported handler types.")); return(null); } } IFilterOperationGenerator generator = engine.GetGeneratorForType(filterValueType); if (generator == null) { errors.Add(new QueryError(filterValueIndex, node.filterValue.Length, $"Unknown type \"{filterValueType}\". Did you set an operator handler for this type?")); return(null); } var generatorData = new FilterOperationGeneratorData { filterValue = node.filterValue, filterValueParseResult = parseResult, globalStringComparison = engine.globalStringComparison, op = node.op, paramValue = node.paramValue, generator = generator }; var operation = node.filter.GenerateOperation(generatorData, operatorIndex, errors); return(operation as BaseFilterOperation <T>); }
public abstract IFilterOperation GenerateOperation(FilterOperationGeneratorData data, int operatorIndex, List <QueryError> errors);