I am struggling to format code in C# in Visual Studio if it is written for the Fluent API of Entity Framework.
Something like this:
_db.ProdSmartSorts
.Where(x => catIds.Contains((int)x.Product.CategoryId))
.OrderBy(x => x.ProdSmartId)
.Select(x => x.Product)
.Include(p => p.Pictures.Where(pic => pic.IsCover))
.Skip(prodCount * (pageNumber - 1))
.Take(prodCount)
.ToList();
What I want:
- align all function calls, so each of them has the same spacing from the left
- maybe just one function call per line
- maybe indent
.ThenInclude()
further
What I have:
- formatting code does not affect fluent code at all
- I did not find any setting for this
Is there a (hidden) setting for this? Are there any extensions which solve this?
I am struggling to format code in C# in Visual Studio if it is written for the Fluent API of Entity Framework.
Something like this:
_db.ProdSmartSorts
.Where(x => catIds.Contains((int)x.Product.CategoryId))
.OrderBy(x => x.ProdSmartId)
.Select(x => x.Product)
.Include(p => p.Pictures.Where(pic => pic.IsCover))
.Skip(prodCount * (pageNumber - 1))
.Take(prodCount)
.ToList();
What I want:
- align all function calls, so each of them has the same spacing from the left
- maybe just one function call per line
- maybe indent
.ThenInclude()
further
What I have:
- formatting code does not affect fluent code at all
- I did not find any setting for this
Is there a (hidden) setting for this? Are there any extensions which solve this?
Share Improve this question edited Feb 16 at 13:45 marc_s 755k184 gold badges1.4k silver badges1.5k bronze badges asked Feb 16 at 12:56 Mo3biusMo3bius 6621 gold badge8 silver badges19 bronze badges2 Answers
Reset to default -1The formatting options in Visual Studio can be found under Tools > Options > Text Editor > C# (or any other supported language)
, but afaik VS doesn't offer, what you want.
I use Jetbrains Resharper to add more formatting options to my ide. Unfourtunately, it is not free and has a noticable performance impact (at least when editing large files). Though it does support the requested "one dot per line" formatting ("wrap chained method calls"), all follow-up-rows are indented to the same level. Individual formatting of selected methods is not possible.
I tried the method you mentioned, and it does meet some of the requirements.
However, this method is not customizable and can only perform the functions mentioned in the documentation: Wrap call chains document
If you want better customization for the formatting you mentioned, the built-in features of VS may not provide much help.