Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditorConfig: Enforce spaces after and before opening/closing brackets for C#

I would like to configure my EditorConfig (https://editorconfig.org/) configuration in a way that the C# code snippet var v = new Object(kind) {Id = num++}; is automatically reformatted to var v = new Object(kind) { Id = num++ }; by adding spaces after the opening and before the closing bracket. I went through the documentation and also checked the C# manual (https://learn.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017#example-editorconfig-file) but couldn't quite find a solution yet.

like image 455
Julian Avatar asked Nov 09 '18 19:11

Julian


1 Answers

Microsoft has implemented there own csharp and dotnet specific options for the .editorconfig.

Here are the up-to-date spacing options. I guess you want to do something like that:

// csharp_space_before_open_square_brackets = true
int [] numbers = new int [] { 1, 2, 3, 4, 5 };

// csharp_space_between_empty_square_brackets = true
int[ ] numbers = new int[ ] { 1, 2, 3, 4, 5 };

// csharp_space_between_square_brackets = true
int index = numbers[ 0 ];

Disclamer: For brackets, there are only square properties currently

like image 98
Schmebi Avatar answered Jan 03 '23 22:01

Schmebi