No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

28 líneas
960 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. var requestPacketWithIdentifier = packet as IMqttPacketWithIdentifier;
  13. if (requestPacketWithIdentifier == null)
  14. {
  15. throw new InvalidOperationException("Response packet has PacketIdentifier but request packet does not.");
  16. }
  17. responsePacketWithIdentifier.PacketIdentifier = requestPacketWithIdentifier.PacketIdentifier;
  18. }
  19. return responsePacket;
  20. }
  21. }
  22. }