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(ConditionalAttributePiece source, CSharpRenderingContext context) { context.Render(source.Value.Children); }