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 {
36 public class FormatterConverter : IFormatterConverter {
38 public FormatterConverter ()
42 public object Convert (object value, Type type)
44 return System.Convert.ChangeType (value, type);
47 public object Convert (object value, TypeCode typeCode)
49 return System.Convert.ChangeType (value, typeCode);
52 public bool ToBoolean (object value)
55 throw new ArgumentNullException ("value is null.");
57 return System.Convert.ToBoolean (value);
60 public byte ToByte (object value)
63 throw new ArgumentNullException ("value is null.");
65 return System.Convert.ToByte (value);
68 public char ToChar (object value)
71 throw new ArgumentNullException ("value is null.");
73 return System.Convert.ToChar (value);
76 public DateTime ToDateTime (object value)
79 throw new ArgumentNullException ("value is null.");
81 return System.Convert.ToDateTime (value);
84 public decimal ToDecimal (object value)
87 throw new ArgumentNullException ("value is null.");
89 return System.Convert.ToDecimal (value);
92 public double ToDouble (object value)
95 throw new ArgumentNullException ("value is null.");
97 return System.Convert.ToDouble (value);
100 public short ToInt16 (object value)
103 throw new ArgumentNullException ("value is null.");
105 return System.Convert.ToInt16 (value);
108 public int ToInt32 (object value)
111 throw new ArgumentNullException ("value is null.");
113 return System.Convert.ToInt32 (value);
116 public long ToInt64 (object value)
119 throw new ArgumentNullException ("value is null.");
121 return System.Convert.ToInt64 (value);
124 public float ToSingle (object value)
127 throw new ArgumentNullException ("value is null.");
129 return System.Convert.ToSingle (value);
132 public string ToString (object value)
135 throw new ArgumentNullException ("value is null.");
137 return System.Convert.ToString (value);
140 [CLSCompliant (false)]
141 public sbyte ToSByte (object value)
144 throw new ArgumentNullException ("value is null.");
146 return System.Convert.ToSByte (value);
149 [CLSCompliant (false)]
150 public ushort ToUInt16 (object value)
153 throw new ArgumentNullException ("value is null.");
155 return System.Convert.ToUInt16 (value);
158 [CLSCompliant (false)]
159 public uint ToUInt32 (object value)
162 throw new ArgumentNullException ("value is null.");
164 return System.Convert.ToUInt32 (value);
167 [CLSCompliant (false)]
168 public ulong ToUInt64 (object value)
171 throw new ArgumentNullException ("value is null.");
173 return System.Convert.ToUInt64 (value);