0

I am trying to save a list of a custom class to isolatedstoragesettings, but either it is not saving correctly or not retrieving correctly and I am not sure whats wrong,

class:

[DataContract()]
public class Object
{
    public int ID { get; set; }
    public bool IsDeleted { get; set; }
    public bool IsActive { get; set; }
    public string Title { get; set; }
    public string Author { get; set; }
    public string Synopsis { get; set; }
    public string Body { get; set; }
    public string ImageUrl { get; set; }
    public string CreationDate { get; set; }
    public string LastUpdateDate { get; set; }
    public string DisplayUntilDate { get; set; }
    public int TotalViews { get; set; }
    public Gallery Gallery { get; set; }
}

then I am using this to save it

 List<Object> to_save = new List<Object>();

//populate the list of objects, this works correctly, it just makes a big list of objects then

 var settings = IsolatedStorageSettings.ApplicationSettings;
   //save to_save to isolated storage
            settings.Add("Stories", to_save);
            settings.Save();

then when I try and retrieve it:

//get the details from the isolated storage

        var settings = IsolatedStorageSettings.ApplicationSettings;
        List<Object> s = settings["Stories"] as List<Object>;

it just give me 2 items that is both null, I think I am doing the serialization wrong, but I don't know the correct way, could someone please help?

Edit:

Ok I have added datamember to each field, now the 2 items returned is not null and contains the correct values, however it is not the entire list, how can I retrieve the entire list, istead of just 2 items?

Bohrend
  • 1,467
  • 3
  • 17
  • 26

1 Answers1

0

you must have strongly type objects to serialise as the serialiser on Windows Phone is fairly basic.

Also for isolated storage only use base data types, so your "gallery" object likely wouldn't be serialised.

Note you don't actually need the data contract and data member attributes for simple serialisation but shouldn't harm it by using it.

If you want to do more complicated serialisation, then look into XMLSerialiser

Darkside
  • 1,722
  • 14
  • 19