简体   繁体   中英

CompositionContainer: How can I get the source class from an exported value

if I have following exports

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;

    };

then I get the list:

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

I should have two elements in the list, and my question is:

How can I identify which one is export from ExportedFunctions_EMPTY which one come from ExportedFunctions_FULL?

You can simply call the GetType() method and inspect the FullName property of the returned Type object.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM