Avoid to check the type of propertyWriter parameter (#1600)

Refactor code of MqttBufferWriter
This commit is contained in:
老九
2022-11-30 17:56:05 +01:00
committed by GitHub
parent 56750adfe4
commit 47df131e7f
+1 -7
View File
@@ -103,18 +103,12 @@ namespace MQTTnet.Formatter
public void Write(MqttBufferWriter propertyWriter) public void Write(MqttBufferWriter propertyWriter)
{ {
if (propertyWriter is MqttBufferWriter writer)
{
WriteBinary(writer._buffer, 0, writer.Length);
return;
}
if (propertyWriter == null) if (propertyWriter == null)
{ {
throw new ArgumentNullException(nameof(propertyWriter)); throw new ArgumentNullException(nameof(propertyWriter));
} }
throw new InvalidOperationException($"{nameof(propertyWriter)} must be of type {nameof(MqttBufferWriter)}"); WriteBinary(propertyWriter._buffer, 0, propertyWriter.Length);
} }
public void WriteBinary(byte[] buffer, int offset, int count) public void WriteBinary(byte[] buffer, int offset, int count)