CompositionContainer:如何从导出的值中获取源类

时间:2014-12-03 11:18:11

标签: c# .net dependency-injection inversion-of-control mef

如果我有以下出口

Class A 
    [Export(typeof(IFOOExport))]
    public   IFOOExport ExportedFunctions_FULL = new FunctionsExport
    {
        Sub = String.Empty;

    };

Class B
   [Export(typeof(IFOOExport))]
    public   IFOOExport ExportedFunctions_EMPTY = new FunctionsExport
    {
        Sub = String.Empty;

    };

然后我得到了清单:

 var exp_list=   CompositionContainer.GetExportedValues<IFOOExport>();

我应该在列表中有两个元素,我的问题是:

如何识别从ExportedFunctions_EMPTY导出哪一个来自ExportedFunctions_FULL?

1 个答案:

答案 0 :(得分:0)

您只需调用GetType()方法并检查返回的FullName对象的Type属性。

foreach (var exp in exp_list)
{
    Console.WriteLine(exp.GetType().FullName);
}