Sadly, How to implement DeepCopy for Windows Store App? RRS feed

  • Question

  • Hi,

    In C# not Store we can use following

    public static T Make<T>(T objectToCopy) where T : class { using (var ms = new MemoryStream()) { var bf = new BinaryFormatter(); bf.Serialize(ms, objectToCopy); ms.Position = 0; return (T)bf.Deserialize(ms); } }

    Where is the BinaryFormatter();>?

    Friday, September 19, 2014 10:12 AM


  • You don't really need to concern yourself with the intermediate format in a clone operation, so just use XML instead:
    public T Clone<T>(T input)
        XmlSerializer s = new XmlSerializer(typeof(T));
        MemoryStream ms = new MemoryStream();
        s.Serialize(ms, input);
        ms.Seek(0, SeekOrigin.Begin);
        return (T)s.Deserialize(ms);

    Darin R.

    Friday, September 19, 2014 5:02 PM