protected override Expression VisitPartialExpression(PartialExpression pex) { var bindingContext = CompilationContext.Args.BindingContext; var writer = CompilationContext.Args.EncodedWriter; var partialBlockTemplate = pex.Fallback != null ? FunctionBuilder.Compile(new[] { pex.Fallback }, new CompilationContext(CompilationContext)) : null; if (pex.Argument != null || partialBlockTemplate != null) { var value = pex.Argument != null ? Arg<object>(FunctionBuilder.Reduce(pex.Argument, CompilationContext)) : bindingContext.Property(o => o.Value); var partialTemplate = Arg(partialBlockTemplate); bindingContext = bindingContext.Call(o => o.CreateChildContext(value, partialTemplate)); } var partialName = Cast<string>(pex.PartialName); var configuration = Arg(CompilationContext.Configuration); return Call(() => InvokePartialWithFallback(partialName, bindingContext, writer, (ICompiledHandlebarsConfiguration) configuration) ); }
protected override Expression VisitPartialExpression(PartialExpression pex) { Expression bindingContext = CompilationContext.BindingContext; if (pex.Argument != null) { bindingContext = Expression.Call( bindingContext, #if netstandard typeof(BindingContext).GetTypeInfo().GetMethod("CreateChildContext"), #else typeof(BindingContext).GetMethod("CreateChildContext"), #endif pex.Argument); } return(Expression.Call( #if netstandard new Action <string, BindingContext, HandlebarsConfiguration>(InvokePartial).GetMethodInfo(), #else new Action <string, BindingContext, HandlebarsConfiguration>(InvokePartial).Method, #endif Expression.Convert(pex.PartialName, typeof(string)), bindingContext, Expression.Constant(CompilationContext.Configuration))); }
protected override Expression VisitPartialExpression(PartialExpression pex) { Expression bindingContext = CompilationContext.BindingContext; var fb = new FunctionBuilder(CompilationContext.Configuration); var partialBlockTemplate = pex.Fallback == null ? null : fb.Compile(new[] { pex.Fallback }, null, null); if (pex.Argument != null || partialBlockTemplate != null) { bindingContext = Expression.Call( bindingContext, typeof(BindingContext).GetMethod("CreateChildContext"), pex.Argument ?? Expression.Constant(null), partialBlockTemplate ?? Expression.Constant(null, typeof(Action <TextWriter, object>))); } var partialInvocation = Expression.Call( #if netstandard new Action <string, BindingContext, HandlebarsConfiguration>(InvokePartialWithFallback).GetMethodInfo(), #else new Action <string, BindingContext, HandlebarsConfiguration>(InvokePartialWithFallback).Method, #endif Expression.Convert(pex.PartialName, typeof(string)), bindingContext, Expression.Constant(CompilationContext.Configuration)); return(partialInvocation); }
protected virtual Expression VisitPartialExpression(PartialExpression pex) { Expression partialName = Visit(pex.PartialName); Expression argument = Visit(pex.Argument); // Don't visit Fallback - it will be compiled separately if (partialName != pex.PartialName || argument != pex.Argument) { return(HandlebarsExpression.Partial(partialName, argument, pex.Fallback)); } return(pex); }
protected override Expression VisitPartialExpression(PartialExpression pex) { Expression bindingContext = CompilationContext.BindingContext; if (pex.Argument != null) { bindingContext = Expression.Call( bindingContext, typeof(BindingContext).GetMethod("CreateChildContext"), pex.Argument); } return Expression.Call( new Action<string, BindingContext, HandlebarsConfiguration>(InvokePartial).Method, Expression.Constant(pex.PartialName), bindingContext, Expression.Constant(CompilationContext.Configuration)); }
protected override Expression VisitPartialExpression(PartialExpression pex) { Expression bindingContext = CompilationContext.BindingContext; if (pex.Argument != null) { bindingContext = Expression.Call( bindingContext, typeof(BindingContext).GetMethod("CreateChildContext"), pex.Argument); } return(Expression.Call( new Action <string, BindingContext, HandlebarsConfiguration>(InvokePartial).Method, Expression.Constant(pex.PartialName), bindingContext, Expression.Constant(CompilationContext.Configuration))); }
protected override Expression VisitPartialExpression(PartialExpression pex) { Expression bindingContext = CompilationContext.BindingContext; if (pex.Argument != null) { bindingContext = Expression.Call( bindingContext, typeof(BindingContext).GetMethod("CreateChildContext"), pex.Argument); } var fb = new FunctionBuilder(CompilationContext.Configuration); var partialBlockTemplate = fb.Compile(pex.Fallback != null ? new[] { pex.Fallback } : Enumerable.Empty <Expression>(), bindingContext); var partialInvocation = Expression.Call( #if netstandard new Func <string, BindingContext, HandlebarsConfiguration, Action <TextWriter, object>, bool>(InvokePartial).GetMethodInfo(), #else new Func <string, BindingContext, HandlebarsConfiguration, Action <TextWriter, object>, bool>(InvokePartial).Method, #endif Expression.Convert(pex.PartialName, typeof(string)), bindingContext, Expression.Constant(CompilationContext.Configuration), partialBlockTemplate); var fallback = pex.Fallback; if (fallback == null) { fallback = Expression.Call( #if netstandard new Action <string>(HandleFailedInvocation).GetMethodInfo(), #else new Action <string>(HandleFailedInvocation).Method, #endif Expression.Convert(pex.PartialName, typeof(string))); } return(Expression.IfThen( Expression.Not(partialInvocation), fallback)); }
protected override Expression VisitPartialExpression(PartialExpression pex) { Expression bindingContext = CompilationContext.BindingContext; if (pex.Argument != null) { bindingContext = Expression.Call( bindingContext, #if netstandard typeof(BindingContext).GetTypeInfo().GetMethod("CreateChildContext"), #else typeof(BindingContext).GetMethod("CreateChildContext"), #endif pex.Argument); } var partialInvocation = Expression.Call( #if netstandard new Func <string, BindingContext, HandlebarsConfiguration, bool>(InvokePartial).GetMethodInfo(), #else new Func <string, BindingContext, HandlebarsConfiguration, bool>(InvokePartial).Method, #endif Expression.Convert(pex.PartialName, typeof(string)), bindingContext, Expression.Constant(CompilationContext.Configuration)); var fallback = pex.Fallback; if (fallback == null) { fallback = Expression.Call( #if netstandard new Action <string>(HandleFailedInvocation).GetMethodInfo(), #else new Action <string>(HandleFailedInvocation).Method, #endif Expression.Convert(pex.PartialName, typeof(string))); } return(Expression.IfThen( Expression.Not(partialInvocation), fallback)); }
protected override Expression VisitPartialExpression(PartialExpression pex) { Expression bindingContext = CompilationContext.BindingContext; if (pex.Argument != null) { bindingContext = Expression.Call( bindingContext, #if netstandard typeof(BindingContext).GetTypeInfo().GetMethod("CreateChildContext"), #else typeof (BindingContext).GetMethod("CreateChildContext"), #endif pex.Argument); } var partialInvocation = Expression.Call( #if netstandard new Func<string, BindingContext, HandlebarsConfiguration, bool>(InvokePartial).GetMethodInfo(), #else new Func<string, BindingContext, HandlebarsConfiguration, bool>(InvokePartial).Method, #endif Expression.Convert(pex.PartialName, typeof(string)), bindingContext, Expression.Constant(CompilationContext.Configuration)); var fallback = pex.Fallback; if (fallback == null) { fallback = Expression.Call( #if netstandard new Action<string>(HandleFailedInvocation).GetMethodInfo(), #else new Action<string>(HandleFailedInvocation).Method, #endif Expression.Convert(pex.PartialName, typeof(string))); } return Expression.IfThen( Expression.Not(partialInvocation), fallback); }
protected override Expression VisitPartialExpression(PartialExpression pex) { var bindingContext = ExpressionShortcuts.Arg <BindingContext>(CompilationContext.BindingContext); var partialBlockTemplate = pex.Fallback != null ? FunctionBuilder.CompileCore(new[] { pex.Fallback }, CompilationContext.Configuration) : null; if (pex.Argument != null || partialBlockTemplate != null) { var value = ExpressionShortcuts.Arg <object>(FunctionBuilder.Reduce(pex.Argument, CompilationContext)); var partialTemplate = ExpressionShortcuts.Arg(partialBlockTemplate); bindingContext = bindingContext.Call(o => o.CreateChildContext(value, partialTemplate)); } var partialName = ExpressionShortcuts.Cast <string>(pex.PartialName); var configuration = ExpressionShortcuts.Arg(CompilationContext.Configuration); return(ExpressionShortcuts.Call(() => InvokePartialWithFallback(partialName, bindingContext, (ICompiledHandlebarsConfiguration)configuration) )); }
protected override Expression VisitPartialExpression(PartialExpression pex) { Expression bindingContext = CompilationContext.BindingContext; if (pex.Argument != null) { bindingContext = Expression.Call( bindingContext, #if netstandard typeof(BindingContext).GetTypeInfo().GetMethod("CreateChildContext"), #else typeof(BindingContext).GetMethod("CreateChildContext"), #endif pex.Argument); } return Expression.Call( #if netstandard new Action<string, BindingContext, HandlebarsConfiguration>(InvokePartial).GetMethodInfo(), #else new Action<string, BindingContext, HandlebarsConfiguration>(InvokePartial).Method, #endif Expression.Convert(pex.PartialName, typeof(string)), bindingContext, Expression.Constant(CompilationContext.Configuration)); }
protected virtual Expression VisitPartialExpression(PartialExpression pex) { return pex; }
protected virtual Expression VisitPartialExpression(PartialExpression pex) { return(pex); }
public PartialBlockAccumulatorContext(Expression startingNode) : base(startingNode) { _startingNode = ConvertToPartialExpression(UnwrapStatement(startingNode)); }