需要ClassInterfaceType.None的? [英] Need of ClassInterfaceType.None?

查看:1177
本文介绍了需要ClassInterfaceType.None的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 没有完全得到下面的<一个href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.classinterfacetype.aspx"相对=nofollow>从MSDN :

      

    ClassInterfaceType.None

         

    表示没有类的接口   为类生成。如果不   接口被明确地实施,   类只能提供后期绑定   通过访问的IDispatch   接口。这是推荐的   设置 ClassInterfaceAttribute 。   使用 ClassInterfaceType.None 是   只有揭露功能的方法   通过实现的接口   明确地由类

  2. [标记有​​ComVisible特性(真)] 必须的COM知名度?

解决方案

请参阅<一href="http://blogs.msdn.com/mbend/archive/2007/04/17/classinterfacetype-none-is-my-recommended-option-over-autodispatch-autodual.aspx">this博客文章对于第一个问题的expanation。问题的关键是,除非你指定 ClassInterfaceType.None 额外的界面处产生,这可能会导致与二进制兼容性,如果你改变方法的顺序,改变他们的签名或删除一些对他们。更理想的办法是明确地定义一个接口,并从中指定 ClassInterfaceType.None

继承类

标记有ComVisible特性(真)不是一个必须的COM可见性。默认情况下公共类的所有公共方法和所有公共类的COM可见,所有其他实体都没有COM可见。如果你需要改变这一点,你使用的标记有ComVisible特性的属性,通常以减少COM可见类的量,因为每一个COM可见的类的注册表项,并输入生成库条目,这会导致不必要的注册表污染和膨胀的类型库。国际海事组织是显式标记与标记有ComVisible特性的所有公共实体是一个好主意。

  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 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.

这篇关于需要ClassInterfaceType.None的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆