问题描述
没有完全得到以下 来自 MSDN:
ClassInterfaceType.None
表示没有类接口为类生成.如果不接口是显式实现的,该类只能提供后期绑定通过 IDispatch 访问界面.这是推荐的ClassInterfaceAttribute 的设置.使用 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.
[ComVisible(true)] 是 COM 可见性的必要条件吗?
Is [ComVisible(true)] a must for COM visibility?
推荐答案
参见 这篇博文 用于扩展第一个问题.关键是,除非您指定 ClassInterfaceType.None,否则会生成一个额外的接口,如果您更改方法的顺序、更改它们的签名或删除其中一些,这可能会导致二进制兼容性问题.一个更好的选择是显式定义一个接口并从它继承你的类,指定 ClassInterfaceType.None.
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) 对于 COM 可见性不是必须的.默认情况下,公共类的所有公共方法和所有公共类都是 COM 可见的,所有其他实体都是 COM 不可见的.如果你需要改变这个,你可以使用 ComVisible 属性,通常是为了减少 COM 可见类的数量,因为每个 COM 可见类的注册表条目和类型库条目都会生成,这会导致不必要的注册表污染并膨胀类型库.IMO 最好用 ComVisible 明确标记所有公共实体.
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.
这篇关于需要 ClassInterfaceType.None 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)