dotnet/roslyn
Suggestion to use `obj is SomeConst` instead of safe cast or direct Equals(object) call
Offen
#45.232 geöffnet am 16.06.2020
Area-IDEConcept-Continuous Improvementhelp wanted
Repository-Metriken
- Stars
- (20.414 Sterne)
- PR-Merge-Metriken
- (Durchschn. Merge 6T 17h) (256 gemergte PRs in 30 T)
Beschreibung
obj as string == "x" and "x".Equals(obj) would be replaced with obj is "x".
This could apply to all constant types, so obj as bool? == SomeBoolConstant and SomeBoolConstant.Equals(obj) would be replaced with obj is SomeBoolConstant.
When CS0252 "Possible unintended reference comparison; to get a value comparison, cast the left hand side to type 'string'" is reported, this fix could offer to change obj == "x" to obj is "x".
Happy to implement.