更改字段属性是在什么情况下一个重大更改?是在、字段、属性、重大

2023-09-06 09:47:02 作者:看不透忘不了

在阅读乔恩斯基特对领域VS属性文章,他提到,改变字段属性是一个重大更改。

While reading Jon Skeet's article on fields vs properties he mentions that changing fields to properties is a breaking change.

我想了解在这种变化可能会导致断常见的场景。随着情况下,如果可以的话,请提供任何细节。

I would like to understand the common scenarios in which this change can cause breaks. Along with the scenario, if you can, please provide any details.

对于初学者来说,有以下几点已经在别处提到的:

For starters, the following points have been mentioned elsewhere:

您不能,如果你是在类上使用反射改变字段属性。这是显而易见的,即使我没有细节。序列化就是使用反射来遍历对象和改变字段属性将打破序列化或改变输出一个场景

You can't change fields to properties if you are using reflection on the class. This is obvious even though I don't have details. Serialization is one scenario where reflection is used to iterate over the object and changing fields to properties will break the serializer or change the output

您不能轻易地对场结合。 (这是为什么呢?我读here)

You can't easily bind against fields. (Why is this? I read it here)

???

编辑:罗伯特有一个COM prehensive的原因选择列表properties在田野并还介绍了如何在它们之间的切换可能会导致重大更改。

Robert has a comprehensive list of reasons for choosing properties over fields and also explains how switching between them can cause a breaking change.

推荐答案

属性可以抛出任意异常,而字段无法(至少当编译器知道在编译时字段赋值)。

Properties can throw any arbitrary exceptions, whereas fields can't (at least when compiler knows about field assignment at compile time).