* SerializationCodeGenerator.cs: Generate check that the object being
authorLluis Sanchez <lluis@novell.com>
Fri, 2 Jul 2004 13:59:56 +0000 (13:59 -0000)
committerLluis Sanchez <lluis@novell.com>
Fri, 2 Jul 2004 13:59:56 +0000 (13:59 -0000)
  serialized has a known type. Little cast fix.
* XmlCustomFormatter.cs: Little fix in Single conversion.

svn path=/trunk/mcs/; revision=30669

mcs/class/System.XML/System.Xml.Serialization/ChangeLog
mcs/class/System.XML/System.Xml.Serialization/SerializationCodeGenerator.cs
mcs/class/System.XML/System.Xml.Serialization/XmlCustomFormatter.cs

index 078d3600482b606687fd8811554a110ac194a0c7..71e2fe486ebb9ed2dca964baa1aaf91e8f3b8749 100755 (executable)
@@ -1,3 +1,9 @@
+2004-07-02  Lluis Sanchez Gual  <lluis@ximian.com>
+
+       * SerializationCodeGenerator.cs: Generate check that the object being 
+         serialized has a known type. Little cast fix.
+       * XmlCustomFormatter.cs: Little fix in Single conversion.
+
 2004-07-01  Lluis Sanchez Gual  <lluis@ximian.com>
 
        * TypeData.cs: In the constructor, set the correct xml type name if the
index beeeb6de7c22b197622748a36f6ea3ccbfc11cc3..d7f939f7c71a403961e5fd37e0bddd76f5e500b4 100644 (file)
@@ -463,16 +463,19 @@ namespace System.Xml.Serialization
                        }
 
                        ArrayList types = typeMap.DerivedTypes;
-                       bool first = true;
+                       
+                       WriteLine ("System.Type type = ob.GetType ();");
+                       WriteLine ("if (type == typeof(" + typeMap.TypeFullName + "))");
+                       WriteLine ("\t;");
+                               
                        for (int n=0; n<types.Count; n++)
                        {
                                XmlTypeMapping map = (XmlTypeMapping)types[n];
                                
-                               WriteLineInd ((first?"else ":"") + "if (ob is " + map.TypeFullName + ") { ");
+                               WriteLineInd ("else if (type == typeof(" + map.TypeFullName + ")) { ");
                                WriteLine (GetWriteObjectName (map) + "((" + map.TypeFullName + ")ob, element, namesp, isNullable, true, writeWrappingElem);");
                                WriteLine ("return;");
                                WriteLineUni ("}");
-                               first = false;
                        }
                        
                        if (typeMap.TypeData.Type == typeof (object)) {
@@ -483,8 +486,10 @@ namespace System.Xml.Serialization
                        }
                        else
                        {
-                               if (types.Count > 0)
-                                       WriteLine ("");
+                               WriteLineInd ("else {");
+                               WriteLine ("throw CreateUnknownTypeException (ob);");
+                               WriteLineUni ("}");
+                               WriteLine ("");
                                
                                WriteLineInd ("if (writeWrappingElem) {");
                                if (_format == SerializationFormat.Encoded) WriteLine ("needType = true;");
@@ -1947,7 +1952,7 @@ namespace System.Xml.Serialization
 
                                WriteLine (td.FullTypeName + " dest = (" + td.FullTypeName + ") list;");
                                WriteLine ("foreach (object ob in (IEnumerable)source)");
-                               WriteLine ("\t dest.Add (ob);");
+                               WriteLine ("\tdest.Add (" + GetCast (td.ListItemTypeData, "ob") + ");");
                                WriteLineUni ("}");
                                WriteLine ("");
                        }
index 17514268a90ffcfa350575ad16fb34b1e0bfddee..b00a8691ca9dae6df7b834cb06dbe25e9dad6b70 100644 (file)
@@ -285,7 +285,7 @@ namespace System.Xml.Serialization {
                                case "int": return "Int32.Parse (" + value + ", CultureInfo.InvariantCulture)";
                                case "long": return "Int64.Parse (" + value + ", CultureInfo.InvariantCulture)";
                                case "byte": return "SByte.Parse (" + value + ", CultureInfo.InvariantCulture)";
-                               case "float": return "XmlConvert.ToSingle (" + value + ", CultureInfo.InvariantCulture)";
+                               case "float": return "XmlConvert.ToSingle (" + value + ")";
                                case "unsignedShort": return "UInt16.Parse (" + value + ", CultureInfo.InvariantCulture)";
                                case "unsignedInt": return "UInt32.Parse (" + value + ", CultureInfo.InvariantCulture)";
                                case "unsignedLong": return "UInt64.Parse (" + value + ", CultureInfo.InvariantCulture)";