Esempio n. 1
0
 public Expression Compile(IEnumerable <Expression> expressions, Expression parentContext)
 {
     try
     {
         if (expressions.Any() == false)
         {
             return(_emptyLambda);
         }
         if (expressions.IsOneOf <Expression, DefaultExpression>() == true)
         {
             return(_emptyLambda);
         }
         var compilationContext = new CompilationContext(_configuration);
         var expression         = CreateExpressionBlock(expressions);
         expression = StaticReplacer.Replace(expression, compilationContext);
         expression = UnencodedStatementVisitor.Visit(expression, compilationContext);
         expression = PartialBinder.Bind(expression, compilationContext);
         expression = IteratorBinder.Bind(expression, compilationContext);
         expression = BlockHelperFunctionBinder.Bind(expression, compilationContext);
         expression = DeferredSectionVisitor.Bind(expression, compilationContext);
         expression = HelperFunctionBinder.Bind(expression, compilationContext);
         expression = BoolishConverter.Convert(expression, compilationContext);
         expression = PathBinder.Bind(expression, compilationContext);
         expression = ContextBinder.Bind(expression, compilationContext, parentContext);
         return(expression);
     }
     catch (Exception ex)
     {
         throw new HandlebarsCompilerException("An unhandled exception occurred while trying to compile the template", ex);
     }
 }
        public static Expression Reduce(Expression expression, CompilationContext context)
        {
            expression = new CommentVisitor().Visit(expression);
            expression = new UnencodedStatementVisitor(context).Visit(expression);
            expression = new PartialBinder(context).Visit(expression);
            expression = new StaticReplacer(context).Visit(expression);
            expression = new IteratorBinder(context).Visit(expression);
            expression = new BlockHelperFunctionBinder(context).Visit(expression);
            expression = new HelperFunctionBinder(context).Visit(expression);
            expression = new BoolishConverter(context).Visit(expression);
            expression = new PathBinder(context).Visit(expression);
            expression = new SubExpressionVisitor(context).Visit(expression);
            expression = new HashParameterBinder().Visit(expression);

            return(expression);
        }