csharpier
csharpier copied to clipboard
Single collection as method parameter
As formatted by 0.27 in playground
Input:
var dummy = new DestructuringOptionsBuilder()
.WithDefaultDestructurers()
.WithDestructurers([
new FirstDestructurer(),
new SecondDestructurer(),
new ThirdDestructurer(),
new FourthDestructurer(),
]);
Output:
var dummy = new DestructuringOptionsBuilder()
.WithDefaultDestructurers()
.WithDestructurers(
[
new FirstDestructurer(),
new SecondDestructurer(),
new ThirdDestructurer(),
new FourthDestructurer(),
]
);
Expected behavior:
Input seems better to me when there's only a single parameter that is a collection.
Using two lines for single characters [
and ]
, and increasing indentation, doesn't seem beneficial in this situation.
I note that this is somewhat similar to the idea that for a single lambda parameter x => ...
, it's nicer to keep Method(x =>
rather than putting x =>
on a line of its own.
Prettier also formats this way
await Promise.all([
queryClient.invalidateQueries(getDoctorProfileInfoQueryKey()),
queryClient.invalidateQueries(getStudyListQueryKey()),
]);
When you type such parameters you more likely get code that looks as in the input sample. At least, In Rider it's so
Thoughts on applying this to attributes as well? They are constructors, so should probably work the same way.
[AllowedExtensions(
[
".txt",
".pdf",
".doc",
".jpeg",
".jpg",
".zip",
".7z",
".png",
".xlsx",
".xlx",
".docx",
".csv"
]
)]
async Task<FormResultDto> PatchResults(){}
[AllowedExtensions([
".txt",
".pdf",
".doc",
".jpeg",
".jpg",
".zip",
".7z",
".png",
".xlsx",
".xlx",
".docx",
".csv"
])]
async Task<FormResultDto> PatchResults(){}
@belav If there's a single argument (be mindful of named properties in attributes!) then I prefer the latter.