export generics in MEF

前端 未结 1 923
清歌不尽
清歌不尽 2021-02-07 13:11

I want to export a generic class to a generic interface via MEF. My objects are:

public interface IService { }

[Export(typeof(IService))] // e         


        
相关标签:
1条回答
  • 2021-02-07 13:57

    Try

    [Export(typeof(IService<>))]
    

    To get a generic type definition from the typeof operator, you omit type arguments. For types with more than one type parameter, use commas to indicate the "arity" of the type. For example:

    typeof(List<>)              // not: typeof(List<T>)
    typeof(IDictionary<,>)      // not: typeof(IDictionary<K, V>)
    
    0 讨论(0)
提交回复
热议问题