Пример #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);
     }
 }
Пример #2
0
        public static Action <BindingContext, TextWriter, object> CompileCore(IEnumerable <Expression> expressions, InternalHandlebarsConfiguration configuration, string templatePath = null)
        {
            try
            {
                if (!expressions.Any())
                {
                    return(EmptyLambdaWithContext);
                }
                if (expressions.IsOneOf <Expression, DefaultExpression>())
                {
                    return(EmptyLambdaWithContext);
                }

                var context    = new CompilationContext(configuration);
                var expression = (Expression)Expression.Block(expressions);
                expression = Reduce(expression, context);

                var lambda = ContextBinder.Bind(context, expression, templatePath);
                return(configuration.CompileTimeConfiguration.ExpressionCompiler.Compile(lambda));
            }
            catch (Exception ex)
            {
                throw new HandlebarsCompilerException("An unhandled exception occurred while trying to compile the template", ex);
            }
        }