CloneExtended.cs 792 B

1234567891011121314151617181920212223242526272829
  1. using System;
  2. using System.IO;
  3. using System.Runtime.Serialization;
  4. using System.Runtime.Serialization.Formatters.Binary;
  5. namespace WWPipeLine.Commons
  6. {
  7. /// <summary>
  8. /// 类的扩展属性
  9. /// </summary>
  10. public class CloneExtended : ICloneable
  11. {
  12. public static object Clone(object obj)
  13. {
  14. BinaryFormatter Formatter = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.Clone));
  15. MemoryStream stream = new MemoryStream();
  16. Formatter.Serialize(stream, obj);
  17. stream.Position = 0;
  18. object clonedObj = Formatter.Deserialize(stream);
  19. stream.Close();
  20. return clonedObj;
  21. }
  22. public object Clone()
  23. {
  24. return null;
  25. }
  26. }
  27. }