private static void Render(ConditionalAttributePiece source, CSharpRenderingContext context) { const string ValueWriterName = "__razor_attribute_value_writer"; var expressionValue = source.Value.Children.First() as RenderExpression; var linePragma = expressionValue != null?context.Writer.BuildLinePragma(source.DocumentLocation) : null; var prefixLocation = source.DocumentLocation.AbsoluteIndex; var valueLocation = source.DocumentLocation.AbsoluteIndex + source.Prefix.Length; var valueLength = source.DocumentLocation.ContentLength - source.Prefix.Length; var renderingConventions = context.GetRenderingConventions(); renderingConventions .StartWriteAttributeValueMethod() .WriteStringLiteral(source.Prefix) .WriteParameterSeparator() .Write(prefixLocation.ToString(CultureInfo.InvariantCulture)) .WriteParameterSeparator(); if (expressionValue != null) { Debug.Assert(source.Value.Children.Count == 1); RenderExpressionInline(expressionValue.Expression, context); } else { // Not an expression; need to buffer the result. context.Writer.WriteStartNewObject(context.CodeLiterals.TemplateTypeName); var redirectConventions = new CSharpRedirectRenderingConventions(ValueWriterName, context); using (context.UseRenderingConventions(redirectConventions)) using (context.Writer.BuildAsyncLambda(endLine: false, parameterNames: ValueWriterName)) { context.Render(source.Value.Children); } context.Writer.WriteEndMethodInvocation(false); } context.Writer .WriteParameterSeparator() .Write(valueLocation.ToString(CultureInfo.InvariantCulture)) .WriteParameterSeparator() .Write(valueLength.ToString(CultureInfo.InvariantCulture)) .WriteParameterSeparator() .WriteBooleanLiteral(false) .WriteEndMethodInvocation(); linePragma?.Dispose(); }
private void Render(Template source, CSharpRenderingContext context) { const string ItemParameterName = "item"; const string TemplateWriterName = "__razor_template_writer"; context.Writer .Write(ItemParameterName).Write(" => ") .WriteStartNewObject(context.CodeLiterals.TemplateTypeName); var redirectConventions = new CSharpRedirectRenderingConventions(TemplateWriterName, context); using (context.UseRenderingConventions(redirectConventions)) using (context.Writer.BuildAsyncLambda(endLine: false, parameterNames: TemplateWriterName)) { context.Render(source.Children); } context.Writer.WriteEndMethodInvocation(); }
private void Render(RenderSection source, CSharpRenderingContext context) { const string SectionWriterName = "__razor_section_writer"; context.Writer .WriteStartMethodInvocation(context.CodeLiterals.DefineSectionMethodName) .WriteStringLiteral(source.Name) .WriteParameterSeparator(); var redirectConventions = new CSharpRedirectRenderingConventions(SectionWriterName, context); using (context.UseRenderingConventions(redirectConventions)) using (context.Writer.BuildAsyncLambda(endLine: false, parameterNames: SectionWriterName)) { context.Render(source.Children); } context.Writer.WriteEndMethodInvocation(); }