【问题标题】:Are Attribute.GetCustomAttributes and MemberInfo.GetCustomAttributes interchangeable?Attribute.GetCustomAttributes 和 MemberInfo.GetCustomAttributes 可以互换吗?
【发布时间】:2019-11-14 17:54:25
【问题描述】:

如果我没记错的话,最初引入 Attribute.GetCustomAttributes 是因为 MemberInfo.GetCustomAttributes 有一个关于字段和事件的错误。

现在我正在尝试查找此问题的任何链接,以了解它们在现代 .NET Framework 中是否完全可互换(如果此错误已修复),但我不能。我可能完全错了,那么请解释一下正确的历史,为什么有两种方法可以做同样的事情?

【问题讨论】:

    标签: c# .net reflection attributes


    【解决方案1】:

    我错过了documentation中的这个评论部分,它解释了一切:

    备注

    此方法忽略属性的inherit 参数和 事件。在继承链中搜索属性的属性 和事件,使用适当的重载 Attribute.GetCustomAttributes 方法。

    我对字段的看法是错误的。此问题仅适用于属性和事件

    希望这个问题能提高这个问题的可搜索性。

    【讨论】:

      猜你喜欢
      • 2012-12-29
      • 2017-12-08
      • 2012-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-27
      • 2013-04-03
      相关资源
      最近更新 更多