-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
dotnet/roslyn-analyzers
#4687Closed
Copy link
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Collectionscode-analyzerMarks an issue that suggests a Roslyn analyzerMarks an issue that suggests a Roslyn analyzercode-fixerMarks an issue that suggests a Roslyn code fixerMarks an issue that suggests a Roslyn code fixer
Milestone
Description
This is a proposal for a new analyzer/codefix for:
// given
Dictionary<int, string> dic = ...;
dic.Keys.Contains(1);
dic.Values.Contains("");
// Could instead be
dic.ContainsKey(1);
dic.ContainsValue("");
I found this code in some design-time build targets today.
EDIT I'd previously incorrectly stated that the former form was O(N), but System.Linq.Enumerable.Contains
does type test for ICollection<>
and delegate to ICollection<>.Contains
, which is also O(1). There is some overhead associated with that however, which could be avoided.
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Collectionscode-analyzerMarks an issue that suggests a Roslyn analyzerMarks an issue that suggests a Roslyn analyzercode-fixerMarks an issue that suggests a Roslyn code fixerMarks an issue that suggests a Roslyn code fixer