Wed Nov 14 16:30:27 CET 2001 Paolo Molaro <lupus@ximian.com>
[mono.git] / mcs / class / corlib / System / UInt16.cs
1 //
2 // System.UInt16.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 UInt16 : IComparable, IFormattable { //, IConvertible {
16                 private static Type Type = typeof (ushort);
17
18                 public const ushort MaxValue = 0xffff;
19                 public const ushort MinValue = 0;
20                 
21                 public ushort value;
22
23                 public int CompareTo (object v)
24                 {
25                         if (!(v is System.UInt16))
26                                 throw new ArgumentException ("Value is not a System.UInt16");
27
28                         return value - ((ushort) v);
29                 }
30
31                 public override bool Equals (object o)
32                 {
33                         if (!(o is System.UInt16))
34                                 return false;
35
36                         return ((ushort) o) == value;
37                 }
38
39                 public override int GetHashCode ()
40                 {
41                         return value;
42                 }
43
44                 public static ushort Parse (string s)
45                 {
46                         return Parse (s, NumberStyles.Integer, null);
47                 }
48
49                 public static ushort Parse (string s, IFormatProvider fp)
50                 {
51                         return Parse (s, NumberStyles.Integer, fp);
52                 }
53
54                 public static ushort Parse (string s, NumberStyles style)
55                 {
56                         return Parse (s, style, null);
57                 }
58
59                 public static ushort Parse (string s, NumberStyles style, IFormatProvider fp)
60                 {
61                         // TODO: Implement me
62                         return 0;
63                 }
64
65                 public override string ToString ()
66                 {
67                         return ToString ("G", null);
68                 }
69
70                 public string ToString (IFormatProvider fp)
71                 {
72                         return ToString ("G", fp);
73                 }
74
75                 public string ToString (string format)
76                 {
77                         return ToString (format, null);
78                 }
79
80                 public string ToString (string format, IFormatProvider fp)
81                 {
82                         string fmt;
83                         NumberFormatInfo nfi;
84                         
85                         fmt = (format == null) ? "G" : format;
86                         
87                         if (fp == null)
88                                 nfi = NumberFormatInfo.CurrentInfo;
89                         else {
90                                 nfi = (NumberFormatInfo) fp.GetFormat (Type);
91                                 
92                                 if (nfi == null)
93                                         nfi = NumberFormatInfo.CurrentInfo;
94                         }
95
96                         return IntegerFormatter.NumberToString (fmt, nfi, value);
97                 }
98
99                 // =========== IConvertible Methods =========== //
100
101                 public TypeCode GetTypeCode ()
102                 {
103                         return TypeCode.UInt16;
104                 }
105         }
106 }