Example #1
0
        public ExpressionConverter()
        {
            _entityProperties = MappedEntity <TModel, TEntity> .EntityProperties;

            _propertyMap      = new PropertyConverterMap(MappedEntity <TModel, TEntity> .PropertyMap.Cast <PropertyConverter>());
            _defaultVisitor   = new DefaultExpressionVisitor();
            _parameterVisitor = new ParameterExpressionVisitor(_propertyMap);
        }
Example #2
0
        public static IExpression <T> Parse <T>(string expression, IPropertyValueProvider <T> valueProvider)
        {
            var sw          = Stopwatch.StartNew();
            var charStream  = new AntlrInputStream(expression);
            var lexer       = new ExpressionLexer(charStream);
            var tokenStream = new CommonTokenStream(lexer);
            var parser      = new ExpressionParser(tokenStream);
            var visitor     = new DefaultExpressionVisitor <T>(valueProvider);

            sw.Stop();
            Console.WriteLine("  Setup: " + sw.ElapsedMilliseconds);
            sw.Restart();
            var exprContext = parser.expr();

            sw.Stop();
            Console.WriteLine("  Parse: " + sw.ElapsedMilliseconds);
            sw.Restart();
            var expr = visitor.Visit(exprContext);

            sw.Stop();
            Console.WriteLine("  Visit: " + sw.ElapsedMilliseconds);
            return(expr);
        }