On 03 Jul 2004 08:41, M Ali wrote:
No takers? Did i post in the wrong group? If so, could any one point
me to the relevant one?
Since you haven't quoted your original question I'm taking a guess, but
here goes.
The conditions for serialising a tree of objects are the same for serialising
one object. Each object in the tree must be serialisable: it has to have
a default public constructor (i.e. no parameters) and each property must
expose a serialisable type. Properties which you don't want to serialise
can be prevented by using the [XmlIgnore] attribute.
Some collections are not serialisable (e.g. Hashtable). In this case you
can work-around it by putting [XmlIgnore] on the Hashtable property and
creating another property which gets/sets the contacts of the Hashtable
as an array of the type contained. This of course allows the clients of
the class to access the collection in two ways which may or may not be
a good thing. For example, if the Hashtable contained strings:
<aircode>
[XmlIgnore]
public Hashtable MyStrings {
get { return myStringHashtable; }
set { myStringHashtable = value; }
}
public string[] SerialisableStrings {
get {
int i = myStringHashtable.Values.Count;
string[] strings = new string[i];
i = 0;
foreach (string astring in myStringHashtable.Values) {
strings[i] = astring;
i++;
}
}
set {
myStingHashtable = new Hashtable();
foreach (string astring in value) {
myStringHashtable.Add(astring, astring);
}
}
}
</aircode>
Now all you need to do is serialise the containing object and as long
as all types exposed are serialisable it will work.
I am obviously talking about Xml serialisation here. For anything more
sophisticated you should implement ISerializable. If you want to do that,
read the docs first and then ask any questions.
--
Simon Smith
simon dot s at ghytred dot com
www.ghytred.com/NewsLook - NNTP Client for Outlook