识别可组合零件的装配
假设我在 AssemblyA 中定义导出:
[Export(typeof(Foo))]
public class Foo
{
...
}
有没有办法确定 Foo 的导出是来自 CompositionContainer 中的 AssemblyA?
我想要做的是,对于任何提供 MEF 导出的给定程序集,它还必须包含特定接口的一个 MEF 导出。我希望能够标记任何不满足此规则的程序集。
Suppose I define an export in AssemblyA:
[Export(typeof(Foo))]
public class Foo
{
...
}
Is there a way to determine the export of Foo is from AssemblyA in the CompositionContainer?
What I am trying to do, is for any given assembly that provides MEF exports, it must also include one MEF export of a specific interface. And I want to be able to flag any assemblies that do not satisfy this rule.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无法在 CompositionContainer 中执行此操作。我建议为每个程序集创建一个 AssemblyCatalog,并检查其任何零件是否具有与您想要的接口匹配的 ExportDefinition。
There's no way to do this from in a CompositionContainer. I would suggest creating an AssemblyCatalog for each assembly and checking whether any of its Parts have an ExportDefinition matching the interface you want.
您可以识别 ComposablePartDefinition< 的类型和程序集/a> 使用静态 ReflectionModelServices.GetPartType 方法。以下示例创建一个不同程序集的列表,其中包含容器目录中包含的类型:
You can identify the type and assembly of a ComposablePartDefinition using the static ReflectionModelServices.GetPartType method. The following example creates a list of distinct assemblies that contain types included in the container's catalog: