Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

c# - Need of ClassInterfaceType.None?

  1. Didn't quite get the following from MSDN:

    ClassInterfaceType.None

    Indicates that no class interface is generated for the class. If no interfaces are implemented explicitly, the class can only provide late-bound access through the IDispatch interface. This is the recommended setting for ClassInterfaceAttribute. Using ClassInterfaceType.None is the only way to expose functionality through interfaces implemented explicitly by the class.

  2. Is [ComVisible(true)] a must for COM visibility?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

See this blog post for the expanation of the first problem. The point is that unless you specify ClassInterfaceType.None an extra interface is generated and this can cause problems with binary compatibility if you alter the order of methods, change their signatures or remove some of them. A much better alternative is to explicitly define an interface and inherit your class from it specifying ClassInterfaceType.None.

ComVisible(true) is not a must for COM visibility. By default all public methods of public classes and all public classes are COM visible, all other entities are not COM visible. If you need to alter this you use ComVisible attribute, usually to decrease the amount of COM visible classes since for every COM visible class registry entries and type library entries are generated and this causes unnecessary registry pollution and inflates the type library. IMO it's a good idea to explicitly mark all public entities with ComVisible.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...