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
{{ message }}
Repository navigation
Do not use OfType<T>() with impossible types #33770
api-approvedAPI was approved in API review, it can be implementedarea-System.Linqcode-analyzerMarks an issue that suggests a Roslyn analyzerin-prThere is an active PR which will close this issue when it is merged
Warn if use of OfType<T>() would provably result in an empty sequence, because we can see that the input type in the sequence will never be the specified type.
Possibly at the same time, though via a different diagnostic ID: calling OfType<T>() on an IEnumerable<T> where the T is identical or assignable is redundant.
Enumerable.Range(1,100).OfType<int>();// @jnyrup points out that this is actually a non-null check,// so isn't completely safe to remove// myString.Split(",").OfType<object>();
Reacted by Viacheslav Ivanov, strangeman375 and Julian Verdurmen
api-approvedAPI was approved in API review, it can be implementedarea-System.Linqcode-analyzerMarks an issue that suggests a Roslyn analyzerin-prThere is an active PR which will close this issue when it is merged
Activity
jeffhandley commentedon Mar 21, 2020
Estimates:
drewnoakes commentedon Jun 4, 2020
Possibly at the same time, though via a different diagnostic ID: calling
OfType<T>()on anIEnumerable<T>where theTis identical or assignable is redundant.fowl2 commentedon Jun 4, 2020
I did a little prototype for fun over at dotnet/roslyn-analyzers#3608
jnyrup commentedon Jun 5, 2020
@drewnoakes Note that for reference types this can be used as a less clear way of writing
Where(e => e != null).bartonjs commentedon Nov 10, 2020
Video
Approved as proposed
Category: Reliability
Suggested severity: Warning