Analyzer for the nameof expression instead of using the typeof(SomeType).Name to get the name of the current type.
Before:
```c#
var name = typeof(SomeType).Name;
After:
```c#
var name = nameof(SomeType);
Note: we currently have an analyzer doing nameof analysis in place of a string.
馃摑 Note that in the above example, nameof(T) will return "T" (a compile-time constant string that does not vary based on the actual type T).
YEah, i'm a bit confuse here. The above would change semantics and would not be desirable.
I think its a reasonable refactoring to offer. Before nameof this was a common thing folks would do. I would assume, unless this is a reflection scenario, this being a compile-time constant is fine
I think its a reasonable refactoring to offer.
But it literally changes the runtime behavior. The latter form always returns "T". The former form returns the name of the actual type this method is constructed with. i.e. GetName<int>(default) returns "Int32", but would now return "T"
馃挱 We could offer this refactoring for cases where the name _wouldn't_ change.
Yeah, sorry I was thinking we should _only_ offer this in a case like this where it will produce the same result:
var name = typeof(SomeType).Name;
var name = nameof(SomeType);
We obviously cannot offer this for generics. @mikadumont can you update the original issue to not use a generic?
Yes, went ahead and updated the issue.
Most helpful comment
馃挱 We could offer this refactoring for cases where the name _wouldn't_ change.