1

In iOS SDK, NSDictionary has got writeToFile and dictionaryWithContentsOfFile methods to write a dictionary into a file and to read the contents of a file as dictionary. Is it possible to do the same in WP7 (C#) ?

saikamesh
  • 4,569
  • 11
  • 53
  • 93

4 Answers4

1

Yes, but you have to serialize the dictionaary and write to a file yourself.

Alternatively you could add to IsoaltedStorageSettings and let the framework do the serialization for you.

Matt Lacey
  • 65,560
  • 11
  • 91
  • 143
1

I believe the SilverlightSerializer library is capable of serializing a dictionary; you could serialize your dictionary to a byte array and write it to Isolated Storage.

SilverlightSerializer examples: http://whydoidoit.com/silverlight-serializer/

Or try SharpSerializer, there's a WP7 version available (and a NuGet package): http://www.sharpserializer.com/en/tutorial/index.html

E.Z. Hart
  • 5,717
  • 1
  • 30
  • 24
0

Isolated storage provides a file system. Serialisation is an orthogonal problem.

It is possible to write any object graph into IsolatedStorageSettings provided every object in the graph is DataContract serialisable. Many common framework types are not, for example GeoCoordinate.

Arguably, IsolatedStorageSettings is a dictionary. But the caveat stands regarding DataContract seralisability.

It is equally possible and a lot smarter to write your dictionary to a file, because the more you store in ISS the longer it takes to instantiate. This can seriously affect app load and resume times. You will still have to manage serialisation yourself to the extent that unsupported classes are involved. Your biggest handicap would be the absence of BinaryFormatter from the framework (I don't know whether Mango adds it.)

Peter Wone
  • 17,965
  • 12
  • 82
  • 134
  • This is a true and constructive statement that tactfully steers the OA away from inappropriate use of isolated storage likely to result in poor performance at a critical part of the application lifecycle. Failure to heed this advice could cause your app to be rejected. Perhaps the down-voter could share with us the brilliance of his insight? – Peter Wone Jul 03 '13 at 00:15
0

@saikamesh, Here is a thread that covers XML serialization of dictionary in .NET. Why isn't there an XML-serializable dictionary in .NET?. It lists a number of different approaches. You can then write the output string to a file in isolated storage.

You can find mappings of iPhone classes to Windows Phone classes at iPhone and Android to WP7 mapping site

Community
  • 1
  • 1
Vivek Nirkhe
  • 369
  • 2
  • 3