Why does System.Reflection.IntrospectionExtensions.GetTypeInfo have unreachable code?

New API .NET4.5 has the following logic in the 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 does this method have unreachable code? Is this a mistake or is it intentional?

+7
source share
1 answer

The confusion is caused by the == operator defined in the Type class.

If you look at IL, you will see that the statement is called instead of ReferenceEquals .

 L_0002: call bool System.Type::op_Equality(class System.Type, class System.Type) 

So the code is really available :)

+6
source

All Articles