New tests.
[mono.git] / mcs / class / System.Runtime.Serialization / System.Runtime.Serialization / DataContractSerializer.cs
index 54b9028bfea5a96953bfef7bb48bafad7be48dd4..44ab29d185956a975080389b768dceec13228a0b 100644 (file)
@@ -55,6 +55,7 @@ namespace System.Runtime.Serialization
 
                int max_items = 0x10000; // FIXME: could be from config.
 
+               bool names_filled;
                XmlDictionaryString root_name, root_ns;
 
                public DataContractSerializer (Type type)
@@ -197,6 +198,7 @@ namespace System.Runtime.Serialization
                        XmlDictionary d = new XmlDictionary ();
                        root_name = d.Add (name);
                        root_ns = d.Add (ns);
+                       names_filled = true;
                }
 
                void Initialize (
@@ -235,10 +237,12 @@ namespace System.Runtime.Serialization
                        get { return preserve_refs; }
                }
 
-               [MonoTODO]
                public override bool IsStartObject (XmlDictionaryReader reader)
                {
-                       throw new NotImplementedException ();
+                       if (reader == null)
+                               throw new ArgumentNullException ("reader");
+                       reader.MoveToContent ();
+                       return reader.IsStartElement (root_name, root_ns);
                }
 
                // SP1
@@ -253,6 +257,11 @@ namespace System.Runtime.Serialization
                        return ReadObject (XmlDictionaryReader.CreateDictionaryReader (reader));
                }
 
+               public override object ReadObject (XmlReader reader, bool verifyObjectName)
+               {
+                       return ReadObject (XmlDictionaryReader.CreateDictionaryReader (reader), verifyObjectName);
+               }
+
                [MonoTODO]
                public override object ReadObject (XmlDictionaryReader reader, bool verifyObjectName)
                {
@@ -321,6 +330,12 @@ namespace System.Runtime.Serialization
                                known_types.RemoveAt (startTypeCount);
                }
 
+               public override void WriteObjectContent (XmlWriter writer, object graph)
+               {
+                       XmlDictionaryWriter w = XmlDictionaryWriter.CreateDictionaryWriter (writer);
+                       WriteObjectContent (w, graph);
+               }
+
                // SP1
                public override void WriteStartObject (
                        XmlWriter writer, object graph)
@@ -339,7 +354,10 @@ namespace System.Runtime.Serialization
 
 
                        if (graph == null) {
-                               writer.WriteStartElement (root_name.Value, root_ns.Value);
+                               if (names_filled)
+                                       writer.WriteStartElement (root_name.Value, root_ns.Value);
+                               else
+                                       writer.WriteStartElement (root_name, root_ns);
                                writer.WriteAttributeString ("i", "nil", XmlSchema.InstanceNamespace, "true");
                                return;
                        }
@@ -350,7 +368,10 @@ namespace System.Runtime.Serialization
 
                        known_types.Add (graph.GetType ());
 
-                       writer.WriteStartElement (root_name.Value, root_ns.Value);
+                       if (names_filled)
+                               writer.WriteStartElement (root_name.Value, root_ns.Value);
+                       else
+                               writer.WriteStartElement (root_name, root_ns);
                        if (root_ns.Value != root_qname.Namespace)
                                if (root_qname.Namespace != KnownTypeCollection.MSSimpleNamespace)
                                        writer.WriteXmlnsAttribute (null, root_qname.Namespace);