2001-11-21 Miguel de Icaza <miguel@ximian.com>
[mono.git] / mcs / class / corlib / System / SByte.cs
1 //
2 // System.SByte.cs
3 //
4 // Author:
5 //   Miguel de Icaza (miguel@ximian.com)
6 //
7 // (C) Ximian, Inc.  http://www.ximian.com
8 //
9
10 using System.Globalization;
11
12 namespace System {
13
14         [CLSCompliant(false)]
15         public struct SByte : IComparable, IFormattable { //, IConvertible {
16                 public static Type Type = typeof (sbyte);
17
18                 public const sbyte MinValue = -128;
19                 public const sbyte MaxValue = 127;
20                 
21                 // VES needs to know about value.  public is workaround
22                 // so source will compile
23                 public sbyte value;
24
25                 public int CompareTo (object v)
26                 {
27                         if (v == null || !(v is System.SByte))
28                                 throw new ArgumentException (Locale.GetText ("Value is not a System.SByte"));
29
30                         return value - ((sbyte) v);
31                 }
32
33                 public override bool Equals (object o)
34                 {
35                         if (!(o is System.SByte))
36                                 return false;
37
38                         return ((sbyte) o) == value;
39                 }
40
41                 public override int GetHashCode ()
42                 {
43                         return value;
44                 }
45
46                 public static sbyte Parse (string s)
47                 {
48                         return Parse (s, NumberStyles.Integer, null);
49                 }
50
51                 public static sbyte Parse (string s, IFormatProvider fp)
52                 {
53                         return Parse (s, NumberStyles.Integer, fp);
54                 }
55
56                 public static sbyte Parse (string s, NumberStyles style)
57                 {
58                         return Parse (s, style, null);
59                 }
60
61                 public static sbyte Parse (string s, NumberStyles style, IFormatProvider fp)
62                 {
63                         // TODO: Implement me
64                         throw new NotImplementedException ();
65                 }
66
67                 public override string ToString ()
68                 {
69                         return ToString ("G", null);
70                 }
71
72                 public string ToString (IFormatProvider fp)
73                 {
74                         return ToString ("G", fp);
75                 }
76
77                 public string ToString (string format)
78                 {
79                         return ToString (format, null);
80                 }
81
82                 public string ToString (string format, IFormatProvider fp)
83                 {
84                         string fmt;
85                         NumberFormatInfo nfi;
86                         
87                         fmt = (format == null) ? "G" : format;
88                         
89                         if (fp == null)
90                                 nfi = NumberFormatInfo.CurrentInfo;
91                         else {
92                                 nfi = (NumberFormatInfo) fp.GetFormat (Type);
93                                 
94                                 if (nfi == null)
95                                         nfi = NumberFormatInfo.CurrentInfo;
96                         }
97
98                         return IntegerFormatter.NumberToString (fmt, nfi, value);
99                 }
100
101                 // =========== ICovnertible Methods =========== //
102
103                 public TypeCode GetTypeCode ()
104                 {
105                         return TypeCode.Byte;
106                 }
107         }
108 }