c# – 为什么System.Reflection.IntrospectionExtensions.GetTyp
发布时间:2020-12-15 07:58:06 所属栏目:百科 来源:网络整理
导读:新的.NET4.5 API在IntrospectionExtensions类中具有以下逻辑 public static TypeInfo GetTypeInfo(this Type type){ if (type == (Type) null) throw new ArgumentNullException("type"); IReflectableType reflectableType = (IReflectableType) type; if (
新的.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) 所以代码实际上是可以达到的:) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |