Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

47 rader
1.2 KiB

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