Reputation: 365
Consider this code...
Create(x,y,z,
null, null, null,
new Class1[ ] {
new Class1(a,b,c),
new Class1(a,b,c)
},
new Class2[] {
new Class2(d,e,f )
},
true);
Notice the lack of spacing after the parameter commas, and the extra spacing in the Class1 array definition and Class2 call.
If I format my document -- Ctrl+E, D or Ctrl+K, D -- the code is formatted to this...
Create(x, y, z,
null, null, null,
new Class1[] {
new Class1(a,b,c),
new Class1(a,b,c)
},
new Class2[] {
new Class2(d,e,f )
},
true);
Notice that the parameter commas in the "outer" code have been properly formatted with spaces (according to my preferences), and the extra spaces have been removed from the Class1 array definition (again, my preferences). However, the parameter commas in the "inner" code HAVE NOT been correctly formatted and the extra spacing remains in the Class2 call.
There is absolutely nothing wrong with the code -- it compiles and runs without errors.
This happens every time I create nested, complex calls using braces. I suppose I could just make my code longer and more complex by breaking it all apart and using temporary variables but that seems like overkill.
Why can't Visual Studio 2010 C# Express correctly format such nested code? Has anyone else experienced this? I can provide my Formatting preferences if necessary. Thanks in advance! :)
Upvotes: 3
Views: 810
Reputation: 2597
@tvwxyz: I could reproduce this issue with Ctrl+K, D.
But, interestingly if I enable "Automatically format completed block on }" it works fine (gets intended as expected) when I close the function.
Tools -> Options -> Text Editor-> C#-> Formatting -> General -> Automatically format completed block on }
Upvotes: 1