title: How does one get Roslyn to format XML Documentation Comments properly?
body: <p>I'm using a <code>SyntaxRewriter</code> to convert classes from an old library to a new library, which basically entails finding classes which a given attribute and then rewriting properties which follow a certain convention. The general skeleton of the rewriter is as follows:</p>
  
  <pre><code>class PropertyConverter : SyntaxRewriter
  {
      public override SyntaxNode VisitPropertyDeclaration(PropertyDeclarationSyntax node)
      {
          if (!MeetsUpdateCriteria(node)) return base.VisitPropertyDeclaration(node);
  
          // these implementations simply return a string
          var name = FigureOutName(node.Identifier);
          var propertyType = FigureOutType(node.Type);
  
          var getter = Syntax.ParseExpression("this.GetValue&lt;" + propertyType + "&gt;(" + name + ")");
          var setter = Syntax.ParseExpression("this.SetValue(" + name + ", value)");
  
          return node.WithType(propertyType)
                     .WithAccessorList(
              Syntax.AccessorList(Syntax.List(
                  Syntax.AccessorDeclaration(
                      SyntaxKind.GetAccessorDeclaration,
                      Syntax.Block(Syntax.ReturnStatement(getter))),
                  Syntax.AccessorDeclaration(
                      SyntaxKind.SetAccessorDeclaration,
                      Syntax.Block(Syntax.ExpressionStatement(setter)))))));
      }
  }
  </code></pre>
  
  <p>The result of this converter is a class with updated properties, and it is outputted in the following code:</p>
  
  <pre><code>// IDocument csfile &lt;- from a project in a Workspace
  var tree = csfile.GetSyntaxTree();
  var root = new PropertyConverter().Visit((SyntaxNode)tree.GetRoot())
                                    .NormalizeWhitespace(); // problem!
  
  File.WriteAllText(Path.GetFileName(csfile.FilePath), root.ToFullString());    
  </code></pre>
  
  <p>At this point the code is all syntactically correct and the outputted syntax tree is correct. My only complaint is the whitespace around the XML Documentation Comments are not in any way correct:</p>
  
  <pre><code>/// &lt;summary&gt;
          /// Gets or sets the thickness (TH).
          /// &lt;/summary&gt;
  public float Thickness
  {
      get
      {
          return this.GetValue&lt;float&gt;(TH);
      }
  
      set
      {
          this.SetValue(TH, value);
      }
  }
  </code></pre>
  
  <p>Notice all of the extraneous indentation. Furthermore, the spacing is corrupted in other ways as well, especially with method documentation:</p>
  
  <pre><code>/// &lt;summary&gt;
          /// Initializes a new instance of the &lt;see cref = "X"/&gt; class.
          /// &lt;/summary&gt;
          /// &lt;param name = "innerRadius"&gt;Inner radius of the X.&lt;/param&gt;
          /// &lt;param name = "thickness"&gt;Thickness of the X.&lt;/param&gt;
  </code></pre>
  
  <p>I've verified that the input tree does not suffer from these indentation problems and I've also verified that the tree does not suffer from these indentation problems prior to calling <code>NormalizeWhitespace</code>. I've also tried <code>elasticTrivia: true</code>, without any luck as well.</p>
  
  <p>So how do you get Roslyn to normalize the whitespace in a consistent manner?</p>