MEF Filter ImportMany

时间:2015-05-07 09:38:54

标签: c# mef

假设我有以下3个类:

<input type="text" value="This text is auto capitalized" />

例如,如果可以这样做:

[Export("Settings",typeof(ISettingsItem)]
[PartCreationPolicy(CreationPolicy.Shared)]
public class Settings1Vm {}

[Export("Settings",typeof(ISettingsItem)]
[PartCreationPolicy(CreationPolicy.Shared)]
public class Settings2Vm {}

[Export("Settings",typeof(ISettingsItem)]
[PartCreationPolicy(CreationPolicy.Shared)]
public class Settings3Vm {}

但是这种导入只能导出Settings2VM类吗?

问候

1 个答案:

答案 0 :(得分:0)

似乎解决方案是:

[Export("Settings",typeof(ISettingsItem)]
[Export("Settings2Vm ",typeof(ISettingsItem)]
[PartCreationPolicy(CreationPolicy.Shared)]
public class Settings2Vm {}

[Import("Settings2Vm ", typeof(ISettingsItemVM))]
private Settings2Vm SettingEntry{ get; set; }

这样我将始终拥有相同的实例。