公开 MEF 加载的“插件”版本

发布于 2024-08-05 17:57:05 字数 739 浏览 1 评论 0原文

对标题表示歉意,我被困住了

我正在将脚趾浸入 MEF 池塘中。到目前为止,一切都很好。我有一个主机应用程序和几个导出内容的“插件”程序集。主机应用定义了一个名为 DescriptionAttribute 的属性,它继承自 ExportAttribute 并具有一个简单的 Name 属性。我的测试表单有一个 IEnumerable(Of Lazy(Of IDoStuff, IDescriptionAttribute))。 MEF 很好地填充了这个值,我可以旋转该集合,Name 属性已填充,生命是黄金。 稍后我会将其拆分为单独的程序集,目前这只是一个概念证明

现在的问题是:有什么方法可以通过 DescriptionAttribute 公开实现 IDoStuff 的程序集版本,DescriptionAttribute 穿着“插件”类> 我有什么属性?到目前为止,我将其传递给属性的构造函数的所有尝试都失败了,工作室不断告诉我需要一个常量表达式(可以理解)。我可以通过 IDoStuff 接口公开它,但将其作为 DescriptionAttribute 属性的一部分会更好,这样“感觉”更好。我也可以对它进行硬编码,但这是我在发布新版本的“插件”时忘记更新的另一个地方:-)

apologies for the title, I got stuck for words

I'm dipping my toes in the MEF pond. So far, so good. I've got a host app and a couple of "plugin" assemblies that export things. The host app defines an attribute called DescriptionAttribute which inherits from ExportAttribute and has a simple Name property. My test form has an <ImportMany> IEnumerable(Of Lazy(Of IDoStuff, IDescriptionAttribute)). This gets nicely filled by MEF, I can spin through the collection, the Name property is filled in, life is golden. I'll split things out into separate assemblies later on, at the moment it's just a proof of concept.

Now, the question is: Is there any way I can expose the assembly version of the IDoStuff implementing, DescriptionAttribute wearing "plugin" classes through the DescriptionAttribute attribute that I have? All my attempts so far at passing it to the constructor of the attribute have failed, studio keeps telling me that a constant expression is required (understandably). I can expose it through the IDoStuff interface, but it'd be much nicer to have it as part of the DescriptionAttribute attribute instead, that "feels" better. I can also hardcode it, but it's another spot that I'd forget to update when releasing a new version of a "plugin" :-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

破晓 2024-08-12 17:57:05

那么您有一堆实现 IDoStuff 的类实例(由 MEF 导入),并且您想知道每个实例的程序集版本吗?

你能做到吗? GetType() 将返回底层类的类型,对吗?不是 typeof(IDoStuff)?

// IDoStuff myStuffDoer
var version = myStuffDoer.GetType().Assembly.GetName().Version;

So you have a bunch of instances of classes that implement IDoStuff, imported by MEF, and you want to know the assembly version for each of them?

Can you do this? GetType() will return the type of the underlying class, right? Not typeof(IDoStuff)?

// IDoStuff myStuffDoer
var version = myStuffDoer.GetType().Assembly.GetName().Version;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文