【问题标题】:Getting a Type Assembly in Windows 8在 Windows 8 中获取类型程序集
【发布时间】:2011-09-30 14:53:25
【问题描述】:

我正在尝试在 Windows 8 中使用 MEF。

为了为容器构建我的AssemblyCatalog,我需要对程序集的引用。在过去,我会这样做:

var catalog = new AssemblyCatalog(typeof(App).Assembly);

神秘地,Assembly 属性不再存在于 Type 对象上。有人知道一个好的工作吗?有没有其他方法可以获取组件?我可以使用Assembly.Load 加载它,但我需要程序集的名称。我也无法从类型中得到它。

是否使用DirectoryCatalog 可能的替代方法?我不喜欢这个主意,但我会做我需要做的。

【问题讨论】:

  • @harold:感谢您的澄清。

标签: c# mef windows-8 windows-runtime


【解决方案1】:
using System.Reflection;

请改用type.GetTypeInfo().Assembly

【讨论】:

  • Intellisense 没有在 typeof(App) 上获取 GetTypeInfo()。不知道现在是什么交易。
  • 文档中的引用将其清除:“您可以通过调用 System.Reflection.IntrospectionExtensions.GetTypeInfo(System.Type) 方法来检索 TypeInfo 对象,该方法是 Type 的扩展方法。”跨度>
  • 添加using System.Reflection; 后,我就可以引用扩展函数了。
  • 其实你在我面前找到了答案:)
【解决方案2】:

在浏览了大量有关构建 Metro 风格应用程序的文档后找到了答案。

http://msdn.microsoft.com/en-us/library/windows/apps/br230302%28v=VS.85%29.aspx#reflection

Type 类的反射方面已移至名为 System.Reflection.TypeInfo 的新对象。你可以通过调用type.GetTypeInfo()获取这个类的一个实例。

所以要获得大会:typeof(App).GetTypeInfo().Assembly

需要using System.Reflection;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多