[英]export generics in MEF
我想通過MEF將泛型類導出到通用接口。 我的目標是:
public interface IService<T> { }
[Export(typeof(IService<T>))] // error!!!!!!
public class Service<T> { }
public class Client<T> {
[Import]
private IService<T> _service;
}
但是當我嘗試導出IService<T>
,我收到此錯誤:
屬性參數不能使用類型參數
有人可以指導我這樣做嗎?
嘗試
[Export(typeof(IService<>))]
要從typeof
運算符獲取泛型類型定義,請省略類型參數。 對於具有多個類型參數的類型,請使用逗號表示該類型的“arity”。 例如:
typeof(List<>) // not: typeof(List<T>)
typeof(IDictionary<,>) // not: typeof(IDictionary<K, V>)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.