[Mono-bugs] [Bug 371559] New: Enum.ToString doesn' t recognize all members when overlapping Flags

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sun Mar 16 11:05:05 EDT 2008


https://bugzilla.novell.com/show_bug.cgi?id=371559

User andyhume32 at yahoo.co.uk added comment
https://bugzilla.novell.com/show_bug.cgi?id=371559#c1

           Summary: Enum.ToString doesn't recognize all members when
                    overlapping Flags
           Product: Mono: Class Libraries
           Version: 1.2.6
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: CORLIB
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: andyhume32 at yahoo.co.uk
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


Repro:
[[
using System.Windows.Forms;// Keys enum
..
Assert.AreEqual("D9", Keys.D9.ToString(), "#1");
Assert.AreEqual("Modifiers", Keys.Modifiers.ToString(), "#2");
]]

Case #2 fails, instead returning "-65536".  Both cases pass on MSFT.

That member is defined as 0xFFFF0000, the enum is [Flags], and the problem only
occurs when there's another member that (slightly) overlaps i.e.
Alt=0x00040000.

A local test-case enum is thus:
[[
[Flags]
enum Aaaa
{
   D9=0x39,
   Alt=0x00040000,
   Modifiers=unchecked((int)0xFFFF0000)
}
]]

If either Alt or [Flags] is removed then ToString works as expected.

Perhaps Mono is not following one aspect of Enum.Format behaviour as listed in
MSDN:
   "… value is searched for flags, going from the flag with the 
     largest value to the smallest value …"

In fact, MonoEnumInfo.GetInfo sorts them in ascending order -- which is likely
the case to suit Enum.GetValues "...sorted by the binary values...".   Seems
that we need a version of that method which will sort them in descending order
for the FormatFlags case.


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list