Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. serviceAssembly = Assembly.LoadFrom(path);
  2.  
  3. public static byte[] TransformMessageToBytes(NotificationMessage msg)
  4. {
  5. if (msg == null)
  6. throw new ArgumentNullException(nameof(msg));
  7.  
  8. using (MemoryStream stream = new MemoryStream())
  9. {
  10. BinaryFormatter binFormatter = new BinaryFormatter();
  11. binFormatter.Serialize(stream, msg);
  12. return stream.ToArray();
  13. }
  14. }
  15.  
  16. public static NotificationMessage TransfromBytesToNotificationMessage(byte[] array, int offset, int count)
  17. {
  18. if(array == null)
  19. throw new ArgumentNullException(nameof(array));
  20.  
  21. using (MemoryStream stream = new MemoryStream())
  22. {
  23. BinaryFormatter binFormatter = new BinaryFormatter();
  24. stream.Write(array, offset, count);
  25. stream.Seek(0, SeekOrigin.Begin);
  26. return binFormatter.Deserialize(stream) as NotificationMessage;
  27. }
  28. }
  29.  
  30. serviceDomain.DoCallBack(() =>
  31. {
  32. // for example
  33. // create instance of NotificationMessage by using reflection
  34. // Invoke convertation methods
  35. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement