using System.IO;
using System.Text;
using System.Xml;
+using System.Data;
using System.Xml.Schema;
using System.Xml.Serialization;
#if NET_2_0
Assert.AreEqual (Infoset ("<ReadOnlyProperties xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText);
}
+ [Test]
+ public void TestSerializeReadOnlyListProp ()
+ {
+ ReadOnlyListProperty ts = new ReadOnlyListProperty ();
+ Serialize (ts);
+ Assert.AreEqual (Infoset ("<ReadOnlyListProperty xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><StrList><string>listString1</string><string>listString2</string></StrList></ReadOnlyListProperty>"), WriterText);
+ }
+
+
[Test]
public void TestSerializeIList ()
{
ser.Deserialize (new XmlTextReader (xml, XmlNodeType.Document, null));
}
-#if NET_2_0
-#if !TARGET_JVM
+#if !TARGET_JVM && !MOBILE
[Test]
public void GenerateSerializerGenerics ()
{
Assert.AreEqual (TestEnumWithNulls.bb, w.nenum.Value);
Assert.AreEqual (t, w.ndate.Value);
}
-#endif
[Test]
public void SerializeBase64Binary()
Assert.AreEqual (Infoset (xml), WriterText);
xs.Deserialize (new StringReader (xml));
}
+
+ [Test]
+ public void XmlAnyElementForObjects () // bug #553032
+ {
+ new XmlSerializer (typeof (XmlAnyElementForObjectsType));
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void XmlAnyElementForObjects2 () // bug #553032-2
+ {
+ new XmlSerializer (typeof (XmlAnyElementForObjectsType)).Serialize (TextWriter.Null, new XmlAnyElementForObjectsType ());
+ }
+
+
+ public class Bug2893 {
+ public Bug2893 ()
+ {
+ Contents = new XmlDataDocument();
+ }
+
+ [XmlAnyElement("Contents")]
+ public XmlNode Contents;
+ }
+
+ // Bug Xamarin #2893
+ [Test]
+ public void XmlAnyElementForXmlNode ()
+ {
+ var obj = new Bug2893 ();
+ XmlSerializer mySerializer = new XmlSerializer(typeof(Bug2893));
+ XmlWriterSettings settings = new XmlWriterSettings();
+
+ var xsn = new XmlSerializerNamespaces();
+ xsn.Add(string.Empty, string.Empty);
+
+ byte[] buffer = new byte[2048];
+ var ms = new MemoryStream(buffer);
+ using (var xw = XmlWriter.Create(ms, settings))
+ {
+ mySerializer.Serialize(xw, obj, xsn);
+ xw.Flush();
+ }
+
+ mySerializer.Serialize(ms, obj);
+ }
+
+ [Test]
+ public void XmlRootOverridesSchemaProviderQName ()
+ {
+ var obj = new XmlRootOverridesSchemaProviderQNameType ();
+
+ XmlSerializer xs = new XmlSerializer (obj.GetType ());
+
+ var sw = new StringWriter ();
+ using (XmlWriter xw = XmlWriter.Create (sw))
+ xs.Serialize (xw, obj);
+ Assert.IsTrue (sw.ToString ().IndexOf ("foo") > 0, "#1");
+ }
+
+ public class AnotherArrayListType
+ {
+ [XmlAttribute]
+ public string one = "aaa";
+ [XmlAttribute]
+ public string another = "bbb";
+ }
+
+ public class DerivedArrayListType : AnotherArrayListType
+ {
+
+ }
+
+ public class ClassWithArrayList
+ {
+ [XmlElement (Type = typeof(int), ElementName = "int_elem")]
+ [XmlElement (Type = typeof(string), ElementName = "string_elem")]
+ [XmlElement (Type = typeof(AnotherArrayListType), ElementName = "another_elem")]
+ [XmlElement (Type = typeof(DerivedArrayListType), ElementName = "derived_elem")]
+ public ArrayList list;
+ }
+
+ public class ClassWithArray
+ {
+ [XmlElement (Type = typeof(int), ElementName = "int_elem")]
+ [XmlElement (Type = typeof(string), ElementName = "string_elem")]
+ [XmlElement (Type = typeof(AnotherArrayListType), ElementName = "another_elem")]
+ [XmlElement (Type = typeof(DerivedArrayListType), ElementName = "derived_elem")]
+ public object[] list;
+
+ }
+
+ [Test]
+ public void MultipleXmlElementAttributesOnArrayList()
+ {
+ var test = new ClassWithArrayList();
+
+ test.list = new ArrayList();
+ test.list.Add(3);
+ test.list.Add("apepe");
+ test.list.Add(new AnotherArrayListType());
+ test.list.Add(new DerivedArrayListType());
+
+ Serialize(test);
+ var expected_text = "<:ClassWithArrayList http://www.w3.org/2000/xmlns/:xsd='http://www.w3.org/2001/XMLSchema' http://www.w3.org/2000/xmlns/:xsi='http://www.w3.org/2001/XMLSchema-instance'><:int_elem>3</><:string_elem>apepe</><:another_elem :another='bbb' :one='aaa'></><:derived_elem :another='bbb' :one='aaa'></></>";
+
+ Assert.AreEqual(WriterText, expected_text, WriterText);
+ }
+
+ [Test]
+ public void MultipleXmlElementAttributesOnArray()
+ {
+ var test = new ClassWithArray();
+
+ test.list = new object[] { 3, "apepe", new AnotherArrayListType(), new DerivedArrayListType() };
+
+ Serialize(test);
+ var expected_text = "<:ClassWithArray http://www.w3.org/2000/xmlns/:xsd='http://www.w3.org/2001/XMLSchema' http://www.w3.org/2000/xmlns/:xsi='http://www.w3.org/2001/XMLSchema-instance'><:int_elem>3</><:string_elem>apepe</><:another_elem :another='bbb' :one='aaa'></><:derived_elem :another='bbb' :one='aaa'></></>";
+
+ Assert.AreEqual(WriterText, expected_text, WriterText);
+ }
+
#endif
#endregion //GenericsSeralizationTests
[XmlArrayItem (typeof (XmlSchemaProviderQNameBecomesRootNameType))]
public object [] Foo = new object [] {new XmlSchemaProviderQNameBecomesRootNameType ()};
}
+
+ public class XmlAnyElementForObjectsType
+ {
+ [XmlAnyElement]
+ public object [] arr = new object [] {3,4,5};
+ }
+
+ [XmlRoot ("foo")]
+ [XmlSchemaProvider ("GetSchema")]
+ public class XmlRootOverridesSchemaProviderQNameType : IXmlSerializable
+ {
+ public static XmlQualifiedName GetSchema (XmlSchemaSet xss)
+ {
+ var xs = new XmlSchema ();
+ var xse = new XmlSchemaComplexType () { Name = "bar" };
+ xs.Items.Add (xse);
+ xss.Add (xs);
+ return new XmlQualifiedName ("bar");
+ }
+
+ XmlSchema IXmlSerializable.GetSchema ()
+ {
+ return null;
+ }
+
+ void IXmlSerializable.ReadXml (XmlReader reader)
+ {
+ }
+ void IXmlSerializable.WriteXml (XmlWriter writer)
+ {
+ }
+ }
+
#endif
void CDataTextNodes_BadNode (object s, XmlNodeEventArgs e)