Configure Fluent API Hierarchical Formatting
Problem
Fluent APIs conventionally rely on indentations to visually indicate the hierarchical nature of the calls, rider however, will completely flatten this hierarchical indention. In some cases almost entirely obfuscating the call relationship between members of the fluent API.
There does not appear to be any code style or configuration I could find for this. Detect style results in:
We can't recommend any changes to your code style settings. Looks like your code conforms to current settings or your code style is unsupported.
When format-on-save is present this breaks readability for fluent APIs, considerably. And there appears to be no way to stop it.
Example 1:
CampaignResponse? response = await _dbContext.Campaigns
.AsNoTracking()
.Include(x => x.Orders!)
.ThenInclude(x => x.Approval)
.ThenInclude(x => x!.ApprovedBy)
.Include(x => x.Orders!)
.ThenInclude(x => x.Creatives)
.Include(x => x.Orders!)
.ThenInclude(x => x.Messages!)
.ThenInclude(x => x.Sender)
.Include(x => x.Company)
.Include(x => x.CreatedBy)
Becomes flattened as:
CampaignResponse? response = await _dbContext.Campaigns
.AsNoTracking()
.Include(x => x.Orders!)
.ThenInclude(x => x.Approval)
.ThenInclude(x => x!.ApprovedBy)
.Include(x => x.Orders!)
.ThenInclude(x => x.Creatives)
.Include(x => x.Orders!)
.ThenInclude(x => x.Messages!)
.ThenInclude(x => x.Sender)
.Include(x => x.Company)
.Include(x => x.CreatedBy)
Example 2:
Or even more extreme:
Table table = new TableBuilder(headerFormat)
.AddColumn("Date", rowsFormat: new CellFormat(foregroundColor: Color.FromArgb(128, 129, 126)))
.AddColumn("Payee")
.RowsFormat()
.ForegroundColor(Color.FromArgb(100, 160, 179))
.AddColumn("Category")
.RowsFormat()
.ForegroundColor(Color.FromArgb(100, 160, 179))
.AddColumn("Value")
.RowFormatter<double>((x) => FormatMoney(x))
.RowsFormat()
.Alignment(Alignment.Right)
.Build();
Becomes:
Table table = new TableBuilder(headerFormat)
.AddColumn("Date", rowsFormat: new CellFormat(foregroundColor: Color.FromArgb(128, 129, 126)))
.AddColumn("Payee")
.RowsFormat()
.ForegroundColor(Color.FromArgb(100, 160, 179))
.AddColumn("Category")
.RowsFormat()
.ForegroundColor(Color.FromArgb(100, 160, 179))
.AddColumn("Value")
.RowFormatter<double>((x) => FormatMoney(x))
.RowsFormat()
.Alignment(Alignment.Right)
.Build();
Which is essentially just obsfucation at this point. And Fluent APIs only get more hierarchical from here.
Request/Solution:
Knowing how the hierarchy works may be difficult if not impossible as to the best of my knowledge C# does not provide any sort of 1st class citizen/special support for defining fluent APIs. Instead Rider could take the approach that many linters do, and NOT change the indentation formatting when it appears that a fluent-api is being utilized.
Please sign in to leave a comment.
Hi Douglas!
As you may already noticed, this is not possible in Rider and ReSharper. Feel free to upvote the issue to be notified about the progress.