Author: lluis
Date: 2005-03-29 06:41:57 -0500 (Tue, 29 Mar 2005)
New Revision: 42328
Modified:
trunk/mcs/class/System.XML/System.Xml.Serialization/ChangeLog
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReader.cs
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriter.cs
Log:
2005-03-29 Lluis Sanchez Gual <[EMAIL PROTECTED]>
* XmlReflectionImporter.cs: Added support for subclasses of XmlNode.
This fixes bug #73901 and should fix #70384.
* XmlSerializationReader.cs: When reading an object element, return
an Object instance if the element has no children. This fixes bug
#73974.
* XmlSerializationWriter.cs: Support writing XmlNode[] as a primitive
type (it is written as an element with those nodes as children).
Modified: trunk/mcs/class/System.XML/System.Xml.Serialization/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/System.Xml.Serialization/ChangeLog
2005-03-29 09:20:57 UTC (rev 42327)
+++ trunk/mcs/class/System.XML/System.Xml.Serialization/ChangeLog
2005-03-29 11:41:57 UTC (rev 42328)
@@ -1,3 +1,12 @@
+2005-03-29 Lluis Sanchez Gual <[EMAIL PROTECTED]>
+
+ * XmlReflectionImporter.cs: Added support for subclasses of XmlNode.
+ This fixes bug #73901 and should fix #70384.
+ * XmlSerializationReader.cs: When reading an object element, return
+ an Object instance if the element has no children. This fixes bug
#73974.
+ * XmlSerializationWriter.cs: Support writing XmlNode[] as a primitive
+ type (it is written as an element with those nodes as children).
+
2005-03-08 Lluis Sanchez Gual <[EMAIL PROTECTED]>
* XmlSchemaImporter.cs: Support importing schemas that define
Modified:
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs
===================================================================
---
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs
2005-03-29 09:20:57 UTC (rev 42327)
+++
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs
2005-03-29 11:41:57 UTC (rev 42328)
@@ -492,31 +492,18 @@
XmlTypeMapping map = helper.GetRegisteredClrType (type,
GetTypeNamespace (TypeTranslator.GetTypeData (type), root, defaultNamespace));
if (map != null) return map;
- // Registers the maps for XmlNode and XmlElement
+ map = CreateTypeMapping (TypeTranslator.GetTypeData
(type), root, null, defaultNamespace);
+ helper.RegisterClrType (map, type,
map.XmlTypeNamespace);
+
+ if (type.BaseType != null)
+ {
+ XmlTypeMapping bmap = ImportTypeMapping
(type.BaseType, root, defaultNamespace);
+ if (type.BaseType != typeof (object))
+ map.BaseMap = bmap;
+
+ RegisterDerivedMap (bmap, map);
+ }
- XmlTypeMapping nodeMap = CreateTypeMapping
(TypeTranslator.GetTypeData (typeof(XmlNode)), root, null, defaultNamespace);
- helper.RegisterClrType (nodeMap, typeof(XmlNode),
nodeMap.XmlTypeNamespace);
-
- XmlTypeMapping elemMap = CreateTypeMapping
(TypeTranslator.GetTypeData (typeof(XmlElement)), root, null, defaultNamespace);
- helper.RegisterClrType (elemMap, typeof(XmlElement),
elemMap.XmlTypeNamespace);
-
- XmlTypeMapping textMap = CreateTypeMapping
(TypeTranslator.GetTypeData (typeof(XmlText)), root, null, defaultNamespace);
- helper.RegisterClrType (textMap, typeof(XmlText),
textMap.XmlTypeNamespace);
-
- XmlTypeMapping docMap = CreateTypeMapping
(TypeTranslator.GetTypeData (typeof(XmlDocument)), root, null,
defaultNamespace);
- helper.RegisterClrType (docMap, typeof(XmlDocument),
textMap.XmlTypeNamespace);
-
- XmlTypeMapping obmap = ImportTypeMapping
(typeof(object));
- obmap.DerivedTypes.Add (nodeMap);
- obmap.DerivedTypes.Add (elemMap);
- obmap.DerivedTypes.Add (textMap);
- obmap.DerivedTypes.Add (docMap);
- nodeMap.DerivedTypes.Add (elemMap);
- nodeMap.DerivedTypes.Add (textMap);
- nodeMap.DerivedTypes.Add (docMap);
-
- map = helper.GetRegisteredClrType (type,
GetTypeNamespace (TypeTranslator.GetTypeData (type), root, defaultNamespace));
- if (map == null) throw new InvalidOperationException
("Objects of type '" + type + "' can't be serialized");
return map;
}
Modified:
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReader.cs
===================================================================
---
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReader.cs
2005-03-29 09:20:57 UTC (rev 42327)
+++
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReader.cs
2005-03-29 11:41:57 UTC (rev 42328)
@@ -706,9 +706,13 @@
{
// Put everything into a node array
XmlNode node = Document.ReadNode (reader);
+
+ if (node.ChildNodes.Count == 0 &&
node.Attributes.Count == 0)
+ return new Object ();
+
XmlElement elem = node as XmlElement;
- if (elem == null)
+ if (elem == null)
return new XmlNode[] {node};
else {
XmlNode[] nodes = new
XmlNode[elem.Attributes.Count + elem.ChildNodes.Count];
Modified:
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriter.cs
===================================================================
---
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriter.cs
2005-03-29 09:20:57 UTC (rev 42327)
+++
trunk/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriter.cs
2005-03-29 11:41:57 UTC (rev 42328)
@@ -795,19 +795,25 @@
name = XmlCustomFormatter.FromXmlName (name);
Writer.WriteStartElement (name, ns);
- if (o is XmlQualifiedName)
- value = FromXmlQualifiedName
((XmlQualifiedName) o);
- else
- value = XmlCustomFormatter.ToXmlString (td, o);
+ if (o is XmlNode[]) {
+ foreach (XmlNode node in (XmlNode[])o)
+ node.WriteTo (Writer);
+ }
+ else {
+ if (o is XmlQualifiedName)
+ value = FromXmlQualifiedName
((XmlQualifiedName) o);
+ else
+ value = XmlCustomFormatter.ToXmlString
(td, o);
- if (xsiType)
- {
- if (td.SchemaType != SchemaTypes.Primitive)
- throw new InvalidOperationException
(string.Format (unexpectedTypeError, o.GetType().FullName));
- WriteXsiType (td.XmlType, XmlSchema.Namespace);
+ if (xsiType)
+ {
+ if (td.SchemaType !=
SchemaTypes.Primitive)
+ throw new
InvalidOperationException (string.Format (unexpectedTypeError,
o.GetType().FullName));
+ WriteXsiType (td.XmlType,
XmlSchema.Namespace);
+ }
+
+ WriteValue (value);
}
-
- WriteValue (value);
Writer.WriteEndElement ();
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches