2
是否可以从导入的MEF函数中获取程序集信息?我需要知道包含该函数的组件版本和插件控件的名称。尝试了以下,但它只是返回System.ComponentModel.Composition版本。如何获取导入的MEF函数的汇编信息?
foreach (Lazy<Func<int>, IMetadata> func in PluginFuncs)
{
// get assembly information of the Plugin control for the imported function
string version = func.GetType().Assembly.GetName().Version.ToString();
Console.WriteLine(version);
}
另一种方法是在元数据中使用硬编码值,但我认为这是不可维护的。当版本改变时,很容易忘记更改这些值。
感谢您的建议,但现在它返回mscorlib的版本。还有什么想法? – 2010-09-30 16:02:22
@John_Sheares:哦,该死的 - 这很有道理 - Func是System.Func ... mmm ...让我想想 –
2010-09-30 16:10:54
@John_Sheares:我相信上面现在可以工作。通过分配给委托,可以通过Delegate.Method中返回的MethodInfo来获取定义方法的类型。 – 2010-09-30 16:16:43