C#
I recently upgraded to VS 2015, and 2015's C# formatting rules changed and don't support the formatting options I want, in so many ways. So I decided that since I have CodeRush and I use it all the time, that I'd switch to use its code formatter. I have it all working wonderfully, except for a couple of things that appear to be missing options. I've checked Resharper, and it has these options available.
Here are the ones that I would use all the time:
First, object initializers with indented braces, followed by indented property initializers. I can get everything except the braces to indent. This is what I want:
C#MyObject myObject = new MyObject
{
MyProperty1 = "Foo",
MyProperty2 = "Bar",
};
This is what I can get:
C#MyObject myObject = new MyObject
{
MyProperty1 = "Foo",
MyProperty2 = "Bar",
};
Next is method chaining, for LINQ. I want all of the chaining to be indented. But I can't figure out the option to make chains indent. What I want:
C#MyObject[] results = foo .Where(f => f.MyValue == GoodDeal) .Select(f => f.ToMyObject()) .ToArray();
What I can get:
C#MyObject[] results = foo .Where(f => f.MyValue == GoodDeal) .Select(f => f.ToMyObject()) .ToArray();
Finally, when I create anonymous method calls inside of other stuff, I want the braces to indent. So, what I want:
C#MyObject[] results = foo
.Where(f => f.MyValue == GoodDeal)
.Select(f =>
{
// Do something with multiple lines here
Bar bar = f.CalculateBar();
if (bar.IsValid)
return new MyObjectBar(bar);
return f.ToMyObject();
})
.ToArray();
vs. what I get:
C#MyObject[] results = foo
.Where(f => f.MyValue == GoodDeal)
.Select(f =>
{
// Do something with multiple lines here
Bar bar = f.CalculateBar();
if (bar.IsValid)
return new MyObjectBar(bar);
return f.ToMyObject();
})
.ToArray();
I was able to get all of these formatting rules set up within 5 minutes in Resharper on a co-worker's system.
Is there a way I can create custom formatters so that I don't have to wait for you guys to incorporate these formatters? I've noticed that lots of refactorings that didn't format properly when they were done DID format properly when I started using your formatters, so it would be great if I could just start using it. :) And the CodeRush formatter works better than the built-in one for me now.
Hi Jason,
Thank you for using our product and for such detailed feedback on the formatting functionality.
We've discussed your suggestions and think that both of them (indentation for braces and indentation for parts of query expressions) make a sense.
We'll work to implement your suggestion regarding the indentation for braces and their contents, and will inform you when it is ready.
We cannot, however, implement formatting of the query expressions fast. This functionality will require significant changes in the architecture of the product. So, I cannot promise you that we will do this in the nearest future. There is a chance, however, that we will change our plans.
Thank you for your assistance.