7
我有下面的接口,我試圖讓COM可見。當我嘗試生成類型庫時,它不喜歡我的實現類從泛型類派生的事實。是否可以使用.NET泛型類實現COM接口?
是否可以使用泛型類作爲COM實現類? (我知道我可以寫一個非一般的包裝和導出到COM,但是這增加了另一層,我寧可沒有。)
[ComVisible(true)]
public interface IMyClass
{
...
}
[ComVisible(true), ComDefaultInterface(typeof(IMyClass))]
[ClassInterface(ClassInterfaceType.None)]
public class MyClass : BaseClass<IMyClass>, IMyClass
{
...
}
錯誤消息:
Warning: Type library exporter encountered a type that derives from a generic class and is not marked as [ClassInterface(ClassInterfaceType.None)]. Class interfaces cannot be exposed for such types. Consider marking the type with [ClassInterface(ClassInterfaceType.None)] and exposing an explicit interface as the default interface to COM using the ComDefaultInterface attribute.