Friday 15 April 2011

asp.net - C# synonymous enum handling -


It is either clever or half-clever, not enough to 62.784%, for odd reasons, our product management decided Done that they want to change the name of some of our values ​​and how they are sorted. After a few different productions they decided that they want to be backwards compatible - that is to read and process older versions of old values.

I thought that I want to declare a new name on the first name, then declare it only after a synonyms, old name = new name , hopefully In the favor of the first declaration, it will succeed to wash the similarity and it will automatically Enum.Parse .

I prepared a small sample app like this:

  Public reward symbols {zero, one, two, three = two, four,}; Public string SynTest () {string result; Syns synTest2 = (syns) syns.Two, synTest3; Bull is ok = Enum.TryParse & lt; Syns & gt; ("Three", outside synTest3); Result = (OK). Ostring () + "," + (synTest2 == synTest3) ostring () + "," + synTest2.ToString () + "," + synTest3.ToString () + ","; SynTest3 = (syns) Enum.Parse (type (syns), "three"); Results + = synTest3.ToString (); Return result; }  

And what I wanted was the old name "three" is parsed, and when the value parsed was evaluated, its The new name was two in every way ie that.

That's why I used the technique in our actual code (working for a long time with app-specific names / values) on my machine, so I checked it.

Our problem is that how it is controlled, there is no consistency in it. Build got queued with QA, and was parsed (equal to) "three" and instead of evaluating the new version two, the whole (old name) as three .

After pulling this thread for a while, it seems that about 50% of the machines were trying to process it on the way my machine (new value prevails) and 50 old names % Skew on

I tried to drag all test cases to a test.aspx page, and my test.aspx page behaves differently than the underlying assemblies. And in the test.aspx page, the above mentioned above behaves differently from our code base than the actual enum.

  1. Any sign which determines how the model evaluates the values ​​
  2. Any ideas why similar assemblies would change machine to the machine? All machines are ready to target 4.5.1 framework, and at least they seemed to be at the same patch level compared to the pair.
  3. Even on a machine where I got the desired behavior, the same announcement in Test.aspx has changed the behavior, so I was thinking that it is playable on file-by-file basis .

This is "plain" under the document:

Notes for callers
If multiple calculations are inherent in the same value as members and you try to represent the string of the counting member's name based on your underlying value, < Strong> Your code should not be done with any assumptions about which method will come back.

(my emphasis)

This is documented for unspecified behavior, in fact, on a machine (appropriately ) May be coherent behavior, depending on NAT runtime version, .NET hotfixes, etc. But you can not make a guarantee that he will continue to behave like tomorrow or next week.

In short, you can not do it like this, you need to find another way to handle aliasing.


No comments:

Post a Comment