为什么公共字段和属性可以互换二进制兼容?

发布于 2024-09-03 01:13:48 字数 299 浏览 3 评论 0原文

在日常工作中,我开发一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

毅然前行 2024-09-10 01:13:49

不,它没有破坏兼容性,因为它没有删除属性 get 和 property let 方法。只是编译器现在正在为您编写它们。

这难道不是 VB6 可以说比 .Net 更好的少数几个领域之一吗?

  • 在 .Net 中,公共字段的行为与公共属性不同,此 使一些重构变得困难并导致混乱
  • 在 VB6 中,公共字段的行为与公共属性完全相同,这就是为什么可以在不影响二进制兼容性的情况下进行切换。在幕后,编译器 生成公共字段的属性获取和设置例程。从某种意义上说,VB6已经自动实现了属性(现在宣传为 VB10 中的“新功能”)...

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?

  • In .Net public fields behave differently to public properties, and this makes some refactorings difficult and causes confusion.
  • In VB6 public fields behave exactly like public properties, which is why it's possible to switch without affecting binary compatibility. Behind the scenes, the compiler generates property get and set routines for public fields. In a sense VB6 has automatically implemented properties (now advertised as a "new feature" in VB10)...
烟火散人牵绊 2024-09-10 01:13:49

我认为这比这更微妙。您将获得 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 :/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文