{
[Serializable]
[CLSCompliant (false)]
+#if NET_2_0
+ [System.Runtime.InteropServices.ComVisible (true)]
+#endif
public struct UInt32 : IFormattable, IConvertible, IComparable
#if NET_2_0
, IComparable<UInt32>, IEquatable <UInt32>
if (!(value is System.UInt32))
throw new ArgumentException (Locale.GetText ("Value is not a System.UInt32."));
- if (this.m_value == (uint) value)
- return 0;
+ uint val = (uint) value;
- if (this.m_value < (uint) value)
- return -1;
+ if (m_value == val)
+ return 0;
- return 1;
+ return (m_value < val) ? -1 : 1;
}
public override bool Equals (object obj)
return -1;
}
- public bool Equals (uint value)
+ public bool Equals (uint obj)
{
- return value == m_value;
+ return obj == m_value;
}
#endif
if (c >= '0' && c <= '9') {
uint d = (uint) (c - '0');
- val = checked (val * 10 + d);
- digits_seen = true;
- }
- else {
- if (Char.IsWhiteSpace (c)) {
- for (i++; i < len; i++) {
- if (!Char.IsWhiteSpace (s [i])) {
- if (!tryParse)
- exc = Int32.GetFormatException ();
- return false;
- }
- }
- break;
- } else {
+ if ((val > MaxValue/10) || (val == (MaxValue / 10) && d > (MaxValue % 10))){
if (!tryParse)
- exc = Int32.GetFormatException ();
+ exc = new OverflowException (Locale.GetText ("Value is too large"));
return false;
}
+ val = (val * 10) + d;
+ digits_seen = true;
+ } else if (!Int32.ProcessTrailingWhitespace (tryParse, s, i, ref exc)){
+ return false;
}
}
if (!digits_seen) {
else
digitValue = (uint) (hexDigit - 'A' + 10);
- number = checked (number * 16 + digitValue);
+ if (tryParse){
+ ulong l = number * 16 + digitValue;
+
+ if (l > MaxValue)
+ return false;
+ number = (uint) l;
+ } else
+ number = checked (number * 16 + digitValue);
}
else if (decimalPointFound) {
nDigits++;
}
[CLSCompliant (false)]
- public static uint Parse (string s, NumberStyles style, IFormatProvider fp)
+ public static uint Parse (string s, NumberStyles style, IFormatProvider provider)
{
Exception exc;
uint res;
- if (!Parse (s, style, fp, false, out res, out exc))
+ if (!Parse (s, style, provider, false, out res, out exc))
throw exc;
return res;
public override string ToString ()
{
- return NumberFormatter.FormatGeneral (new NumberFormatter.NumberStore (m_value));
+ return NumberFormatter.NumberToString (m_value, null);
}
- public string ToString (IFormatProvider fp)
+ public string ToString (IFormatProvider provider)
{
- return NumberFormatter.FormatGeneral (new NumberFormatter.NumberStore (m_value), fp);
+ return NumberFormatter.NumberToString (m_value, provider);
}
public string ToString (string format)
return ToString (format, null);
}
- public string ToString (string format, IFormatProvider fp)
+ public string ToString (string format, IFormatProvider provider)
{
- NumberFormatInfo nfi = NumberFormatInfo.GetInstance (fp);
- return NumberFormatter.NumberToString (format, m_value, nfi);
+ return NumberFormatter.NumberToString (format, m_value, provider);
}
// =========== IConvertible Methods =========== //