2 // System.Runtime.Serialization.Formatter.cs
4 // Duncan Mak (duncan@ximian.com)
10 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
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.
33 using System.Runtime.Serialization;
35 namespace System.Runtime.Serialization {
37 [System.Runtime.InteropServices.ComVisibleAttribute (true)]
39 public class FormatterConverter : IFormatterConverter {
41 public FormatterConverter ()
45 public object Convert (object value, Type type)
47 return System.Convert.ChangeType (value, type);
50 public object Convert (object value, TypeCode typeCode)
52 return System.Convert.ChangeType (value, typeCode);
55 public bool ToBoolean (object value)
58 throw new ArgumentNullException ("value is null.");
60 return System.Convert.ToBoolean (value);
63 public byte ToByte (object value)
66 throw new ArgumentNullException ("value is null.");
68 return System.Convert.ToByte (value);
71 public char ToChar (object value)
74 throw new ArgumentNullException ("value is null.");
76 return System.Convert.ToChar (value);
79 public DateTime ToDateTime (object value)
82 throw new ArgumentNullException ("value is null.");
84 return System.Convert.ToDateTime (value);
87 public decimal ToDecimal (object value)
90 throw new ArgumentNullException ("value is null.");
92 return System.Convert.ToDecimal (value);
95 public double ToDouble (object value)
98 throw new ArgumentNullException ("value is null.");
100 return System.Convert.ToDouble (value);
103 public short ToInt16 (object value)
106 throw new ArgumentNullException ("value is null.");
108 return System.Convert.ToInt16 (value);
111 public int ToInt32 (object value)
114 throw new ArgumentNullException ("value is null.");
116 return System.Convert.ToInt32 (value);
119 public long ToInt64 (object value)
122 throw new ArgumentNullException ("value is null.");
124 return System.Convert.ToInt64 (value);
127 public float ToSingle (object value)
130 throw new ArgumentNullException ("value is null.");
132 return System.Convert.ToSingle (value);
135 public string ToString (object value)
138 throw new ArgumentNullException ("value is null.");
140 return System.Convert.ToString (value);
143 [CLSCompliant (false)]
144 public sbyte ToSByte (object value)
147 throw new ArgumentNullException ("value is null.");
149 return System.Convert.ToSByte (value);
152 [CLSCompliant (false)]
153 public ushort ToUInt16 (object value)
156 throw new ArgumentNullException ("value is null.");
158 return System.Convert.ToUInt16 (value);
161 [CLSCompliant (false)]
162 public uint ToUInt32 (object value)
165 throw new ArgumentNullException ("value is null.");
167 return System.Convert.ToUInt32 (value);
170 [CLSCompliant (false)]
171 public ulong ToUInt64 (object value)
174 throw new ArgumentNullException ("value is null.");
176 return System.Convert.ToUInt64 (value);