c# – 为什么System.Reflection.IntrospectionExtensions.GetTypeInfo有无法访问的代码?

c# – 为什么System.Reflection.IntrospectionExtensions.GetTypeInfo有无法访问的代码?,第1张

概述新的.NET4.5 API在IntrospectionExtensions类中具有以下逻辑 public static TypeInfo GetTypeInfo(this Type type){ if (type == (Type) null) throw new ArgumentNullException("type"); IReflectableType reflectabl 新的.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有无法访问的代码?全部内容,希望文章能够帮你解决c# – 为什么System.Reflection.IntrospectionExtensions.GetTypeInfo有无法访问的代码?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/langs/1245283.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-07
下一篇2022-06-07

发表评论

登录后才能评论

评论列表(0条)

    保存