New .NET4.5 API has the following logic in IntrospectionExtensions class
public static TypeInfo GetTypeInfo(this Type type)
{
  if (type == (Type) null)
    throw new ArgumentNullException("type");
  IReflectableType reflectableType = (IReflectableType) type;
  if (reflectableType == null) 
    return (TypeInfo) null; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< HERE!
  else
    return reflectableType.GetTypeInfo();
}
Why this method has unreachable code? Is this a bug or done intentionally?
The confusion is caused by the == operator defined on the Type class.
If you look at the IL, you will see the operator is called instead of ReferenceEquals.
L_0002: call bool System.Type::op_Equality(class System.Type, class System.Type)
So the code is in fact reachable :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With