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