serializable class

Help!!!

I need to create a serializable (xml style) class to write it on a DB field (type memo/text on sql).

This class contains a collection. To understand i have a db of similar things with a Levels field. Here i want store the level structure, style xml.

<Level1 name="">

<level2 name=""></level2>

</Level1>

Give me some indications to write this class and some code to start, please.

Thx

[493 byte] By [manuel0081] at [2007-12-19]
# 1

Hi!

You can use this for a start.

public class Style

{

[XmlAttribute]

public string FontName;

[XmlAttribute]

public int Color;

[XmlArray]

public List<Style> Children = new List<Style>();

public Style FromXml(string fileName)

{

using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read))

{

return new XmlSerializer(typeof(Style)).Deserialize(stream) as Style;

}

}

public void SaveXml(string fileName)

{

using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write))

{

new XmlSerializer(typeof(Style)).Serialize(stream, this);

}

}

}

SergeyGalich at 2007-9-8 > top of Msdn Tech,Visual C#,Visual C# General...
# 2

In .net framework we get some things for free!

You can use the default serialization:

System.Xml.Serialization.XmlSerializer

You can custom the serialization operation using attributes, such as

System.Xml.Serialization.XmlIgnoreAttribute

System.Xml.Serialization.XmlElementAttribute

guykolbis at 2007-9-8 > top of Msdn Tech,Visual C#,Visual C# General...