[Mono-winforms-list] Quick question about bug 661750

stifu at free.fr stifu at free.fr
Wed Jan 5 02:38:25 EST 2011


Hi guys,

I'll go ahead and do this in the next few days, unless someone pops up and objects.
I'll add a nice comment explaining why it's okay to cast to Int64.

----- Mail Original -----
De: stifu at free.fr
À: "mono-winforms-list" <mono-winforms-list at lists.ximian.com>
Cc: "Miguel de Icaza" <miguel at novell.com>
Envoyé: Dimanche 2 Janvier 2011 21:45:33 GMT +01:00 Amsterdam / Berlin / Berne / Rome / Stockholm / Vienne
Objet: Quick question about bug 661750

Bug 661750 is about an exception when converting the value of a NumericUpDown control to hexadecimal, if the value is 0.
This conversion happens in the UpdateEditText method of the NumericUpDown control. The author of the code added the following comments:

// Decimal.ToString doesn't know the "X" formatter, and
// converting it to an int is narrowing, so do it
// manually..

It'd be possible to fix this conversion bug by updating the conversion code a little, but instead, Oliver proposes (in bug report 661750) that we do this instead:

Text = ((Int64)dvalue).ToString("X", CultureInfo.CurrentCulture);

Which seems right, as Int64.MaxValue is actually the maximum value of a NumericUpDown in hexa mode, not Decimal.MaxValue. So there would be no precision loss, actually.
I support this suggestion very strongly, as that'd mean we'd replace 131 lines of code with a single one. Slimming down the NumericUpDown code from 615 lines to 485, and therefore avoiding more potential bugs.

Does this seem alright?

Oh, and while I'm here, do you prefer "Int64" or "long"? I don't think I've seen that specified in the Mono guidelines. But from what I've seen "int" is more commonly used than "Int32", so it'd probably make sense to go for "long".


More information about the Mono-winforms-list mailing list