dotgnu-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[DotGNU]Enum.ToObject


From: Thong \(Tum\) Nguyen
Subject: [DotGNU]Enum.ToObject
Date: Wed, 30 Jul 2003 00:04:39 +1200

Hi Guys,

I was just looking at bug 4507
(http://savannah.gnu.org/bugs/?func=detailbug&bug_id=4507&group_id=353)

It looks like Microsoft uses a different method for getting the object
value of an enum.  Here's an illustration:

using System;
using System.Threading;

public class E
{
        public enum MyEnum
        {
                ONE1 = 1,
                ONE2 = 1,
                ONE3 = 1
        }

        public static void Main()
        {
                Console.WriteLine(Enum.ToObject(typeof(MyEnum), 1));
        }
}


On MS.NET it prints "ONE2" and on pnet it (correctly IMO) prints "ONE1".

The reason MS's prints ONE2 is because MS internally sorts the enum's
fields based on the field values and then uses those sorted values for
all lookups (including for calls to GetValues and GetNames).  PNET on
the other hand simply uses and searches the enum field values in the
order they're written.

We need to make GetValues & GetNames do sorting (which is "required" by
MS docs) but do you think we need to worry about ToObject()?  I think
pnet abides by the spec even though it uses a different underlying
implementation.  The different implementation unfortunately gives a
different (although technically still correct) output.

Any thoughts on the matter would be appreciated...

Thanks,

^Tum





reply via email to

[Prev in Thread] Current Thread [Next in Thread]