2012-09-16 126 views

回答

3

ClassInterfaceAttribute用於聲明你的類對COM調用者有多可見,也就是說,如果你的類將與來自COM世界嘗試使用你的類的東西玩得很好。枚舉ClassInterfaceType中包含三個選項,您可以將其指定爲ClassInterfaceAttribute的過載參數。在這裏它是從MSDN,和下面是三個類聲明,每一個不同的選擇InterfaceType的示例:

ClassInterfaceAttribute on MSDN

ClassInterfaceType on MSDN

下面舉例說明使用ClassInterfaceAttribute的:

// This one will not be visible to COM clients. 
[ClassInterface(ClassInterfaceType.None)] 
public class MyClass1 
{ 

} 

// This one will provide an interface for COM clients, 
// but only when/if one is requested of it. 
[ClassInterface(ClassInterfaceType.AutoDispatch)] 
public class MyClass2 
{ 

} 

// This one will, immediately upon instantiation, 
// automatically include an interface for COM clients. 
[ClassInterface(ClassInterfaceType.AutoDual)] 
public class MyClass3 
{ 

} 
相關問題