-
Notifications
You must be signed in to change notification settings - Fork 6k
Update option values for prefer collection expressions #45790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM, but I have a clarifying question for Cyrus.
|--------------------------|-------------------------------------------|---------------------------------------| | ||
| **Option name** | dotnet_style_prefer_collection_expression | | | ||
| **Option values** | `true` | `when_types_exactly_match` | Prefer to use collection expressions only when types match exactly, for example, `List<int> list = new List<int>() { 1, 2 };`. | | ||
| | `when_types_loosely_match`\* | Prefer to use collection expressions even when types match loosely, for example, `IEnumerable<int> list = new List<int>() { 1, 2 };`. The targeted type must match the type on the right-hand side or be one of the following types: <xref:System.Collections.Generic.IEnumerable%601>, <xref:System.Collections.Generic.ICollection%601>, <xref:System.Collections.Generic.IList%601>, <xref:System.Collections.Generic.IReadOnlyCollection%601>, <xref:System.Collections.Generic.IReadOnlyList%601>. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CyrusNajmabadi should take a look at these two lines. Currently, the collection expressions spec guarantees that IList<T>
products a List<T>
as the concrete type. That could mean that case should be in "when types exactly match", but I'm not sure the analyzer implemented it that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That could mean that case should be in "when types exactly match", but I'm not sure the analyzer implemented it that way.
The analyzer is implemented that way. When we see an ICollection<T>
or IList<T>
target, and we see the original type was List<T>
, we will offer the change even if hte setting is "when types exactly match" as the final emitted type will exactly match the original type the user specified.
Fixes dotnet/roslyn#72532.
cc @cremor - and thank you for alerting me to the bad info.
Internal previews
Create()
(IDE0303)