Exemplo n.º 1
0
        public void RenderDesignTimeExpressionBlockChunk(ExpressionBlockChunk chunk)
        {
            var firstChild = (ExpressionChunk)chunk.Children.FirstOrDefault();

            if (firstChild != null)
            {
                var currentIndent        = Writer.CurrentIndent;
                var designTimeAssignment = "__o = ";
                Writer.ResetIndent();

                var documentLocation = firstChild.Association.Start;
                // This is only here to enable accurate formatting by the C# editor.
                Writer.WriteLineNumberDirective(documentLocation, Context.SourceFile);

                // We build the padding with an offset of the design time assignment statement.
                Writer.Write(_paddingBuilder.BuildExpressionPadding((Span)firstChild.Association, designTimeAssignment.Length))
                .Write(designTimeAssignment);

                // We map the first line of code but do not write the line pragmas associated with it.
                CreateRawCodeMapping(firstChild.Code, documentLocation);

                // Render all but the first child.
                // The reason why we render the other children differently is because when formatting the C# code
                // the formatter expects the start line to have the assignment statement on it.
                Accept(chunk.Children.Skip(1).ToList());

                Writer.WriteLine(";")
                .WriteLine()
                .WriteLineDefaultDirective()
                .WriteLineHiddenDirective()
                .SetIndent(currentIndent);
            }
        }