Why is this an issue?
If you call GetType()
on a Type
variable, the return value will always be typeof(System.Type)
. So there’s no
real point in making that call. The same applies to passing a type argument to IsInstanceOfType
. In both cases the results are entirely
predictable.
Noncompliant code example
var intType = typeof(int);
var runtimeType = intType.GetType(); // Noncompliant, always typeof(System.RuntimeType)
var s = "abc";
if (s.GetType().IsInstanceOfType(typeof(string))) // Noncompliant; false
{ /* ... */ }
Compliant solution
var s = "abc";
if (s.GetType().IsInstanceOfType("string"))
{ /* ... */ }
Exceptions
typeof(Type).GetType(); // Can be used by convention to get an instance of ‘System.RuntimeType’