Example #1
0
        public IFilterOperation GenerateOperation <TData, TFilterLhs>(FilterOperationGeneratorData data, RegexFilter <TData, TFilterLhs> filter, int operatorIndex, ICollection <QueryError> errors)
        {
            var stringComparisonOptions = filter.overridesStringComparison ? filter.stringComparison : data.globalStringComparison;
            var filterOperatorContext   = new FilterOperatorContext(filter);
            Func <TData, TFilterRhs, bool> operation = (o, filterValue) => false;

            var handlerFound = false;
            var typedHandler = data.op.GetHandler <TFilterLhs, TFilterRhs>();

            if (typedHandler != null)
            {
                operation    = (o, filterValue) => typedHandler(filterOperatorContext, filter.GetData(o, data.filterName), filterValue, stringComparisonOptions);
                handlerFound = true;
            }

            if (!handlerFound)
            {
                var genericHandler = data.op.GetHandler <object, object>();
                if (genericHandler != null)
                {
                    operation    = (o, filterValue) => genericHandler(filterOperatorContext, filter.GetData(o, data.filterName), 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(null);
            }

            var filterOperation = new FilterOperation <TData, TFilterLhs, TFilterRhs>(filter, in data.op, data.filterValue, operation);

            if (data.filterValueParseResult != null)
            {
                var filterValue = ((ParseResult <TFilterRhs>)data.filterValueParseResult).parsedValue;
                filterOperation.SetFilterValue(filterValue);
            }

            return(filterOperation);
        }
Example #2
0
 public bool Invoke(FilterOperatorContext ctx, object ev, object fv, StringComparison sc)
 {
     return(handler(ctx, (TLhs)ev, (TRhs)fv, sc));
 }