Link to home
Start Free TrialLog in
Avatar of FrancineTaylor
FrancineTaylor

asked on

Best way to save a generic list of custom objects

I've got a class which contains a list of classes, which in turn contain lists of classes.  I'm looking for the cleanest way to simply save and retrieve the objects.  There is a wealth of code out there, using Xmlserialize, a BinaryFormatter, conversion to XML...I'm a bit overloaded with information.

Here's an example of my code.

public class cParent {
   public List<cChild> children;
   public string firstname;
   public string lastname;
   public cParent() {
   }
}

public class cChild {
   public List<cToy> toys;
   public List<cChild> friends;
   public string firstname;
   public DateTime bday;
   public bool male;
   public cChild() {
   }
}
public class cToy {
   eToyType ttype;
   public cToy() {
   }
}
public enum eToyType {
    doll, book, weapon, game, sports
}

So, given the classes above, if I have a list of parent objects:

List<cParent> parents = SomeFunctionCreatingTheObjects();

...if I want to simply save the parent objects to a file, what is the best way to do it?  And what modifications do I need to make to the classes (such as the [Serialize] attribute, XmlRoot/XmlElement, etc).  And then how do I retrieve them?
ASKER CERTIFIED SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial