CopyHelper.cs 671 B

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Runtime.Serialization.Formatters.Binary;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace Common
  9. {
  10. [Serializable]
  11. public class DeepCopyHelper<T> : ICloneable
  12. {
  13. public T data { get; set; }
  14. public DeepCopyHelper(T t)
  15. {
  16. this.data = t;
  17. }
  18. public object Clone()
  19. {
  20. var bf = new BinaryFormatter();
  21. var ms = new MemoryStream();
  22. bf.Serialize(ms, this);
  23. ms.Position = 0;
  24. return bf.Deserialize(ms);
  25. }
  26. }
  27. }