Getting an export from an MEF container given only a Type instance

后端 未结 2 363
灰色年华
灰色年华 2020-12-30 07:25

I have a scenario where I have to get an export from my CompositionContainer instance but I only have a Type to work with; I don\'t know the type at compile time, hence I ca

相关标签:
2条回答
  • 2020-12-30 07:47

    Found the answer:

    var export = _container.GetExports(someType, null, null).FirstOrDefault();
    
    0 讨论(0)
  • 2020-12-30 08:01

    Create the call dynamically using Type.MakeGeneric.....

    http://geekswithblogs.net/marcel/archive/2007/03/24/109722.aspx

    0 讨论(0)
提交回复
热议问题