custom serialization

G

Guest

Hi,
I'm new serialization concepts....I need some hwlp..
I've a class defined as follows

class CustomSerialization1
{
private string s;

public string Test
{
get { return s; }
set { s = value; }
}

private int i;

public int Test1
{
get { return i; }
set { i = value; }
}
CustomSerialization1 obj = new CustomSerialization1();
obj.Test = "vijaya,wajid,vani";
object.Test1 = 3;
}

if want the the output to be sth below after applying serializatiion

<Task>
<Test>
<TestInnner>Vijaya</TestInnner>
<TestInnner>wajid</TestInnner>
<TestInnner>vani</TestInnner>
</Test>
<Test1>3</Test3>
</Task>

Basically I want to control teh way inwhich my Test property will be
displayed during serialization and deserialization....


please help me out..just let me know if this is possible by any means...
either thru XmlSerialization or Custom Serialziation...
 
B

bruce barker

pretty trivial. you implement IXmlSerializable:

public void WriteXml(XmlWriter writer)
{
writer.WriteStartElement("Taskt");
writer.WriteStartElement("Test");
string[] values = s.Split(',');
for (int i=0; i < values.Length; ++i)
{
writer.WriteStartElement("Test1");
writer.WriteString(values);
writer.WriteEndElement();
}
writer.WriteEndElement();

writer.WriteStartElement("Test1");
writer.WriteString(Test1.ToString());
writer.WriteEndElement();
writer.WriteEndElement();
}
public void ReadXml(XmlReader reader)
{
// left to reader
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top