【问题标题】:Is there a difference between Assembly.ExportedTypes and Assembly.GetExportedTypes()Assembly.ExportedTypes 和 Assembly.GetExportedTypes() 之间有区别吗
【发布时间】:2013-08-11 19:28:46
【问题描述】:

.NET 程序集类包含一个方法 (GetExportedTypes()) 和一个属性 (ExportedTypes)。

这些文档似乎相同(“返回程序集中所有公共可见类型的集合”)。这些有什么区别吗?还是这与 Assembly 类的 API 的历史原因有关?

【问题讨论】:

  • 看起来一样,但似乎 ExportedTypes 属性是 .net 4.5 中的新属性
  • 它被记录在商店应用程序中可用,而 GetExportedTypes 不可用。我猜并没有那么顺利。

标签: c# .net clr .net-assembly


【解决方案1】:

ExportedTypes 实现之后使用 ILSpy 查看 .NET 源代码:

public virtual IEnumerable<Type> ExportedTypes
{
    get
    {
        return this.GetExportedTypes();
    }
}

但是,继承 Assembly 类的类可以以不同的方式实现该属性,因此您可能不应该依赖 GetExportedTypes()ExportedTypes 做完全相同的事情。

【讨论】:

    猜你喜欢
    • 2012-02-16
    • 2020-01-11
    • 2016-12-02
    • 2021-10-09
    • 2010-09-27
    • 2014-08-30
    • 2014-09-25
    • 2017-12-23
    • 2014-12-04
    相关资源
    最近更新 更多