改变一个枚举的次数是一个突破性的变化? [英] Is changing the number of an enum a breaking change?

查看:94
本文介绍了改变一个枚举的次数是一个突破性的变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下代码:

  public enum SomeCode 
{
NIF = 0
,NIE = 1
,CIF = 2
,PAS = 3
,NIN = 4
,SSN = 5
,OTH = 5
, UKN = 6
}

将更改 OTH = 5 OTH = 7 是一个突破性的变化?






编辑:我从来没有存储int值,只有枚举的文本表示。它可能在其他DLL中使用,但将使用相同的存储。

解决方案

这是一个突破性的变化,因为你正在改变一个公共API。



使用旧值构建的库/应用程序仍然保留旧值并使用它。您将需要重新编译它们。



从MSDN - 枚举(C#参考)


正如任何常量一样,所有对个人的引用在编译时,枚举的值将转换为数字文字。这可以创建潜在的版本控制问题,如常量(C#编程指南)中所述。



Consider the following code:

public enum SomeCode
{
     NIF = 0
    ,NIE = 1
    ,CIF = 2
    ,PAS = 3
    ,NIN = 4
    ,SSN = 5
    ,OTH = 5
    ,UKN = 6
}

Would changing OTH = 5 to OTH = 7 be a breaking change?


Edit: I never store the int value, only ever the text representation of the enum. It may be used in other DLLs, but will use the same storage.

解决方案

It is a breaking change, as you are changing a public API.

Libraries/applications that were built with the old value will still hold the old value and use it. You will need to recompile them all.

From MSDN - enum (C# Reference):

Just as with any constant, all references to the individual values of an enum are converted to numeric literals at compile time. This can create potential versioning issues as described in Constants (C# Programming Guide).

这篇关于改变一个枚举的次数是一个突破性的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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