I need to format a class to ensure it's easily human readable. I have the syntax tree, the root CompilationUnitSyntax and the ClassDeclarationSyntax. I format the whitespace as follows.
root = root.ReplaceNode(classSyntax, classSyntax.NormalizeWhitespace(elasticTrivia: true));
syntaxTree = syntaxTree.WithRootAndOptions(root, syntaxTree.Options);
Before:
#region MyRegion
public class MyClass
{
// Info about MyClass
}
#endregion
After:
#region MyRegion
public class MyClass
{
// Info about MyClass
}#endregion
Why is the class's closing brace slammed into the #endregion?
If I run NormalizeWhitespace once more on the 'After' text, #endregion is moved back down onto its own line. Then a further call to NormalizeWhitespace moves it back up again. What is going on?
This sounds like a bug, possibly related to https://github.com/dotnet/roslyn/issues/1066.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With