public Expression Compile(IEnumerable <Expression> expressions, Expression parentContext, string templatePath = null)
 {
     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 = CommentVisitor.Visit(expression, compilationContext);
         expression = UnencodedStatementVisitor.Visit(expression, compilationContext);
         expression = PartialBinder.Bind(expression, compilationContext);
         expression = StaticReplacer.Replace(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 = SubExpressionVisitor.Visit(expression, compilationContext);
         expression = ContextBinder.Bind(expression, compilationContext, parentContext, templatePath);
         return(expression);
     }
     catch (Exception ex)
     {
         throw new HandlebarsCompilerException("An unhandled exception occurred while trying to compile the template", ex);
     }
 }
Пример #2
0
        public Expression Compile(IEnumerable <Expression> expressions, Expression parentContext, string templateName = null)
        {
            try
            {
                var expressionsList = expressions as IList <Expression> ?? expressions.ToList();

                if (expressionsList.Count == 0)
                {
                    return(EmptyLambda);
                }
                if (expressionsList.Count == 1 && expressionsList[0] is DefaultExpression)
                {
                    return(EmptyLambda);
                }
                var compilationContext = new CompilationContext(_engine);
                var expression         = CreateExpressionBlock(expressionsList);
                expression = CommentVisitor.Visit(expression, compilationContext);
                expression = UnencodedStatementVisitor.Visit(expression, compilationContext);
                expression = PartialBinder.Bind(expression, compilationContext);
                expression = StaticReplacer.Replace(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 = SubExpressionVisitor.Visit(expression, compilationContext);
                expression = ContextBinder.Bind(expression, compilationContext, parentContext, templateName);
                return(expression);
            }
            catch (Exception ex)
            {
                throw new HandlebarsCompilerException("An unhandled exception occurred while trying to compile the template.", ex);
            }
        }