Skip to content

Prefer using generic method overload instead of string

Vladimir edited this page Dec 18, 2018 · 2 revisions

Using the string for the component type variants in methods like GetComponent results in additional overhead that should not be incurred when possible. Also using string literal as type name is unsafe, because target class can be renamed, removed or typo could occurred inside string literal.

Rider provides auto-completion for string literal, also supports refactoring and navigation from string literal.

This inspection will highlight using string literal inside GetComponent, AddComponent and CreateInstance and provide quick fix (Alt+Enter) to convert string literal to type parameter.

History:

  • This inspection was first added in Rider/ReSharper 2018.3
Clone this wiki locally