I need to format the class so that it can be easily read by humans. I have a syntax tree, the root of CompilationUnitSyntax and ClassDeclarationSyntax. I will format the spaces 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 did the class closing bracket slam shut in #endregion?
If I run NormalizeWhitespace again in the After text, #endregion will be moved back to its own line. Then an additional call to NormalizeWhitespace brings it back again. What's happening?
source share