2003-04-25 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
[mono.git] / mcs / class / System.XML / System.Xml.Serialization / TypeTranslator.cs
1 //
2 // System.Xml.Serialization.TypeTranslator
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //      Erik LeBel (eriklebel@yahoo.ca)
7 //
8 // (C) 2002 Ximian, Inc (http://www.ximian.com)
9 // (C) 2003 Erik Lebel
10 //
11
12 using System;
13 using System.Collections;
14
15 namespace System.Xml.Serialization
16 {
17         internal class TypeTranslator
18         {
19                 static Hashtable primitives;
20
21                 static TypeTranslator ()
22                 {
23                         primitives = new Hashtable ();
24                         primitives.Add (typeof (bool), "boolean");
25                         primitives.Add (typeof (short), "short");
26                         primitives.Add (typeof (ushort), "unsignedShort");
27                         primitives.Add (typeof (int), "int");
28                         primitives.Add (typeof (uint), "unsignedInt");
29                         primitives.Add (typeof (long), "long");
30                         primitives.Add (typeof (ulong), "unsignedLong");
31                         primitives.Add (typeof (float), "float");
32                         primitives.Add (typeof (double), "double");
33                         primitives.Add (typeof (DateTime), "dateTime"); // TODO: timeInstant, Xml date, xml time
34                         primitives.Add (typeof (Guid), "guid");
35                         primitives.Add (typeof (Decimal), "decimal");
36                         primitives.Add (typeof (XmlQualifiedName), "QName");
37                         primitives.Add (typeof (string), "string");
38                         primitives.Add (typeof (byte), "unsignedByte");
39                         primitives.Add (typeof (sbyte), "byte");
40                         primitives.Add (typeof (char), "char");
41                         primitives.Add (typeof (object), "anyType");
42                         primitives.Add (typeof (byte[]), "base64Binary");
43                 }
44
45                 private TypeTranslator ()
46                 {
47                 }
48
49                 static public TypeData GetTypeData (Type type)
50                 {
51                         string name = primitives [type] as string;
52                         if (name == null && type.IsArray) {
53                                 name = primitives [type.GetElementType ()] as string;
54                                 if (name != null)
55                                         name = "ArrayOf" + Char.ToUpper (name [0]) + name.Substring (1);
56                         }
57                         
58                         return new TypeData (type, (name == null) ? type.Name : name, name != null);
59                 }
60         }
61 }
62