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.
 
 
 
 

27 righe
904 B

  1. using System;
  2. namespace MQTTnet.Core.Packets
  3. {
  4. public static class MqttPacketExtensions
  5. {
  6. public static TResponsePacket CreateResponse<TResponsePacket>(this MqttBasePacket packet)
  7. {
  8. if (packet == null) throw new ArgumentNullException(nameof(packet));
  9. var responsePacket = Activator.CreateInstance<TResponsePacket>();
  10. if (responsePacket is IMqttPacketWithIdentifier responsePacketWithIdentifier)
  11. {
  12. if (!(packet is IMqttPacketWithIdentifier requestPacketWithIdentifier))
  13. {
  14. throw new InvalidOperationException("Response packet has PacketIdentifier but request packet does not.");
  15. }
  16. responsePacketWithIdentifier.PacketIdentifier = requestPacketWithIdentifier.PacketIdentifier;
  17. }
  18. return responsePacket;
  19. }
  20. }
  21. }