I have to copy an Arraylist to a new Arraylist. In the old Arraylist there are multiple elements which changes at runtime.One of them is the module settings parameter inside the Arraylist. I would like to deep copy the values of the arraylist so that I can use it for undo operation. I tried using Binaryformater and Datacontract. Both can't be done for non serializable object. Can anyone help , pls?
            Asked
            
        
        
            Active
            
        
            Viewed 712 times
        
    2 Answers
0
            Without more information it's hard to say exactly what's wrong, but ArrayList itself is serializable. However, if you are using a custom object you need to mark it as serializable for serialization to work. See: Serialize ArrayList of Objects
 
    
    
        luxun
        
- 457
- 5
- 14
- 
                    Seems I have to make Individual classes inside the Arraylist as serializable. Thanks for the input :) – Sangathamilan Ravichandran May 31 '17 at 08:51
0
            
            
        Use a memory stream and binary formatter Something like
`public T Clone<T> (T obj)
.   {
.       using(var ms = new MemoryStream())
.       {
.          var formatter = new BinaryFormatter();
        formatter.Serialize(stream, obj);
        stream.Position =0;
        return (T)formatter.Deserialize(stream);
     }
.    }’
Hope that helps
 
    
    
        KwackMaster
        
- 180
- 2
- 13
- 
                    I already tried the above code. I had to convert all the classes under my app to serializable to acheive that. :) – Sangathamilan Ravichandran May 31 '17 at 08:57
