为什么公共字段和属性可以互换二进制兼容?
在日常工作中,我开发一个 VB6(我知道,但不要嘲笑这个受苦的人……)应用程序,该应用程序使用了我们编写的许多库(也在曾经杰出的 VB6 中)。其中一个支持库有大量通过公共属性公开的私有成员,我被要求删除这些属性,并将私有成员变量提升到与原始属性同名的公共字段中。
现在,我不是 COM 专家,但我的印象是类中的每个公开项目都有它自己的 GUID。由于我们将从每个值从 2 个 Guid(Property Get 和 Property Let)变为仅使用一个(公共字段)的情况,我预计这会破坏二进制兼容性 - 但似乎并没有没有这样做。
谁能解释为什么?
In the day job, I work on a VB6 (I know, but don't mock the afflicted...) application that uses a number of libraries we have written (also in the ever illustrious VB6). One of these supporting libraries had a load of private members exposed via public properties, and I was asked to remove the properties, and promote the private member variables into public fields with the same name as the original properties.
Now, I'm no COM expert, but I was under the impression that each and every exposed item on a class gets it's own GUID. Since we would be going from a situation where each value went from 2 Guids (Property Get and Property Let) to one where they only used the one (the public field), I was expecting this to break binary compatibility - but it seems it hasn't done that.
Can anyone explain why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,它没有破坏兼容性,因为它没有删除属性 get 和 property let 方法。只是编译器现在正在为您编写它们。
这难道不是 VB6 可以说比 .Net 更好的少数几个领域之一吗?
No, it hasn't broken compatibility because it hasn't removed the property get and property let methods. It's just that the compiler is now writing them for you.
Isn't this one of the few areas where VB6 is arguably better than .Net?
我认为这比这更微妙。您将获得 COM 接口的 GUID(不是每个单独的字段/方法)。据我了解,二进制兼容性尝试确定当前编译的接口是否向后兼容 DLL 的参考版本(假设您有一个),并且仅在不兼容时才更改 GUID。
因此,我也很惊讶它决定删除所有兼容的 get/set 方法:/
I think it's a bit more subtle than that. You get a GUID for the COM interface (not each individual field/method). As I understand it the binary compatibility attempts to work out if the interface your currently compiling is backwards compatible with a reference version of your DLL (assuming you have one) and only changes the GUID if they are not compatible.
I'm therefore also surprised that it has decided removing all the get/set methods is compatible :/