Forum Xamarin.Forms

Serializing Pocos to bye[] and save to app sandbox

TripVoltageTripVoltage GBMember
edited November 2016 in Xamarin.Forms

Hi I'm trying to figure out how to save transient app data to app sandbox storage. To begin with the object I need to save are my standard Pocos which have some images.

My first thought was to pass my object down to my iOS project using Dependancy Service and have it converted with basic Object to byte array converter before writing it to storage. But serializable [Serializable] is not supported for my Pocos in the PCL! Phew, and xml is no good for me because of the image info etc.

Basic Poco:
public class MyClass { public string id { get; set; } public string Standard { get; set; } public string Image { get; set; } }
public byte[] ObjectToByteArray(Object obj) { MemoryStream fs = new MemoryStream(); BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(fs, obj); byte[] rval = fs.ToArray(); fs.Close(); return rval; }

What are the solutions for this situation in Xamarin PCL?



  • josemmortegajosemmortega ESUniversity ✭✭✭

    @TripVoltage You have right. When you serialize in byte[] only need pass to dependency service and store this data in a file or something. Also, if you want I recomend you use Json.Net and serialize to Json.

Sign In or Register to comment.