2008-09-14 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mcs / class / corlib / System.Runtime.Serialization / FormatterConverter.cs
1 //
2 // System.Runtime.Serialization.Formatter.cs
3 //
4 // Duncan Mak  (duncan@ximian.com)
5 //
6 // (C) Ximian, Inc.
7 //
8
9 //
10 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31
32 using System;
33 using System.Runtime.Serialization;
34
35 namespace System.Runtime.Serialization {
36 #if NET_2_0
37         [System.Runtime.InteropServices.ComVisibleAttribute (true)]
38 #endif
39         public class FormatterConverter : IFormatterConverter {
40
41                 public FormatterConverter ()
42                 {
43                 }
44
45                 public object Convert (object value, Type type)
46                 {
47                         return System.Convert.ChangeType (value, type);
48                 }
49
50                 public object Convert (object value, TypeCode typeCode)
51                 {
52                         return System.Convert.ChangeType (value, typeCode);
53                 }
54
55                 public bool ToBoolean (object value)
56                 {
57                         if (value == null)
58                                 throw new ArgumentNullException ("value is null.");
59                 
60                         return System.Convert.ToBoolean (value);
61                 }
62
63                 public byte ToByte (object value)
64                 {
65                         if (value == null)
66                                 throw new ArgumentNullException ("value is null.");
67
68                         return System.Convert.ToByte (value);
69                 }
70
71                 public char ToChar (object value)
72                 {
73                         if (value == null)
74                                 throw new ArgumentNullException ("value is null.");
75
76                         return System.Convert.ToChar (value);
77                 }
78
79                 public DateTime ToDateTime (object value)
80                 {
81                         if (value == null)
82                                 throw new ArgumentNullException ("value is null.");
83
84                         return System.Convert.ToDateTime (value);
85                 }
86
87                 public decimal ToDecimal (object value)
88                 {
89                         if (value == null)
90                                 throw new ArgumentNullException ("value is null.");
91
92                         return System.Convert.ToDecimal (value);
93                 }
94
95                 public double ToDouble (object value)
96                 {
97                         if (value == null)
98                                 throw new ArgumentNullException ("value is null.");
99
100                         return System.Convert.ToDouble (value);
101                 }
102
103                 public short ToInt16 (object value)
104                 {
105                         if (value == null)
106                                 throw new ArgumentNullException ("value is null.");
107
108                         return System.Convert.ToInt16 (value);
109                 }
110
111                 public int ToInt32 (object value)
112                 {
113                         if (value == null)
114                                 throw new ArgumentNullException ("value is null.");
115
116                         return System.Convert.ToInt32 (value);
117                 }
118
119                 public long ToInt64 (object value)
120                 {
121                         if (value == null)
122                                 throw new ArgumentNullException ("value is null.");
123
124                         return System.Convert.ToInt64 (value);
125                 }
126
127                 public float ToSingle (object value)
128                 {
129                         if (value == null)
130                                 throw new ArgumentNullException ("value is null.");
131
132                         return System.Convert.ToSingle (value);
133                 }
134
135                 public string ToString (object value)
136                 {
137                         if (value == null)
138                                 throw new ArgumentNullException ("value is null.");
139
140                         return System.Convert.ToString (value);
141                 }
142
143                 [CLSCompliant (false)]
144                 public sbyte ToSByte (object value)
145                 {
146                         if (value == null)
147                                 throw new ArgumentNullException ("value is null.");
148
149                         return System.Convert.ToSByte (value);
150                 }
151
152                 [CLSCompliant (false)]
153                 public ushort ToUInt16 (object value)
154                 {
155                         if (value == null)
156                                 throw new ArgumentNullException ("value is null.");
157
158                         return System.Convert.ToUInt16 (value);
159                 }
160
161                 [CLSCompliant (false)]
162                 public uint ToUInt32 (object value)
163                 {
164                         if (value == null)
165                                 throw new ArgumentNullException ("value is null.");
166
167                         return System.Convert.ToUInt32 (value);
168                 }
169
170                 [CLSCompliant (false)]
171                 public ulong ToUInt64 (object value)
172                 {
173                         if (value == null)
174                                 throw new ArgumentNullException ("value is null.");
175
176                         return System.Convert.ToUInt64 (value);
177                 }
178         }
179 }