Is it possible by using attributes to serialize a <List<List<Point>>
property to output as shown below?
Current Output
<PolyPolyline>
<ArrayOfPoint>
<Point>
<X>5</X>
<Y>5</Y>
</Point>
<Point>
<X>10</X>
<Y>15</Y>
</Point>
Preferred Output
<PolyPolyline>
<Polyline>
<Point X=5 Y=5 />
<Point X=10 Y=15 />
Here is some sample code of the class:
--------------------------------------------------------------
using System.Drawing;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Serialization;
namespace Cjf
{
public class Test
{
private List<List<Point>_polyPolyline = new
List<List<Point>>();
public List<List<Point>PolyPolyline
{
get { return _polyPolyline; }
set { _polyPolyline = value; }
}
public static void Serialize(string filename, Test test)
{
XmlSerializer serializer = new XmlSerializer(typeof(Test));
XmlWriter writer = XmlWriter.Create(filename);
serializer.Serialize(writer, test);
writer.Close();
}
public static Test Deserialize(string filename)
{
XmlSerializer s = new XmlSerializer(typeof(Test));
XmlReader reader = XmlReader.Create(filename);
Test test = (Test)s.Deserialize(reader);
reader.Close();
return test;
}
public static Test CreateTestData()
{
Test test = new Test();
List<Pointpolyline = new List<Point>();
test.PolyPolyline.Add(polyline);
polyline.Add(new Point(5, 5));
polyline.Add(new Point(10, 15));
polyline.Add(new Point(20, 15));
polyline.Add(new Point(25, 30));
polyline = new List<Point>();
test.PolyPolyline.Add(polyline);
polyline.Add(new Point(-5, -5));
polyline.Add(new Point(-10, -15));
polyline.Add(new Point(-20, -15));
return test;
}
}
}
-------------------------------------------------------------
string path = System.IO.Path.GetTempPath();
Cjf.Test test = Cjf.Test.CreateTestData();
Cjf.Test.Serialize(path + "test1.xml", test);