Ameen
Ameen

Reputation: 1907

Save IEnumerable in Isolated Storage

I used the isolated storage before to save text files, xml files and images. However, is it possible to save variables of type IEnumerable using IsolatedStorage or any other resource in windows phone 7??

Thanks,

Upvotes: 0

Views: 940

Answers (2)

quetzalcoatl
quetzalcoatl

Reputation: 33506

You are misunderstanding core concepts.. There is no such thing as "saving variables", you save objects. Your variable points to an object, and that objects implements IEnumerable. Is On WP7, it is the object's actual class that determines whether that object can be serialized and stored on the ISO directly. If that actual collection class does not support serialization, you will have to re-wrap all its current elements into a List/Array/Dictionary/Stack/Queue - literally whatever what supports being serialized - and store that instead of.

Once you have an serializable collection, then your code for saving gets reduced to something as trivial as:

IsolatedStorageSettings.ApplicationSettings["blah"] = your_serializable_collection;
IsolatedStorageSettings.ApplicationSettings.Save();

and in general, that's it. Retrieving is similar:

var items = (SomeCollection)IsolatedStorageSettings.ApplicationSettings["blah"];

where SomeCollection may be an IEnumerable, a List/Array/Dictionary/Stack/Queue - whatever you had put there and whatever is implemented by the actual collection class.

If you want, you may use IsolatedStorageFile and write files directly, but unless you have a good reason to - there's no point in it, as using the common dictionary is far simplier.

In my other post you'll find some links: How to do isolated storage in Wp7?

Upvotes: 2

Ralf Ehlert
Ralf Ehlert

Reputation: 400

Use for saving/loading of data List which are serializable out of the box. Last time i tried deserialize an IEnumerable I got errors...

Upvotes: 1

Related Questions