void SerializerDCArray(XmlWriter writer) { DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(DCWithEnum [])); DCWithEnum [] arr = new DCWithEnum [2]; arr [0] = new DCWithEnum(); arr [0].colors = Colors.Red; arr [1] = new DCWithEnum(); arr [1].colors = Colors.Green; using (XmlWriter w = writer) { ser.WriteObject(w, arr); } }
public void DeserializeDCWithEnum() { object o = Deserialize( "{\"_colors\":0}", typeof(DCWithEnum)); Assert.AreEqual(typeof(DCWithEnum), o.GetType(), "#de7"); DCWithEnum dc = (DCWithEnum)o; Assert.AreEqual(Colors.Red, dc.colors, "#de8"); }
void SerializerDCArray2(XmlWriter writer) { List <Type> known = new List <Type> (); known.Add(typeof(DCWithEnum)); known.Add(typeof(DCSimple1)); DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(object []), known); object [] arr = new object [2]; arr [0] = new DCWithEnum(); ((DCWithEnum)arr [0]).colors = Colors.Red; arr [1] = new DCSimple1(); ((DCSimple1)arr [1]).Foo = "hello"; using (XmlWriter w = writer) { ser.WriteObject(w, arr); } }