Please treat anonymous functions differently for code formatting purposes
I want the code formatting options to be explicitly different for anonymous functions vs named. Here is the example:
// This line is too long so it wraps.
var customerRepository = new CustomerRepository(
vendorId,
databaseContext,
traceId);
// This line is too long so it wraps.
var specialCustomers = customers.Select(x =>
{
return new SpecialCustomer(x.Props, databaseContext);
});
Also note that the above brackets are _not_ indented one. This is often a preferred method for simple LINQ statements.
The setting in question is Code Editing > C# > Line Breaks and Wrapping > Prefer wrap after "(" in declaration.
This setting is preferred for named functions. But not preferred for anonymous functions.
This is mostly because "chaining" has it's own preferred style. Often instead of next line per chain, you often want it on the same line as well. Like when implementing a pipeline.
x.IncreaseAge(x =>
{
x.Age += 1;
return new NextStep(x);
}).DetermineNextBirthDate(x =>
{
});
But of course some people want the chaining evocation to go to the next line. That setting could be "Prefer wrap before . in anonymous call chain".
As a last note, this is what the current formatting ends up being, and I cannot change it without breaking the other formatting.
var items = oldList.Select(
x =>
{
var otherWork = x.DoStuff();
return new Item(otherWork);
})
.ToArray();
The identation style here makes no sense and is completely unclear. Compare it to:
var items = oldList.Select(x =>
{
var otherWork = x.DoStuff();
return new Item(otherWork);
})
.ToArray();
Please sign in to leave a comment.