1

Something like these cocoa methods:

NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile: path]
[dict writeToFile: someOtherPath atomically: YES];

NSArray *array = [NSArray arrayWithContentsOfFile: path];
[array writeToFile: someOtherPath atomically: YES];

and so on. Ideally, the file format would be one I could create and edit manually.

EDIT: this is for Windows Phone 7.

EDIT: Thanks for the answers. Though looking through some of your links . . . XMLSerializer does not handle dictionaries?!?!?

William Jockusch
  • 26,513
  • 49
  • 182
  • 323

2 Answers2

3

You could also take a look at this post about binary serialization on windows phone 7. Whether you want to do binary or xml serialization will depend on your needs.

You might also be interested in this discussion of binary vs xml serialization.

Community
  • 1
  • 1
Roman
  • 19,581
  • 6
  • 68
  • 84
1

Why are you not simply using XmlSerializer class with XmlSerializer.Serialize and XmlSerializer.Deserialize methods? There is no universal standard of converting collections to files and vice versa, but it may be one of the most popular methods.

If you both need to serialize/deserialize dictionaries and have the ability to manullay edit files so they must be readable, you can use Json.NET as an alternative. JSON is very readable and handles dictionaries. For instance:

string json = @"{""key1"":""value1"",""key2"":""value2""}";

Dictionary<string, string> values = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
Teoman Soygul
  • 25,584
  • 6
  • 69
  • 80