新的 .NET4.5 API 在 IntrospectionExtensions 类中具有以下逻辑
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();
}
为什么这个方法有无法访问的代码?这是错误还是有意为之?
最佳答案
混淆是由 Type
类上定义的 ==
运算符引起的。
如果您查看 IL,您会看到调用的是运算符而不是 ReferenceEquals
。
L_0002: call bool System.Type::op_Equality(class System.Type, class System.Type)
所以代码实际上是可以访问的:)
关于c# - 为什么 System.Reflection.IntrospectionExtensions.GetTypeInfo 有无法访问的代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14089706/