2002-01-14 Miguel de Icaza <miguel@ximian.com>
[mono.git] / mcs / class / corlib / System / Console.cs
1 //
2 // System.Console.cs
3 //
4 // Author:
5 //   Dietmar Maurer (dietmar@ximian.com)
6 //
7 // (C) Ximian, Inc.  http://www.ximian.com
8 //
9
10 using System.IO;
11 using System.PAL;
12
13 namespace System {
14
15         public sealed class Console {
16
17                 private static TextWriter stdout;
18                 private static TextWriter stderr;
19                 private static TextReader stdin;
20
21                 private static OpSys _os = Platform.OS;
22
23                 static Console ()
24                 {
25                         stderr = new StreamWriter (OpenStandardError ());
26                         stdout = new StreamWriter (OpenStandardOutput ());
27                         stdin  = new StreamReader (OpenStandardInput ());
28                 }
29                 
30                 public static TextWriter Error
31                 {
32                         get {
33                                 return stderr;
34                         }
35                 }
36
37                 public static TextWriter Out
38                 {
39                         get {
40                                 return stdout;
41                         }
42                 }
43
44                 public static TextReader In
45                 {
46                         get {
47                                 return stdin;
48                         }
49                 }
50
51                 public static Stream OpenStandardError ()
52                 {
53                         return OpenStandardError (0);
54                 }
55                 
56                 public static Stream OpenStandardError (int bufferSize)
57                 {
58                         return new FileStream (_os.StderrHandle,
59                                                FileAccess.Write,
60                                                false,  bufferSize);
61                 }
62
63                 public static Stream OpenStandardInput ()
64                 {
65                         return OpenStandardInput (0);
66                 }
67                 
68                 public static Stream OpenStandardInput (int bufferSize)
69                 {
70                         return new FileStream (_os.StdinHandle,
71                                                FileAccess.Read,
72                                                false,  bufferSize);
73                 }
74
75                 public static Stream OpenStandardOutput ()
76                 {
77                         return OpenStandardOutput (0);
78                 }
79                 
80                 public static Stream OpenStandardOutput (int bufferSize)
81                 {
82                         return new FileStream (_os.StdoutHandle,
83                                                FileAccess.Write,
84                                                false,  bufferSize);
85                 }
86
87                 public static void setError (TextWriter newError)
88                 {
89                         if (newError == null)
90                                 throw new ArgumentNullException ();
91
92                         stderr = newError;
93                 }
94
95                 public static void setIn (TextReader newIn)
96                 {
97                         if (newIn == null)
98                                 throw new ArgumentNullException ();
99
100                         stdin = newIn;
101                 }
102
103                 public static void setOut (TextWriter newOut)
104                 {
105                         if (newOut == null)
106                                 throw new ArgumentNullException ();
107
108                         stdout = newOut;
109                 }
110
111                 public static void Write (bool value)
112                 {
113                         stdout.Write (value);
114                 }
115
116                 public static void Write (char value)
117                 {
118                         stdout.Write (value);
119                 }
120
121                 public static void Write (char[] value)
122                 {
123                         stdout.Write (value);
124                 }
125                 
126                 public static void Write (decimal value)
127                 {
128                         stdout.Write (value);
129                 }
130                 
131                 public static void Write (double value)
132                 {
133                         stdout.Write (value);
134                 }
135
136                 public static void Write (int value)
137                 {
138                         stdout.Write (value);
139                 }
140                 
141                 public static void Write (long value)
142                 {
143                         stdout.Write (value);
144                 }
145                 
146                 public static void Write (object value)
147                 {
148                         stdout.Write (value);
149                 }
150                 
151                 public static void Write (float value)
152                 {
153                         stdout.Write (value);
154                 }
155                 
156                 public static void Write (string value)
157                 {
158                         stdout.Write (value);
159                 }
160                 
161                 [CLSCompliant(false)]
162                 public static void Write (uint value)
163                 {
164                         stdout.Write (value);
165                 }
166                 
167                 [CLSCompliant(false)]
168                 public static void Write (ulong value)
169                 {
170                         stdout.Write (value);
171                 }
172                 
173                 public static void Write (string format, object arg0)
174                 {
175                         stdout.Write (format, arg0);
176                 }
177                 
178                 public static void Write (string format, params object[] arg)
179                 {
180                         stdout.Write (format, arg);
181                 }
182                 
183                 public static void Write (char[] buffer, int index, int count)
184                 {
185                         stdout.Write (buffer, index, count);
186                 }
187                 
188                 public static void Write (string format, object arg0, object arg1)
189                 {
190                         stdout.Write (format, arg0, arg1);
191                 }
192                 
193                 public static void Write (string format, object arg0, object arg1, object arg2 )
194                 {
195                         stdout.Write (format, arg0, arg1, arg2);
196                 }
197                 
198                 public static void WriteLine ()
199                 {
200                         stdout.WriteLine ();
201                 }
202                 
203                 public static void WriteLine (bool value)
204                 {
205                         stdout.Write (value);
206                         stdout.WriteLine();
207                 }
208                 
209                 public static void WriteLine (char value)
210                 {
211                         stdout.Write (value);
212                         stdout.WriteLine();
213                 }
214                 
215                 public static void WriteLine (char[] value)
216                 {
217                         stdout.Write (value);
218                         stdout.WriteLine();
219                 }
220                 
221                 public static void WriteLine (decimal value)
222                 {
223                         stdout.Write (value);
224                         stdout.WriteLine();
225                 }
226                 
227                 public static void WriteLine (double value)
228                 {
229                         stdout.Write (value);
230                         stdout.WriteLine();
231                 }
232                 
233                 public static void WriteLine (int value)
234                 {
235                         stdout.Write (value);
236                         stdout.WriteLine();
237                 }
238                 
239                 public static void WriteLine (long value)
240                 {
241                         stdout.Write (value);
242                         stdout.WriteLine();
243                 }
244                 
245                 public static void WriteLine (object value)
246                 {
247                         stdout.Write (value);
248                         stdout.WriteLine();
249                 }
250                 
251                 public static void WriteLine (float value)
252                 {
253                         stdout.Write (value);
254                         stdout.WriteLine();
255                 }
256                 
257                 public static void WriteLine (string value)
258                 {
259                         stdout.Write (value);
260                         stdout.WriteLine();
261                 }
262                 
263                 [CLSCompliant(false)]
264                 public static void WriteLine (uint value)
265                 {
266                         stdout.Write (value);
267                         stdout.WriteLine();
268                 }
269                 
270                 [CLSCompliant(false)]
271                 public static void WriteLine (ulong value)
272                 {
273                         stdout.Write (value);
274                         stdout.WriteLine();
275                 }
276                 
277                 public static void WriteLine (string format, object arg0)
278                 {
279                         stdout.Write (format, arg0);
280                         stdout.WriteLine();
281                 }
282                 
283                 public static void WriteLine (string format, params object[] arg)
284                 {
285                         stdout.Write (format, arg);
286                         stdout.WriteLine();
287                 }
288                 
289                 public static void WriteLine (char[] buffer, int index, int count)
290                 {
291                         stdout.Write (buffer, index, count);
292                         stdout.WriteLine();
293                 }
294                 
295                 public static void WriteLine (string format, object arg0, object arg1)
296                 {
297                         stdout.Write (format, arg0, arg1);
298                         stdout.WriteLine();
299                 }
300                 
301                 public static void WriteLine (string format, object arg0, object arg1, object arg2)
302                 {
303                         stdout.Write (format, arg0, arg1, arg2);
304                         stdout.WriteLine();
305                 }
306
307                 public static int Read ()
308                 {
309                         return stdin.Read ();
310                 }
311                 
312                 public static string ReadLine ()
313                 {
314                         return stdin.ReadLine ();
315                 }
316                 
317         }
318 }