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.
|
- using System;
-
- namespace MQTTnet.Packets
- {
- public static class MqttPacketExtensions
- {
- public static TResponsePacket CreateResponse<TResponsePacket>(this MqttBasePacket packet)
- {
- if (packet == null) throw new ArgumentNullException(nameof(packet));
-
- var responsePacket = Activator.CreateInstance<TResponsePacket>();
-
- if (responsePacket is IMqttPacketWithIdentifier responsePacketWithIdentifier)
- {
- if (!(packet is IMqttPacketWithIdentifier requestPacketWithIdentifier))
- {
- throw new InvalidOperationException("Response packet has PacketIdentifier but request packet does not.");
- }
-
- responsePacketWithIdentifier.PacketIdentifier = requestPacketWithIdentifier.PacketIdentifier;
- }
-
- return responsePacket;
- }
- }
- }
|