0

I like to indent the code in my #region blocks for readability (personal preference). However the default behavior of the Text Editor is to inline code with its surrounding region, as follows:

#region

// code defaults to this position 

#endregion

I have not been able to find any extensions that will allow the following indentation behavior:

#region

    // code should indent to here by default

#endregion

Can roslyn code analysis be used to write an analyzer which enforced this formatting?

Aleksandr Albert
  • 1,777
  • 1
  • 19
  • 26

1 Answers1

0

Yeah you could definitely do that. If you put your above code into a C# file and look at the Syntax Visualizer (View -> Other Windows) you will see that the the #region is viewed as a RegionDirectiveTrivia instance with the comment being a SingleLineCommentTrivia. enter image description here

It looks like you would just need to create a longer WhitespaceTrivia before the SingleLineCommentTrivia

devlife
  • 15,275
  • 27
  • 77
  • 131