Add license and copyright to all source files in corlib
[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         public class FormatterConverter : IFormatterConverter {
37
38                 public FormatterConverter ()
39                 {
40                 }
41
42                 public object Convert (object value, Type type)
43                 {
44                         return System.Convert.ChangeType (value, type);
45                 }
46
47                 public object Convert (object value, TypeCode typeCode)
48                 {
49                         return System.Convert.ChangeType (value, typeCode);
50                 }
51
52                 public bool ToBoolean (object value)
53                 {
54                         if (value == null)
55                                 throw new ArgumentNullException ("value is null.");
56                 
57                         return System.Convert.ToBoolean (value);
58                 }
59
60                 public byte ToByte (object value)
61                 {
62                         if (value == null)
63                                 throw new ArgumentNullException ("value is null.");
64
65                         return System.Convert.ToByte (value);
66                 }
67
68                 public char ToChar (object value)
69                 {
70                         if (value == null)
71                                 throw new ArgumentNullException ("value is null.");
72
73                         return System.Convert.ToChar (value);
74                 }
75
76                 public DateTime ToDateTime (object value)
77                 {
78                         if (value == null)
79                                 throw new ArgumentNullException ("value is null.");
80
81                         return System.Convert.ToDateTime (value);
82                 }
83
84                 public decimal ToDecimal (object value)
85                 {
86                         if (value == null)
87                                 throw new ArgumentNullException ("value is null.");
88
89                         return System.Convert.ToDecimal (value);
90                 }
91
92                 public double ToDouble (object value)
93                 {
94                         if (value == null)
95                                 throw new ArgumentNullException ("value is null.");
96
97                         return System.Convert.ToDouble (value);
98                 }
99
100                 public short ToInt16 (object value)
101                 {
102                         if (value == null)
103                                 throw new ArgumentNullException ("value is null.");
104
105                         return System.Convert.ToInt16 (value);
106                 }
107
108                 public int ToInt32 (object value)
109                 {
110                         if (value == null)
111                                 throw new ArgumentNullException ("value is null.");
112
113                         return System.Convert.ToInt32 (value);
114                 }
115
116                 public long ToInt64 (object value)
117                 {
118                         if (value == null)
119                                 throw new ArgumentNullException ("value is null.");
120
121                         return System.Convert.ToInt64 (value);
122                 }
123
124                 public float ToSingle (object value)
125                 {
126                         if (value == null)
127                                 throw new ArgumentNullException ("value is null.");
128
129                         return System.Convert.ToSingle (value);
130                 }
131
132                 public string ToString (object value)
133                 {
134                         if (value == null)
135                                 throw new ArgumentNullException ("value is null.");
136
137                         return System.Convert.ToString (value);
138                 }
139
140                 [CLSCompliant (false)]
141                 public sbyte ToSByte (object value)
142                 {
143                         if (value == null)
144                                 throw new ArgumentNullException ("value is null.");
145
146                         return System.Convert.ToSByte (value);
147                 }
148
149                 [CLSCompliant (false)]
150                 public ushort ToUInt16 (object value)
151                 {
152                         if (value == null)
153                                 throw new ArgumentNullException ("value is null.");
154
155                         return System.Convert.ToUInt16 (value);
156                 }
157
158                 [CLSCompliant (false)]
159                 public uint ToUInt32 (object value)
160                 {
161                         if (value == null)
162                                 throw new ArgumentNullException ("value is null.");
163
164                         return System.Convert.ToUInt32 (value);
165                 }
166
167                 [CLSCompliant (false)]
168                 public ulong ToUInt64 (object value)
169                 {
170                         if (value == null)
171                                 throw new ArgumentNullException ("value is null.");
172
173                         return System.Convert.ToUInt64 (value);
174                 }
175         }
176 }