2008-09-25 37 views
7

Tôi có giao diện sau đây mà tôi đang cố gắng hiển thị COM. Khi tôi cố gắng để tạo ra các loại thư viện nó không giống như thực tế là lớp thực hiện của tôi xuất phát từ một lớp chung chung.Có thể triển khai giao diện COM với lớp Generics .NET không?

Có thể sử dụng lớp chung làm lớp triển khai COM không? (Tôi biết tôi có thể viết một wrapper không chung chung và xuất khẩu đó để COM, nhưng điều này cho biết thêm một lớp mà tôi thà làm mà không có.) Nhắn

[ComVisible(true)] 
public interface IMyClass 
{ 
    ... 
} 

[ComVisible(true), ComDefaultInterface(typeof(IMyClass))] 
[ClassInterface(ClassInterfaceType.None)] 
public class MyClass : BaseClass<IMyClass>, IMyClass 
{ 
    ... 
} 

Lỗi:

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.

Trả lời

5

Generic loại và loại xuất phát từ loại chung không thể xuất được. Đặt ComVisible(false) trên loại MyClass của bạn. Bạn sẽ cần phải tạo ra một triển khai lớp không chung chung hoặc chỉ sử dụng giao diện.

Các vấn đề liên quan