dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15k stars 4.67k forks source link

[Analyzer Proposal]: warn when calling `GetType()` on a `System.Type` #108200

Open ericstj opened 2 hours ago

ericstj commented 2 hours ago

I've noticed a few times where folks make a mistake through refactoring or copy-paste (or AI hallucinations) where they call GetType() on a System.Type object. This doesn't cause any compile errors since System.Type is an object and therefore has a GetType() method - but it's more often the wrong thing to do than not.

I suggest we add an analyzer that warns folks when they do this.

dotnet-policy-service[bot] commented 1 hour ago

Tagging subscribers to this area: @dotnet/area-system-runtime See info in area-owners.md if you want to be subscribed.