You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This rule flags places where a collection is built in a fluent manner, that is, where methods like Add(), AddRange(), AsSpan(), ToList(), and ToArray() are chained.
But the rule is triggered when there is no fluent/chaining of methods.
Describe suggestions on how to achieve the rule
The documentation/description should probably be changed to indicate that it is just triggered by using any methods that can be chained. (But why are these methods even there or can be used fluently if we aren't supposed to use them that way?)
Or, ideally, I think that it would help if it was just made to be configurable with an option to trigger like it does now or to only trigger for actual fluent code with chained methods. Right now if it sees something like someList.ToArray() it will suggest something like [.. someList] even though that isn't really fluent or any chaining. Sure, that is fewer characters to type, if you don't count Intellisense helping you. But it isn't nearly as readable. Now, if it does encounter some chain of multiple methods then it might make more sense to refactor that to use collection expressions.
Analyzer
Diagnostic ID: IDE0305
Describe the improvement
The documentation for this rule says :
But the rule is triggered when there is no fluent/chaining of methods.
Describe suggestions on how to achieve the rule
The documentation/description should probably be changed to indicate that it is just triggered by using any methods that can be chained. (But why are these methods even there or can be used fluently if we aren't supposed to use them that way?)
Or, ideally, I think that it would help if it was just made to be configurable with an option to trigger like it does now or to only trigger for actual fluent code with chained methods. Right now if it sees something like
someList.ToArray()
it will suggest something like[.. someList]
even though that isn't really fluent or any chaining. Sure, that is fewer characters to type, if you don't count Intellisense helping you. But it isn't nearly as readable. Now, if it does encounter some chain of multiple methods then it might make more sense to refactor that to use collection expressions.So it would be nice to have something like:
dotnet_style_prefer_collection_expression = when_multiple_methods
Honestly, ideally it might just take an integer and if the chain is that long or longer it triggers. So something like one/both of:
The text was updated successfully, but these errors were encountered: