mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-21 12:16:02 +08:00
Convert null checks to modern ThrowIfNull checks (#2089)
Convert null check to modern ThrowIfNull checks
This commit is contained in:
@@ -11,10 +11,7 @@ namespace MQTTnet.Formatter
|
||||
{
|
||||
public static MqttApplicationMessage Create(MqttPublishPacket publishPacket)
|
||||
{
|
||||
if (publishPacket == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(publishPacket));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(publishPacket);
|
||||
|
||||
return new MqttApplicationMessage
|
||||
{
|
||||
|
||||
@@ -105,10 +105,7 @@ namespace MQTTnet.Formatter
|
||||
|
||||
public void Write(MqttBufferWriter propertyWriter)
|
||||
{
|
||||
if (propertyWriter == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(propertyWriter));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(propertyWriter);
|
||||
|
||||
WriteBinary(propertyWriter._buffer, 0, propertyWriter.Length);
|
||||
}
|
||||
@@ -140,10 +137,7 @@ namespace MQTTnet.Formatter
|
||||
|
||||
public void WriteBinary(byte[] buffer, int offset, int count)
|
||||
{
|
||||
if (buffer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(buffer));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(buffer);
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
@@ -292,7 +286,7 @@ namespace MQTTnet.Formatter
|
||||
|
||||
if (_position > Length)
|
||||
{
|
||||
// Also extend the position because we reached the end of the
|
||||
// Also extend the position because we reached the end of the
|
||||
// pre allocated buffer.
|
||||
Length = _position;
|
||||
}
|
||||
|
||||
@@ -11,10 +11,7 @@ public static class MqttConnectPacketFactory
|
||||
{
|
||||
public static MqttConnectPacket Create(MqttClientOptions clientOptions)
|
||||
{
|
||||
if (clientOptions == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(clientOptions));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(clientOptions);
|
||||
|
||||
var connectPacket = new MqttConnectPacket
|
||||
{
|
||||
|
||||
@@ -12,10 +12,7 @@ public static class MqttPubAckPacketFactory
|
||||
{
|
||||
public static MqttPubAckPacket Create(MqttApplicationMessageReceivedEventArgs applicationMessageReceivedEventArgs)
|
||||
{
|
||||
if (applicationMessageReceivedEventArgs == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(applicationMessageReceivedEventArgs));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(applicationMessageReceivedEventArgs);
|
||||
|
||||
var pubAckPacket = new MqttPubAckPacket
|
||||
{
|
||||
|
||||
@@ -12,10 +12,7 @@ public static class MqttPubCompPacketFactory
|
||||
{
|
||||
public static MqttPubCompPacket Create(MqttPubRelPacket pubRelPacket, MqttApplicationMessageReceivedReasonCode reasonCode)
|
||||
{
|
||||
if (pubRelPacket == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(pubRelPacket));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(pubRelPacket);
|
||||
|
||||
return new MqttPubCompPacket
|
||||
{
|
||||
|
||||
@@ -12,10 +12,7 @@ public static class MqttPubRecPacketFactory
|
||||
{
|
||||
public static MqttPubRecPacket Create(MqttApplicationMessageReceivedEventArgs applicationMessageReceivedEventArgs)
|
||||
{
|
||||
if (applicationMessageReceivedEventArgs == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(applicationMessageReceivedEventArgs));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(applicationMessageReceivedEventArgs);
|
||||
|
||||
var pubRecPacket = Create(applicationMessageReceivedEventArgs.PublishPacket, applicationMessageReceivedEventArgs.ReasonCode);
|
||||
pubRecPacket.UserProperties = applicationMessageReceivedEventArgs.ResponseUserProperties;
|
||||
|
||||
@@ -12,10 +12,7 @@ public static class MqttPubRelPacketFactory
|
||||
{
|
||||
public static MqttPubRelPacket Create(MqttPubRecPacket pubRecPacket, MqttApplicationMessageReceivedReasonCode reasonCode)
|
||||
{
|
||||
if (pubRecPacket == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(pubRecPacket));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(pubRecPacket);
|
||||
|
||||
return new MqttPubRelPacket
|
||||
{
|
||||
|
||||
@@ -12,10 +12,7 @@ namespace MQTTnet.Formatter
|
||||
{
|
||||
public static MqttPublishPacket Create(MqttApplicationMessage applicationMessage)
|
||||
{
|
||||
if (applicationMessage == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(applicationMessage));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(applicationMessage);
|
||||
|
||||
// Copy all values to their matching counterparts.
|
||||
// The not supported values in MQTT 3.1.1 are not serialized (excluded) later.
|
||||
|
||||
@@ -11,10 +11,7 @@ public static class MqttSubscribePacketFactory
|
||||
{
|
||||
public static MqttSubscribePacket Create(MqttClientSubscribeOptions clientSubscribeOptions)
|
||||
{
|
||||
if (clientSubscribeOptions == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(clientSubscribeOptions));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(clientSubscribeOptions);
|
||||
|
||||
var packet = new MqttSubscribePacket
|
||||
{
|
||||
|
||||
@@ -11,10 +11,7 @@ public static class MqttUnsubscribePacketFactory
|
||||
{
|
||||
public static MqttUnsubscribePacket Create(MqttClientUnsubscribeOptions clientUnsubscribeOptions)
|
||||
{
|
||||
if (clientUnsubscribeOptions == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(clientUnsubscribeOptions));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(clientUnsubscribeOptions);
|
||||
|
||||
var packet = new MqttUnsubscribePacket
|
||||
{
|
||||
|
||||
@@ -91,10 +91,7 @@ namespace MQTTnet.Formatter.V3
|
||||
|
||||
public MqttPacketBuffer Encode(MqttPacket packet)
|
||||
{
|
||||
if (packet == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(packet));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(packet);
|
||||
|
||||
// Leave enough head space for max header size (fixed + 4 variable remaining length = 5 bytes)
|
||||
_bufferWriter.Reset(5);
|
||||
@@ -797,10 +794,7 @@ namespace MQTTnet.Formatter.V3
|
||||
|
||||
void ValidateConnectPacket(MqttConnectPacket packet)
|
||||
{
|
||||
if (packet == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(packet));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(packet);
|
||||
|
||||
if (string.IsNullOrEmpty(packet.ClientId) && !packet.CleanSession)
|
||||
{
|
||||
|
||||
@@ -25,10 +25,7 @@ public sealed class MqttV5PacketEncoder
|
||||
|
||||
public MqttPacketBuffer Encode(MqttPacket packet)
|
||||
{
|
||||
if (packet == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(packet));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(packet);
|
||||
|
||||
// Leave enough head space for max header size (fixed + 4 variable remaining length = 5 bytes)
|
||||
const int ReservedHeaderSize = 5;
|
||||
|
||||
@@ -221,7 +221,7 @@ namespace MQTTnet.Formatter.V5
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
// Absence of the flag means it is supported!
|
||||
// Absence of the flag means it is supported!
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -230,10 +230,7 @@ namespace MQTTnet.Formatter.V5
|
||||
|
||||
public void WriteTo(MqttBufferWriter target)
|
||||
{
|
||||
if (target == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(target));
|
||||
}
|
||||
ArgumentNullException.ThrowIfNull(target);
|
||||
|
||||
target.WriteVariableByteInteger((uint)_bufferWriter.Length);
|
||||
target.Write(_bufferWriter);
|
||||
|
||||
Reference in New Issue
Block a user