Possible to serialize a collection that is part of an object
Im trying to store my data in an XML file using the XML Serialization. Question is, if my object has a collection member, can i serialize the collection as well?
This is how my objects work.
class Project{
List<Iteration&开发者_运维百科gt;
}
class Iteration{
List<Job>
}
class Job{
some other attributes
}
So each project has a list of iterations, and each iteration has a list of projects. So essentially, Each project can have many iterations and each iteration can have many jobs.
If serialization is not possible, can anyone suggest to me another method to store my data?
thanks in advance.
I have used such a type of serialization before. If you have a simple application you can sometimes serialize your whole set of data from one root object (might be an antipattern somehow, but I know I have done it before).
This should work with the default XML serializer in the XML.Serialization namespace, but you need to make sure your classes are marked with the serializable attribute. I'm not sure if it is available on the compact framework though.
Have you considered using Json serialization instead? If you use something like Json.Net (available for Windows Phone 7), you should be able to serialize the entire object graph.
精彩评论