您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

41 行
1005 B

  1. /* Describtion : Class for Binary Serialize and Deserialize
  2. * Company : Wuxi Xinje
  3. * Author : Somuns
  4. * DateTime : 2021/1/18
  5. */
  6. using System.IO;
  7. using System.Runtime.Serialization.Formatters.Binary;
  8. namespace StuMgmLib.MyNameSpace
  9. {
  10. public class BinaryED // 序列化与反序列化
  11. {
  12. /// <summary>
  13. /// 序列化
  14. /// </summary>
  15. public static byte[] Serialize<T>(T c)
  16. {
  17. MemoryStream ms = new MemoryStream();
  18. BinaryFormatter iFormatter = new BinaryFormatter();
  19. iFormatter.Serialize(ms, c);
  20. byte[] buf = ms.GetBuffer();
  21. return buf;
  22. }
  23. /// <summary>
  24. /// 反序列化
  25. /// </summary>
  26. public static T Deserialize<T>(byte[] buf)
  27. {
  28. MemoryStream ms = new MemoryStream(buf);
  29. BinaryFormatter iFormatter = new BinaryFormatter();
  30. var obj = (T)iFormatter.Deserialize(ms);
  31. return obj;
  32. }
  33. }
  34. }