using System;
using System.Collections;
+using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Xml;
ArrayList namespaces;
XmlWriter writer;
+#if MOONLIGHT
+ Queue<object> referencedElements;
+#else
Queue referencedElements;
+#endif
Hashtable callbacks;
Hashtable serializedObjects;
const string xmlNamespace = "http://www.w3.org/2000/xmlns/";
#region Properties
+#if MOONLIGHT
+ protected IList XmlNamespaces {
+ get { return namespaces; }
+ set { namespaces = (value as ArrayList); }
+ }
+#else
protected ArrayList Namespaces {
get { return namespaces; }
set { namespaces = value; }
}
+#endif
protected XmlWriter Writer {
get { return writer; }
Writer.WriteAttributeString (prefix, localName, ns, value);
}
+#if !MOONLIGHT
+ void WriteXmlNode (XmlNode node)
+ {
+ if (node is XmlDocument)
+ node = ((XmlDocument) node).DocumentElement;
+
+ node.WriteTo (Writer);
+ }
+
protected void WriteElementEncoded (XmlNode node, string name, string ns, bool isNullable, bool any)
{
if (name != string.Empty)
else
{
Writer.WriteStartElement (name, ns);
- node.WriteTo (Writer);
+ WriteXmlNode (node);
Writer.WriteEndElement ();
}
}
else
- node.WriteTo (Writer);
+ WriteXmlNode(node);
}
protected void WriteElementLiteral (XmlNode node, string name, string ns, bool isNullable, bool any)
else
{
Writer.WriteStartElement (name, ns);
- node.WriteTo (Writer);
+ WriteXmlNode (node);
Writer.WriteEndElement ();
}
}
else
- node.WriteTo (Writer);
+ WriteXmlNode (node);
}
+#endif
protected void WriteElementQualifiedName (string localName, XmlQualifiedName value)
{
{
if (ns == null)
return;
-
+#if MOONLIGHT
+ IEnumerable<XmlQualifiedName> namespaces = ns.GetNamespaces ();
+#else
ICollection namespaces = ns.Namespaces.Values;
+#endif
foreach (XmlQualifiedName qn in namespaces) {
if (qn.Namespace != String.Empty && Writer.LookupPrefix (qn.Namespace) != qn.Name)
WriteAttribute ("xmlns", qn.Name, xmlNamespace, qn.Namespace);
{
if (referencedElements == null)
{
+#if MOONLIGHT
+ referencedElements = new Queue<object> ();
+#else
referencedElements = new Queue ();
+#endif
InitCallbacks ();
}
}
}
protected void WriteSerializable (IXmlSerializable serializable, string name, string ns, bool isNullable)
+ {
+ WriteSerializable (serializable, name, ns, isNullable, true);
+ }
+
+#if NET_2_0
+ protected
+#endif
+ void WriteSerializable (IXmlSerializable serializable, string name, string ns, bool isNullable, bool wrapped)
{
if (serializable == null)
{
- if (isNullable) WriteNullTagLiteral (name, ns);
+ if (isNullable && wrapped) WriteNullTagLiteral (name, ns);
return;
}
else
{
- Writer.WriteStartElement (name, ns);
+ if (wrapped)
+ Writer.WriteStartElement (name, ns);
serializable.WriteXml (Writer);
- Writer.WriteEndElement ();
+ if (wrapped)
+ Writer.WriteEndElement ();
}
}
}
protected void WriteStartElement (string name, string ns, object o, bool writePrefixed)
+ {
+ WriteStartElement (name, ns, o, writePrefixed, namespaces);
+ }
+
+#if NET_2_0
+ protected void WriteStartElement (string name, string ns, Object o, bool writePrefixed, XmlSerializerNamespaces xmlns)
+ {
+ WriteStartElement (name, ns, o, writePrefixed, xmlns != null ? xmlns.ToArray () : null);
+ }
+#endif
+
+ void WriteStartElement (string name, string ns, object o, bool writePrefixed, ICollection namespaces)
{
if (o != null)
{
if (topLevelElement && ns != null && ns.Length != 0)
{
- foreach (XmlQualifiedName qn in namespaces)
- if (qn.Namespace == ns) {
- prefix = qn.Name;
- writePrefixed = true;
- break;
- }
+ if (namespaces != null)
+ foreach (XmlQualifiedName qn in namespaces)
+ if (qn.Namespace == ns) {
+ prefix = qn.Name;
+ writePrefixed = true;
+ break;
+ }
}
if (writePrefixed && ns != string.Empty)
string value;
TypeData td = TypeTranslator.GetTypeData (o.GetType ());
if (td.SchemaType != SchemaTypes.Primitive)
- throw new InvalidOperationException ("The type of the argument object is not primitive.");
+ throw new InvalidOperationException (String.Format ("The type of the argument object '{0}' is not primitive.", td.FullTypeName));
if (name == null) {
ns = td.IsXsdType ? XmlSchema.Namespace : XmlSerializer.WsdlTypesNamespace;
Writer.WriteString (value);
}
+#if !MOONLIGHT
protected void WriteXmlAttribute (XmlNode node)
{
WriteXmlAttribute (node, null);
WriteAttribute (attr.Prefix, attr.LocalName, attr.NamespaceURI, attr.Value);
}
+#endif
protected void WriteXsiType (string name, string ns)
{
#if NET_2_0
- [MonoTODO]
protected Exception CreateInvalidAnyTypeException (object o)
{
- throw new NotImplementedException ();
+ if (o == null)
+ return new InvalidOperationException ("null is invalid as anyType in XmlSerializer");
+ else
+ return CreateInvalidAnyTypeException (o.GetType ());
}
- [MonoTODO]
protected Exception CreateInvalidAnyTypeException (Type t)
{
- throw new NotImplementedException ();
+ return new InvalidOperationException (String.Format ("An object of type '{0}' is invalid as anyType in XmlSerializer", t));
}
protected Exception CreateInvalidEnumValueException (object value, string typeName)
throw new NotImplementedException ();
}
- [MonoTODO]
- protected void WriteSerializable (IXmlSerializable serializable, string name, string ns, bool isNullable, bool any)
- {
- throw new NotImplementedException ();
- }
-
[MonoTODO]
protected bool EscapeName
{