Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

46 righe
1.2 KiB

  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Runtime.Serialization.Formatters.Binary;
  5. namespace StuMgmClient
  6. {
  7. class Utility
  8. {
  9. internal static bool BinSerialize<T>(T data, out byte[] buff)
  10. {
  11. try
  12. {
  13. MemoryStream ms = new MemoryStream();
  14. BinaryFormatter iFormatter = new BinaryFormatter();
  15. iFormatter.Serialize(ms, data);
  16. buff = ms.GetBuffer();
  17. return true;
  18. }
  19. catch (Exception e)
  20. {
  21. Debug.Print(e.Message);
  22. buff = null;
  23. return false;
  24. }
  25. }
  26. internal static bool BinDeserialize(byte[] data, out object o)
  27. {
  28. try
  29. {
  30. MemoryStream ms = new MemoryStream(data);
  31. BinaryFormatter iFormatter = new BinaryFormatter();
  32. o = iFormatter.Deserialize(ms);
  33. return true;
  34. }
  35. catch (Exception e)
  36. {
  37. Debug.Print(e.Message);
  38. o = null;
  39. return false;
  40. }
  41. }
  42. }
  43. }