5 // Miguel de Icaza (miguel@ximian.com)
7 // (C) Ximian, Inc. http://www.ximian.com
10 using System.Globalization;
15 public struct SByte : IComparable, IFormattable { //, IConvertible {
16 public static Type Type = typeof (sbyte);
18 public const sbyte MinValue = -128;
19 public const sbyte MaxValue = 127;
21 // VES needs to know about value. public is workaround
22 // so source will compile
25 public int CompareTo (object v)
30 if (!(v is System.SByte))
31 throw new ArgumentException (Locale.GetText ("Value is not a System.SByte"));
42 public override bool Equals (object o)
44 if (!(o is System.SByte))
47 return ((sbyte) o) == value;
50 public override int GetHashCode ()
55 public static sbyte Parse (string s)
61 bool digits_seen = false;
64 throw new ArgumentNullException (Locale.GetText ("s is null"));
69 for (i = 0; i < len; i++){
71 if (!Char.IsWhiteSpace (c))
76 throw new FormatException ();
89 if (c >= '0' && c <= '9'){
90 val = checked ((sbyte) (val * 10 + (c - '0')));
93 if (Char.IsWhiteSpace (c)){
94 for (i++; i < len; i++){
95 if (!Char.IsWhiteSpace (s [i]))
96 throw new FormatException ();
100 throw new FormatException ();
104 throw new FormatException ();
107 val = checked ((sbyte) -val);
112 public static sbyte Parse (string s, IFormatProvider fp)
114 return Parse (s, NumberStyles.Integer, fp);
117 public static sbyte Parse (string s, NumberStyles style)
119 return Parse (s, style, null);
123 public static sbyte Parse (string s, NumberStyles style, IFormatProvider fp)
125 // TODO: Implement me
126 throw new NotImplementedException ();
129 public override string ToString ()
131 return ToString ("G", null);
134 public string ToString (IFormatProvider fp)
136 return ToString ("G", fp);
139 public string ToString (string format)
141 return ToString (format, null);
144 public string ToString (string format, IFormatProvider fp)
147 NumberFormatInfo nfi;
149 fmt = (format == null) ? "G" : format;
152 nfi = NumberFormatInfo.CurrentInfo;
154 nfi = (NumberFormatInfo) fp.GetFormat (Type);
157 nfi = NumberFormatInfo.CurrentInfo;
160 return IntegerFormatter.NumberToString (fmt, nfi, value);
163 // =========== ICovnertible Methods =========== //
165 public TypeCode GetTypeCode ()
167 return TypeCode.Byte;