Esempio n. 1
0
        public FilterOperator AddHandler <TLhs, TRhs>(Func <TLhs, TRhs, StringComparison, bool> handler)
        {
            var operatorTypes = new FilterOperatorTypes(typeof(TLhs), typeof(TRhs));

            if (handlers.ContainsKey(operatorTypes))
            {
                handlers[operatorTypes] = handler;
            }
            else
            {
                handlers.Add(operatorTypes, handler);
            }
            return(this);
        }
Esempio n. 2
0
        public virtual IFilterOperation GenerateOperation(int operatorIndex, List <QueryError> errors, QueryEngineImpl <TObject> engine)
        {
            Func <TObject, bool> operation = o => false;
            var filterValue             = m_FilterValueParseResult.parsedValue;
            var handlerTypedKey         = new FilterOperatorTypes(typeof(TFilterVariable), typeof(TFilterConstant));
            var handlerGenericKey       = new FilterOperatorTypes(typeof(object), typeof(object));
            var stringComparisonOptions = m_Filter.overrideStringComparison ? m_Filter.stringComparison : engine.globalStringComparison;

            var error = "";

            if (m_Operator.handlers.ContainsKey(handlerTypedKey))
            {
                if (!(m_Operator.handlers[handlerTypedKey] is Func <TFilterVariable, TFilterConstant, StringComparison, bool> handler))
                {
                    error = $"Filter operator handler of type ({handlerTypedKey.leftHandSideType}, {handlerTypedKey.rightHandSideType}) could not be" +
                            $" converted to Func<{handlerTypedKey.leftHandSideType}, {handlerTypedKey.rightHandSideType}, bool>";
                    errors.Add(new QueryError(operatorIndex, error));
                }
                else
                {
                    operation = o => handler(m_Filter.GetData(o), filterValue, stringComparisonOptions);
                }
            }