Scenario:
Copy an object to another one.Solution:
Serialze to bytes to copy all properties and then De-Serialize to new object.
1 2 3 4 5 6 7 8 9 10 | private static MyNewObject CopyObject(MyObject myObject) { var data = _serializer.Deserialize<MyNewObject>(_serializer.ToBytes(myObject)); if (data == null) return null; data.item.ToList().ForEach(li => li.state = "New State"); return data; } |
No comments:
Post a Comment