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
With classes inherited from Dictionary, OfType generates a warning when filtering an enum with custom Dictionaries on a dictionary with the same types. See example below:
publicclassCustomDict:Dictionary<int,int>{publicstringExtraProp{get;set;}=string.Empty;}publicclassOfTypeWarning{publicIEnumerable<CustomDict>customDictEnum=[];publicvoidTestOfType(){varx= customDictEnum.OfType<Dictionary<int,int>>();<--- this generated CA2021 warning
}}
Expected behavior
No warnings
Actual behavior
CA2021 warning
The text was updated successfully, but these errors were encountered:
DavidH541
changed the title
CA2021 False positive filtering Dictionary<T, U> with OfType<T> where T is a class inheriting from said Dictionary<T, U>
CA2021 False positive filtering Dictionary<U, V> with OfType<T> where T is a class inheriting from said Dictionary<U, V>
Oct 28, 2024
DavidH541
changed the title
CA2021 False positive filtering Dictionary<U, V> with OfType<T> where T is a class inheriting from said Dictionary<U, V>
CA2021 False positive filtering enum of Dictionary<U, V> with OfType<T> where T is a class inheriting from said Dictionary<U, V>
Oct 28, 2024
DavidH541
changed the title
CA2021 False positive filtering enum of Dictionary<U, V> with OfType<T> where T is a class inheriting from said Dictionary<U, V>
CA2021 False positive filtering enum of custom type inheriting from Dictionary<U, V> with OfType<T> where T is Dictionary<U, V>
Oct 28, 2024
Analyzer
Diagnostic ID: CA2021:
Don't call Enumerable.Cast<T> or Enumerable.OfType<T> with incompatible types
Analyzer source
SDK: Built-in CA analyzers in .NET 9.0.100-rc.2.24474.11 SDK or later
Version: SDK 9.0.100-rc.2.24474.11
Describe the bug
With classes inherited from Dictionary, OfType generates a warning when filtering an enum with custom Dictionaries on a dictionary with the same types. See example below:
Expected behavior
No warnings
Actual behavior
CA2021 warning
The text was updated successfully, but these errors were encountered: