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 [System.Runtime.InteropServices.ComVisibleAttribute (true)]
37 public class FormatterConverter : IFormatterConverter {
39 public FormatterConverter ()
43 public object Convert (object value, Type type)
45 return System.Convert.ChangeType (value, type);
48 public object Convert (object value, TypeCode typeCode)
50 return System.Convert.ChangeType (value, typeCode);
53 public bool ToBoolean (object value)
56 throw new ArgumentNullException ("value is null.");
58 return System.Convert.ToBoolean (value);
61 public byte ToByte (object value)
64 throw new ArgumentNullException ("value is null.");
66 return System.Convert.ToByte (value);
69 public char ToChar (object value)
72 throw new ArgumentNullException ("value is null.");
74 return System.Convert.ToChar (value);
77 public DateTime ToDateTime (object value)
80 throw new ArgumentNullException ("value is null.");
82 return System.Convert.ToDateTime (value);
85 public decimal ToDecimal (object value)
88 throw new ArgumentNullException ("value is null.");
90 return System.Convert.ToDecimal (value);
93 public double ToDouble (object value)
96 throw new ArgumentNullException ("value is null.");
98 return System.Convert.ToDouble (value);
101 public short ToInt16 (object value)
104 throw new ArgumentNullException ("value is null.");
106 return System.Convert.ToInt16 (value);
109 public int ToInt32 (object value)
112 throw new ArgumentNullException ("value is null.");
114 return System.Convert.ToInt32 (value);
117 public long ToInt64 (object value)
120 throw new ArgumentNullException ("value is null.");
122 return System.Convert.ToInt64 (value);
125 public float ToSingle (object value)
128 throw new ArgumentNullException ("value is null.");
130 return System.Convert.ToSingle (value);
133 public string ToString (object value)
136 throw new ArgumentNullException ("value is null.");
138 return System.Convert.ToString (value);
141 [CLSCompliant (false)]
142 public sbyte ToSByte (object value)
145 throw new ArgumentNullException ("value is null.");
147 return System.Convert.ToSByte (value);
150 [CLSCompliant (false)]
151 public ushort ToUInt16 (object value)
154 throw new ArgumentNullException ("value is null.");
156 return System.Convert.ToUInt16 (value);
159 [CLSCompliant (false)]
160 public uint ToUInt32 (object value)
163 throw new ArgumentNullException ("value is null.");
165 return System.Convert.ToUInt32 (value);
168 [CLSCompliant (false)]
169 public ulong ToUInt64 (object value)
172 throw new ArgumentNullException ("value is null.");
174 return System.Convert.ToUInt64 (value);