简体   繁体   中英

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>
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM