Calling GetType on a Type variable will always return the System.Type representation, which is equivalent to
typeof(System.Type). This also applies to passing a Type argument to IsInstanceOfType which always returns
false.
In both cases, the results are entirely predictable and should be avoided.
Calling GetType on System.Type is considered compliant to get an instance of System.RuntimeType, as
demonstrated in the following example:
typeof(Type).GetType(); // Can be used by convention to get an instance of 'System.RuntimeType'
Make sure the usage of GetType or IsInstanceOfType is invoked with the correct variable or argument type.
void ExamineSystemType(string str)
{
Type stringType = str.GetType();
Type runtimeType = stringType.GetType(); // Noncompliant
if (stringType.IsInstanceOfType(typeof(string))) // Noncompliant; will always return false
{ /* ... */ }
}
void ExamineSystemType(string str)
{
Type stringType = str.GetType();
if (stringType.IsInstanceOfType(str)) // Compliant
{ /* ... */ }
}