ExportFactory <t,tmetadata - =“”get =“”type =“”of =“”class =“”which =“”derives =“”from =“”t =“”

时间:2018-03-25 15:49:31

标签: c# reflection export

1 个答案:

答案 0 :(得分:1)

Because you are storing all the factories in a IEnumerable<ExportFactory<ITask,IMetaData>>, there is no way you can determine the actual type of ITask without executing the factory's CreateExport() method (which I assume you don't want to do yet).

That being said: You are using the ExportFactory<,> with MetaData, so you could expand your IMetaData to contain a TaskType property. That would result in:

IEnumerable<ExportFactory<ITask,IMetaData>> myTasks = ...;
foreach (var task in myTasks)
{
    Type taskType = task.Metadata.TaskType;
}