What does the C# CoClass attribute do?

后端 未结 1 534
孤独总比滥情好
孤独总比滥情好 2020-12-14 06:06

I found code something like the following in a 3rd party library we\'re using.

[CoClass(typeof(BlahClass))]
public interface Blah : IBlah
{
}
相关标签:
1条回答
  • 2020-12-14 06:41

    It declares that the interface Blah is intended to be implemented by a specific class. It means that you can conveniently say new Blah and the runtime will know what object to create - something that is not normally possible with an interface.

    If you look at the generated declaration for BlahClass, it will presumably have a Guid associated with it which can be used to create an instance of a COM object.

    0 讨论(0)
提交回复
热议问题