using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Data;
using System.IO;
+using System.Linq;
using System.Net;
using System.Runtime.Serialization;
using System.Text;
using System.Xml;
-using NUnit.Framework;
-using System.Xml.Serialization;
using System.Xml.Schema;
+using System.Xml.Serialization;
+using NUnit.Framework;
+
+[assembly: ContractNamespace ("http://www.u2u.be/samples/wcf/2009", ClrNamespace = "U2U.DataContracts")] // bug #599889
namespace MonoTests.System.Runtime.Serialization
{
[Test]
public void ConstructorKnownTypesNull ()
{
- // null knownTypes is allowed.
- new DataContractSerializer (typeof (Sample1), null);
- new DataContractSerializer (typeof (Sample1), "Foo", String.Empty, null);
- new DataContractSerializer (typeof (Sample1), new XmlDictionary ().Add ("Foo"), XmlDictionaryString.Empty, null);
+ // null knownTypes is allowed. Though the property is filled.
+ Assert.IsNotNull (new DataContractSerializer (typeof (Sample1), (IEnumerable<Type>)null).KnownTypes, "#1");
+ Assert.IsNotNull (new DataContractSerializer (typeof (Sample1), "Foo", String.Empty, null).KnownTypes, "#2");
+ Assert.IsNotNull (new DataContractSerializer (typeof (Sample1), new XmlDictionary ().Add ("Foo"), XmlDictionaryString.Empty, null).KnownTypes, "#3");
}
[Test]
ser.WriteObject (sw, 1);
string expected = "<int xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">1</int>";
byte[] buf = sw.ToArray ();
- Assert.AreEqual (expected, Encoding.UTF8.GetString (buf, 0, buf.Length));
+ // Skip the utf8 bom
+ Assert.AreEqual (expected, Encoding.UTF8.GetString (buf, 3, buf.Length - 3));
}
[Test]
Assert.AreEqual (expected, sw.ToString ());
}
+ // DCEmpty
+
+ [Test]
+ public void SerializeEmptyNoNSClass ()
+ {
+ var ser = new DataContractSerializer (typeof (DCEmptyNoNS));
+ SerializeEmptyNoNSClass (ser, "<DCEmptyNoNS xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" />");
+ }
+
+ void SerializeEmptyNoNSClass (XmlObjectSerializer ser, string expected)
+ {
+ var sw = new StringWriter ();
+ using (var w = XmlWriter.Create (sw, settings)) {
+ ser.WriteObject (w, new DCEmptyNoNS ());
+ }
+ Assert.AreEqual (expected, sw.ToString ());
+ }
// string (primitive)
[Test]
[Test]
[ExpectedException (typeof (SerializationException))]
- [Category ("NotWorking")] // behavior changed in 3.5/SP1
public void SerializeSimpleXml ()
{
DataContractSerializer ser =
using (XmlWriter xw = XmlWriter.Create (sw, settings)) {
ser.WriteObject (xw, new SerializeNonDCArrayType ());
}
- Assert.AreEqual (@"<SerializeNonDCArrayType xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"" xmlns=""http://schemas.datacontract.org/2004/07/MonoTests.System.Runtime.Serialization""><IPAddresses xmlns:d2p1=""http://schemas.datacontract.org/2004/07/System.Net"" /></SerializeNonDCArrayType>",
+ Assert.AreEqual (@"<SerializeNonDCArrayType xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"" xmlns=""http://schemas.datacontract.org/2004/07/MonoTests.System.Runtime.Serialization""><IPAddresses /></SerializeNonDCArrayType>",
sw.ToString ());
}
StringWriter sw = new StringWriter ();
using (XmlWriter xw = XmlWriter.Create (sw, settings)) {
SerializeNonDCArrayType obj = new SerializeNonDCArrayType ();
- obj.IPAddresses = new IPAddress [] {new IPAddress (new byte [] {1, 2, 3, 4})};
+ obj.IPAddresses = new NonDCItem [] {new NonDCItem () { Data = new int [] {1, 2, 3, 4} } };
ser.WriteObject (xw, obj);
}
nsmgr.AddNamespace ("n", "http://schemas.datacontract.org/2004/07/System.Net");
nsmgr.AddNamespace ("a", "http://schemas.microsoft.com/2003/10/Serialization/Arrays");
- Assert.AreEqual (1, doc.SelectNodes ("/s:SerializeNonDCArrayType/s:IPAddresses/n:IPAddress", nsmgr).Count, "#1");
- Assert.AreEqual ("67305985", doc.SelectSingleNode ("/s:SerializeNonDCArrayType/s:IPAddresses/n:IPAddress/n:m_Address", nsmgr).InnerText, "#2");
- XmlElement el = doc.SelectSingleNode ("/s:SerializeNonDCArrayType/s:IPAddresses/n:IPAddress/n:m_Numbers", nsmgr) as XmlElement;
+ Assert.AreEqual (1, doc.SelectNodes ("/s:SerializeNonDCArrayType/s:IPAddresses/s:NonDCItem", nsmgr).Count, "#1");
+ XmlElement el = doc.SelectSingleNode ("/s:SerializeNonDCArrayType/s:IPAddresses/s:NonDCItem/s:Data", nsmgr) as XmlElement;
Assert.IsNotNull (el, "#3");
- Assert.AreEqual (8, el.SelectNodes ("a:unsignedShort", nsmgr).Count, "#4");
+ Assert.AreEqual (4, el.SelectNodes ("a:int", nsmgr).Count, "#4");
+ }
+
+ [Test]
+ public void SerializeArrayOfAnyTypeGuid ()
+ {
+ DataContractSerializer ser = new DataContractSerializer (typeof(object[]));
+ StringWriter sw = new StringWriter ();
+ using (XmlWriter w = XmlWriter.Create (sw, settings)) {
+ ser.WriteObject (w, new object[] { Guid.Empty });
+ }
+
+ XmlComparer.AssertAreEqual (
+ "<ArrayOfanyType xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\"><anyType xmlns:d2p1=\"http://schemas.microsoft.com/2003/10/Serialization/\" i:type=\"d2p1:guid\">00000000-0000-0000-0000-000000000000</anyType></ArrayOfanyType>",
+ sw.ToString ());
+ }
+
+ [Test]
+ public void SerializeArrayOfAnyTypeChar ()
+ {
+ DataContractSerializer ser = new DataContractSerializer (typeof(object[]));
+ StringWriter sw = new StringWriter ();
+ using (XmlWriter w = XmlWriter.Create (sw, settings)) {
+ ser.WriteObject (w, new object[] { new char () });
+ }
+
+ XmlComparer.AssertAreEqual (
+ "<ArrayOfanyType xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\"><anyType xmlns:d2p1=\"http://schemas.microsoft.com/2003/10/Serialization/\" i:type=\"d2p1:char\">0</anyType></ArrayOfanyType>",
+ sw.ToString ());
}
[Test]
}
[Test]
- [Category ("NotWorking")]
public void DeserializeDCWithNullableEnum ()
{
DCWithNullableEnum dc = Deserialize<DCWithNullableEnum> (
new DataContractSerializer(typeof (AsxEntryInfo)).ReadObject (reader);
}
+ [Test]
+ public void Bug539563 ()
+ {
+ new DataContractSerializer (typeof (NestedContractType));
+ }
+
+ [Test]
+ public void Bug560155 ()
+ {
+ var g = Guid.NewGuid ();
+ Person p1 = new Person ("UserName", g);
+ Assert.AreEqual ("name=UserName,id=" + g, p1.ToString (), "#1");
+ MemoryStream memStream = new MemoryStream ();
+ DataContractSerializer ser = new DataContractSerializer (typeof (Person));
+
+ ser.WriteObject (memStream, p1);
+ memStream.Seek (0, SeekOrigin.Begin);
+ Person p2 = (Person) ser.ReadObject (memStream);
+ Assert.AreEqual ("name=UserName,id=" + g, p2.ToString (), "#1");
+ }
+
private T Deserialize<T> (string xml)
{
return Deserialize<T> (xml, typeof (T));
}
Assert.AreEqual (@"<MemberIgnored xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"" xmlns=""http://schemas.datacontract.org/2004/07/MonoTests.System.Runtime.Serialization""><body><Bar>bar</Bar></body></MemberIgnored>", sw.ToString (), "#1");
}
- }
+ [Test]
+ public void DeserializeEmptyArray ()
+ {
+ var ds = new DataContractSerializer (typeof (string []));
+ var sw = new StringWriter ();
+ var xw = XmlWriter.Create (sw);
+ ds.WriteObject (xw, new string [] {});
+ xw.Close ();
+ Console.WriteLine (sw.ToString ());
+ var sr = new StringReader (sw.ToString ());
+ var xr = XmlReader.Create (sr);
+ var ret = ds.ReadObject (xr);
+ Assert.AreEqual (typeof (string []), ret.GetType (), "#1");
+ }
+
+ [Test]
+ public void ContractNamespaceAttribute ()
+ {
+ var ds = new DataContractSerializer (typeof (U2U.DataContracts.Person));
+ string xml = "<?xml version='1.0' encoding='utf-16'?><Person xmlns:i='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://www.u2u.be/samples/wcf/2009'><Name>Rupert</Name><Occupation><Description>Monkey</Description></Occupation></Person>";
+ var person = new U2U.DataContracts.Person () {
+ Name = "Rupert",
+ Occupation = new U2U.DataContracts.Job () { Description = "Monkey" }
+ };
+ var sw = new StringWriter ();
+ using (var xw = XmlWriter.Create (sw))
+ ds.WriteObject (xw, person);
+ Assert.AreEqual (xml, sw.ToString ().Replace ('"', '\''), "#1");
+ }
+
+ [Test]
+ public void Bug610036 ()
+ {
+ var ms = new MemoryStream ();
+ Type [] knownTypes = new Type [] { typeof (ParentClass), typeof (Foo), typeof (Bar) };
+
+ var ds = new DataContractSerializer (typeof (Root), "Root", "Company.Foo", knownTypes, 1000, false, true, null);
+
+ var root = new Root ("root");
+ var bar1 = new Bar ("bar1");
+ var bar2 = new Bar ("bar2");
+ var bar3 = new Bar ("bar3");
+
+ var foo1 = new Foo ("foo1");
+ var foo2 = new Foo ("foo2");
+
+ foo1.FDict.Add (bar1);
+ foo1.FDict.Add (bar2);
+
+ foo2.FDict.Add (bar1);
+ foo2.FDict.Add (bar3);
+
+ root.FDict.Add (foo1);
+ root.FDict.Add (foo2);
+
+ ds.WriteObject (ms, root);
+ string result = Encoding.UTF8.GetString (ms.ToArray ());
+ ms.Position = 0;
+
+ root = (Root) ds.ReadObject (ms);
+
+ Assert.AreEqual (2, root.FDict.Count, "#1");
+ int idx = result.IndexOf ("foo1");
+ Assert.IsTrue (idx >= 0, "#2");
+ // since "foo1" is stored as z:Ref for string, it must not occur twice.
+ int idx2 = result.IndexOf ("foo1", idx + 1);
+ Assert.IsTrue (idx2 < 0, "idx2 should not occur at " + idx2);
+ }
+
+ [Test]
+ public void AncestralReference ()
+ {
+ // Reference to Parent comes inside the Parent itself.
+ // In this case, adding reference after complete deserialization won't work (but it should).
+ var ms = new MemoryStream ();
+ Type [] knownTypes = new Type [] { typeof (ParentClass), typeof (Foo), typeof (Bar) };
+
+ var ds = new DataContractSerializer (typeof (Parent));
+
+ var org = new Parent ();
+ ds.WriteObject (ms, org);
+ string result = Encoding.UTF8.GetString (ms.ToArray ());
+ ms.Position = 0;
+
+ var parent = (Parent) ds.ReadObject (ms);
+
+ Assert.IsNotNull (parent.Child, "#1");
+ Assert.AreEqual (parent, parent.Child.Parent, "#2");
+ }
+
+ [Test]
+ public void IXmlSerializableCallConstructor ()
+ {
+ IXmlSerializableCallConstructor (false);
+ IXmlSerializableCallConstructor (true);
+ }
+
+ void IXmlSerializableCallConstructor (bool binary)
+ {
+ Stream s = IXmlSerializableCallConstructorSerialize (binary);
+ var a = new byte [s.Length];
+ s.Position = 0;
+ s.Read (a, 0, a.Length);
+ s.Position = 0;
+ IXmlSerializableCallConstructorDeserialize (s, binary);
+ }
+
+ public Stream IXmlSerializableCallConstructorSerialize (bool binary)
+ {
+ var ds = new DataSet ("ds");
+ var dt = new DataTable ("dt");
+ ds.Tables.Add (dt);
+ dt.Columns.Add ("n", typeof (int));
+ dt.Columns.Add ("s", typeof (string));
+
+ dt.Rows.Add (5, "five");
+ dt.Rows.Add (10, "ten");
+
+ ds.AcceptChanges ();
+
+ var s = new MemoryStream ();
+
+ var w = binary ? XmlDictionaryWriter.CreateBinaryWriter (s) : XmlDictionaryWriter.CreateTextWriter (s);
+
+ var x = new DataContractSerializer (typeof (DataSet));
+ x.WriteObject (w, ds);
+ w.Flush ();
+
+ return s;
+ }
+
+ public void IXmlSerializableCallConstructorDeserialize (Stream s, bool binary)
+ {
+ var r = binary ? XmlDictionaryReader.CreateBinaryReader (s, XmlDictionaryReaderQuotas.Max)
+ : XmlDictionaryReader.CreateTextReader (s, XmlDictionaryReaderQuotas.Max);
+
+ var x = new DataContractSerializer (typeof (DataSet));
+
+ var ds = (DataSet) x.ReadObject (r);
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidDataContractException))] // BaseConstraintType1 is neither DataContract nor Serializable.
+ public void BaseConstraint1 ()
+ {
+ new DataContractSerializer (typeof (BaseConstraintType3)).WriteObject (XmlWriter.Create (TextWriter.Null), new BaseConstraintType3 ());
+ }
+
+ [Test]
+ public void BaseConstraint2 ()
+ {
+ new DataContractSerializer (typeof (BaseConstraintType4)).WriteObject (XmlWriter.Create (TextWriter.Null), new BaseConstraintType4 ());
+ }
+
+ [Test] // bug #652331
+ public void MembersNamespacesInBaseType ()
+ {
+ string xml1 = @"<Currency>JPY</Currency><Description i:nil=""true"" />";
+ string xml2 = @"<Currency xmlns=""http://schemas.datacontract.org/2004/07/SLProto5"">JPY</Currency><Description i:nil=""true"" xmlns=""http://schemas.datacontract.org/2004/07/SLProto5"" />";
+ Assert.AreEqual ("JPY", MembersNamespacesInBaseType_Part<SLProto5.CashAmount> (new SLProto5.CashAmount () { Currency = "JPY" }, xml1, "#1").Currency, "r#1");
+ Assert.AreEqual ("JPY", MembersNamespacesInBaseType_Part<SLProto5_Different.CashAmount> (new SLProto5_Different.CashAmount () { Currency = "JPY" }, xml2, "#2").Currency, "r#2");
+ Assert.AreEqual ("JPY", MembersNamespacesInBaseType_Part<SLProto5.CashAmountDC> (new SLProto5.CashAmountDC () { Currency = "JPY" }, xml1, "#3").Currency, "r#3");
+ Assert.AreEqual ("JPY", MembersNamespacesInBaseType_Part<SLProto5_Different.CashAmountDC> (new SLProto5_Different.CashAmountDC () { Currency = "JPY" }, xml2, "#4").Currency, "r#4");
+ }
+
+ T MembersNamespacesInBaseType_Part<T> (T instance, string expectedPart, string assert)
+ {
+ var ds = new DataContractSerializer (typeof (T));
+ var sw = new StringWriter ();
+ using (var w = XmlWriter.Create (sw))
+ ds.WriteObject (w, instance);
+ Assert.IsTrue (sw.ToString ().IndexOf (expectedPart) > 0, assert);
+ return (T) ds.ReadObject (XmlReader.Create (new StringReader (sw.ToString ())));
+ }
+
+ [Test]
+ public void DateTimeOffsetSerialization ()
+ {
+ var ds = new DataContractSerializer (typeof (DateTimeOffset));
+ var sw = new StringWriter ();
+ string xml = "<DateTimeOffset xmlns:i='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://schemas.datacontract.org/2004/07/System'><DateTime>2011-03-01T02:05:06.078Z</DateTime><OffsetMinutes>120</OffsetMinutes></DateTimeOffset>".Replace ('\'', '"');
+
+ var v = new DateTimeOffset (new DateTime (2011, 3, 1, 4, 5, 6, 78), TimeSpan.FromMinutes (120));
+ using (var xw = XmlWriter.Create (sw, settings)) {
+ ds.WriteObject (xw, v);
+ }
+ Assert.AreEqual (xml, sw.ToString (), "#1");
+ Assert.AreEqual (v, ds.ReadObject (XmlReader.Create (new StringReader (sw.ToString ()))), "#2");
+ }
+
+ [Test]
+ public void DateTimeOffsetNullableSerialization ()
+ {
+ var ds = new DataContractSerializer (typeof (DateTimeOffset?));
+ var sw = new StringWriter ();
+ string xml = "<DateTimeOffset xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.datacontract.org/2004/07/System\"><DateTime>2012-05-04T00:34:00Z</DateTime><OffsetMinutes>120</OffsetMinutes></DateTimeOffset>";
+
+ var v = new DateTimeOffset (new DateTime (2012, 05, 04, 02, 34, 0), TimeSpan.FromMinutes (120));
+ using (var xw = XmlWriter.Create (sw, settings)) {
+ ds.WriteObject (xw, v);
+ }
+ Assert.AreEqual (xml, sw.ToString (), "#1");
+ Assert.AreEqual (v, ds.ReadObject (XmlReader.Create (new StringReader (sw.ToString ()))), "#2");
+ }
+
+ [Test]
+ public void XmlDocumentSupport ()
+ {
+ var xml = "<XmlDocumentContract xmlns:i='http://www.w3.org/2001/XMLSchema-instance' xmlns='urn:foo'><Content><Root xmlns=''>Hello, world!</Root></Content><Nodes><child1 xmlns='' /><child2 xmlns='' /></Nodes></XmlDocumentContract>".Replace ('\'', '"');
+ var xml2 = "<Root>Hello, world!</Root>";
+ var obj = new XmlDocumentContract ();
+ var doc = new XmlDocument ();
+ doc.LoadXml (xml2);
+ obj.Content = doc.DocumentElement;
+ doc = new XmlDocument ();
+ doc.LoadXml ("<root><child1/><child2/></root>");
+ var l = new List<XmlNode> ();
+ foreach (XmlNode node in doc.DocumentElement.ChildNodes)
+ l.Add (node);
+ obj.Nodes = l.ToArray ();
+ var serializer = new DataContractSerializer (typeof (XmlDocumentContract))
+ ;
+ var sb = new StringBuilder ();
+ using (var writer = new StringWriter (sb))
+ serializer.WriteObject (new XmlTextWriter (writer), obj);
+ Assert.AreEqual (xml, sb.ToString (), "#1");
+ using (var reader = new StringReader (sb.ToString ()))
+ obj = serializer.ReadObject (new XmlTextReader (reader)) as XmlDocumentContract;
+ Assert.AreEqual ("Hello, world!", obj.Content != null ? obj.Content.InnerText : String.Empty, "#2");
+ Assert.AreEqual (2, obj.Nodes != null ? obj.Nodes.Length : -1, "#3");
+ }
+
+ [Test]
+ public void ArrayAsEnumerableAsRoot ()
+ {
+ var ds = new DataContractSerializer (typeof (IEnumerable<Guid>));
+ var sw = new StringWriter ();
+ using (var xw = XmlWriter.Create (sw, settings))
+ ds.WriteObject (xw, new Guid [] {Guid.Empty});
+ string xml = "<ArrayOfguid xmlns:i='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://schemas.microsoft.com/2003/10/Serialization/Arrays'><guid>00000000-0000-0000-0000-000000000000</guid></ArrayOfguid>".Replace ('\'', '"');
+ Assert.AreEqual (xml, sw.ToString (), "#1");
+ }
+
+ // bug #7957
+ [Test]
+ public void DeserializeEmptyDictionary ()
+ {
+ string whatItGets = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+ + "<MyData xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://sickhead.com/types/Example\">"
+ + "<Data xmlns:b=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\"/>"
+ + "<FirstId>b8a7eb6f-f593-4668-8178-07be9f7266d1</FirstId>"
+ + "<SecondId>ID-GOES-HERE</SecondId>"
+ + "</MyData>";
+ var serializer = new DataContractSerializer (typeof (MyData));
+ using (var stream = new MemoryStream (Encoding.UTF8.GetBytes (whatItGets)))
+ {
+ var data = serializer.ReadObject (stream);
+ }
+ }
+ }
+
[DataContract]
public class MemberIgnored
{
public string Foo = "TEST";
}
+ [DataContract (Namespace = "")]
+ public class DCEmptyNoNS
+ {
+ }
+
[DataContract]
public class DCSimple1
{
class SerializeNonDCArrayType
{
[DataMember]
- public IPAddress [] IPAddresses = new IPAddress [0];
+ public NonDCItem [] IPAddresses = new NonDCItem [0];
+ }
+
+ public class NonDCItem
+ {
+ public int [] Data { get; set; }
}
[DataContract]
[DataMember]
public IList<int> Array { get; set; }
}
+
+ [DataContract]
+ public class NestedContractType
+ {
+ [DataMember]
+ public NestedContractType Nested;
+ [DataMember]
+ public string X = "x";
+ }
+
+ class BaseConstraintType1 // non-serializable
+ {
+ }
+
+ [Serializable]
+ class BaseConstraintType2
+ {
+ }
+
+ [DataContract]
+ class BaseConstraintType3 : BaseConstraintType1
+ {
+ }
+
+ [DataContract]
+ class BaseConstraintType4 : BaseConstraintType2
+ {
+ }
+
+ [DataContract (Namespace = "urn:foo")]
+ public class XmlDocumentContract
+ {
+ [DataMember (Name = "Content")]
+ private XmlElement content;
+
+ public XmlElement Content {
+ get { return content; }
+ set { content = value; }
+ }
+
+ [DataMember (Name = "Nodes")]
+ private XmlNode [] nodes;
+
+ public XmlNode [] Nodes {
+ get { return nodes; }
+ set { nodes = value; }
+ }
+ }
}
[DataContract]
[DataMember]
public string AdvertPrompt { get; set; }
}
+
+// bug #560155
+
+[DataContract]
+public class Person
+{
+ [DataMember]
+ readonly public string name;
+ [DataMember]
+ readonly public Guid Id = Guid.Empty;
+
+ public Person (string nameIn, Guid idIn)
+ {
+ name = nameIn;
+ Id = idIn;
+ }
+
+ public override string ToString()
+ {
+ return string.Format ("name={0},id={1}", name, Id);
+ }
+}
+
+// bug #599889
+namespace U2U.DataContracts
+{
+ [DataContract]
+ public class Person
+ {
+ [DataMember]
+ public string Name { get; set; }
+
+ [DataMember]
+ public Job Occupation { get; set; }
+ }
+
+ [DataContract]
+ public class Job
+ {
+ [DataMember]
+ public string Description { get; set; }
+ }
+}
+
+#region bug #610036
+//parent class with a name property
+[DataContract (Namespace = "Company.Foo")]
+public abstract class ParentClass
+{
+
+ //constructor
+ public ParentClass (string name)
+ {
+ Name = name;
+ }
+
+ //the name
+ [DataMember]
+ public string Name{ get; set; }
+
+}
+
+//root object
+[DataContract (Namespace = "Company.Foo")]
+public class Root : ParentClass
+{
+ //dict
+ [DataMember]
+ public Dict<Foo> FDict;
+
+ //constructor
+ public Root (string name)
+ : base (name)
+ {
+ FDict = new Dict<Foo> ();
+ }
+}
+
+
+//subclass
+[DataContract (Namespace = "Company.Foo")]
+public class Foo : ParentClass
+{
+ //here is one dict
+ [DataMember]
+ public Dict<Bar> FDict;
+
+ //constructor
+ public Foo (string name)
+ : base (name)
+ {
+ FDict = new Dict<Bar> ();
+ }
+
+}
+
+//another sublass
+[DataContract (Namespace = "Company.Foo")]
+public class Bar : ParentClass
+{
+ //constructor
+ public Bar (string name)
+ : base (name)
+ {
+ }
+
+}
+//the custom dictionary
+[CollectionDataContract (ItemName = "DictItem", Namespace = "Company.Foo")]
+public class Dict<T> : Dictionary<string, T> where T : ParentClass
+{
+ public void Add (T item)
+ {
+ Add (item.Name, item);
+ }
+
+}
+
+[DataContract (IsReference = true)]
+public class Parent
+{
+ //constructor
+ public Parent ()
+ {
+ Child = new Child (this);
+ }
+
+ [DataMember]
+ public Child Child;
+}
+
+[DataContract]
+public class Child
+{
+ public Child ()
+ {
+ }
+
+ public Child (Parent parent)
+ {
+ this.Parent = parent;
+ }
+
+ [DataMember]
+ public Parent Parent;
+}
+
+namespace SLProto5
+{
+ public class CashAmount : Amount
+ {
+ }
+
+ [DataContract]
+ public class CashAmountDC : AmountDC
+ {
+ }
+
+ public class Amount
+ {
+ public string Currency { get; set; }
+ public string Description { get; set; }
+ }
+
+ [DataContract]
+ public class AmountDC
+ {
+ [DataMember]
+ public string Currency { get; set; }
+ [DataMember]
+ public string Description { get; set; }
+ }
+}
+
+namespace SLProto5_Different
+{
+ public class CashAmount : SLProto5.Amount
+ {
+ }
+
+ [DataContract]
+ public class CashAmountDC : SLProto5.AmountDC
+ {
+ }
+}
+
+// bug #7957
+[DataContract(Namespace = "http://sickhead.com/types/Example")]
+public class MyData
+{
+ public MyData()
+ {
+ Data = new Dictionary<int, byte[]> ();
+ }
+
+ [DataMember]
+ public Guid FirstId { get; set; }
+
+ [DataMember]
+ public string SecondId { get; set; }
+
+ [DataMember]
+ public Dictionary<int, byte[]> Data { get; set; }
+}
+
+#endregion