[ClassInterface(ClassInterfaceType.None)]
Class Program()
{
}
When would we need to apply the ClassInterface
attribute to a class, as is done here?
ClassInterfaceAttribute
is used for declaring how visible your class is to COM callers, that is, if your class will play nice with something from the COM world trying to use your class. There are three options, contained in the ClassInterfaceType
enumeration, which you can specify as a parameter of the overload of the ClassInterfaceAttribute
. Here it is from MSDN, and below is an example of three class declarations, each with a different choice of InterfaceType:
ClassInterfaceAttribute
on MSDN
ClassInterfaceType
on MSDN
The following illustrates use of the 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
{
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With