更改字段属性是在什么情况下一个重大更改? [英] Changing fields to property is a breaking change under what scenarios?

查看:150
本文介绍了更改字段属性是在什么情况下一个重大更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读乔恩斯基特对领域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

您不能轻易地对场结合。 (这是为什么呢?我读<一href="http://stackoverflow.com/questions/174198/c3-0-automatic-properties-why-not-access-the-field-directly">here)

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

???

编辑:罗伯特有一个COM prehensive的原因选择列表<一href="http://stackoverflow.com/questions/205568/have-trivial-properties-ever-saved-your-bacon/207146#207146">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).

这篇关于更改字段属性是在什么情况下一个重大更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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