[corlib] ParseNumber.StringToInt now check for overflows.
[mono.git] / mcs / class / corlib / System / ConsoleKeyInfo.cs
1 //
2 // System.ConsoleKeyInfo.cs
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // (C) 2005 Novell, Inc (http://www.novell.com)
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 namespace System {
31         [Serializable]
32         public struct ConsoleKeyInfo {
33                 internal static ConsoleKeyInfo Empty = new ConsoleKeyInfo ('\0', 0, false, false, false);
34                 ConsoleKey _key;
35                 char _keyChar;
36                 ConsoleModifiers _mods;
37
38                 public ConsoleKeyInfo (char keyChar, ConsoleKey key, bool shift, bool alt, bool control)
39                 {
40                         _key = key;
41                         _keyChar = keyChar;
42                         _mods = 0;
43                         SetModifiers (shift, alt, control);
44                 }
45
46                 internal ConsoleKeyInfo (ConsoleKeyInfo other)
47                 {
48                         _key = other._key;
49                         _keyChar = other._keyChar;
50                         _mods = other._mods;
51                 }
52
53                 internal void SetKey (ConsoleKey key)
54                 {
55                         _key = key;
56                 }
57
58                 internal void SetKeyChar (char keyChar)
59                 {
60                         _keyChar = keyChar;
61                 }
62
63                 internal void SetModifiers (bool shift, bool alt, bool control)
64                 {
65                         _mods = (shift) ? ConsoleModifiers.Shift : 0;
66                         _mods |= (alt) ? ConsoleModifiers.Alt : 0;
67                         _mods |= (control) ? ConsoleModifiers.Control : 0;
68                 }
69
70                 public ConsoleKey Key 
71                 {
72                         get { return _key; }
73                 }
74
75                 public char KeyChar 
76                 {
77                         get { return _keyChar; }
78                 }
79
80                 public ConsoleModifiers Modifiers 
81                 {
82                         get { return _mods; }
83                 }
84
85                 public override bool Equals (object value)
86                 {
87                         if (!(value is ConsoleKeyInfo))
88                                 return false;
89
90                         return Equals ((ConsoleKeyInfo) value);
91                 }
92
93                 public static bool operator == (ConsoleKeyInfo a, ConsoleKeyInfo b)
94                 {
95                         return a.Equals (b);
96                 }
97
98                 public static bool operator != (ConsoleKeyInfo a, ConsoleKeyInfo b)
99                 {
100                         return !a.Equals (b);
101                 }
102
103                 public bool Equals (ConsoleKeyInfo obj)
104                 {
105                         return _key == obj._key && _keyChar == obj._keyChar && _mods == obj._mods;
106                 }
107
108                 public override int GetHashCode ()
109                 {
110                         return _key.GetHashCode () ^ _keyChar.GetHashCode () ^ _mods.GetHashCode ();
111                 }
112         }
113 }