Skip to content

Commit 7e9c2d2

Browse files
committed
Fix code smells in NetworkStream
- Disambiguate Read cref references (CS0419). - Make Read overloads adjacent (S4136). - Remove unnecessary boolean literals (S1125).
1 parent 853050b commit 7e9c2d2

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

‎nanoFramework.System.Net/Sockets/NetworkStream.cs‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public NetworkStream(Socket socket, bool ownsSocket)
9090
/// </summary>
9191
/// <value>true if data can be read from the stream; otherwise, false. The default value is true.</value>
9292
/// <remarks>
93-
/// If CanRead is true, <see cref="NetworkStream"/> allows calls to the <see cref="Read"/> method. Provide the appropriate FileAccess enumerated value in the constructor to set
93+
/// If CanRead is true, <see cref="NetworkStream"/> allows calls to the <see cref="Read(byte[], int, int)"/> method. Provide the appropriate FileAccess enumerated value in the constructor to set
9494
/// the readability and write-ability of the <see cref="NetworkStream"/>. The CanRead property is set when the <see cref="NetworkStream"/> is initialized.
9595
/// </remarks>
9696
public override bool CanRead { get { return true; } }
@@ -152,7 +152,7 @@ public override long Length
152152
{
153153
get
154154
{
155-
if (_disposed == true) throw new ObjectDisposedException();
155+
if (_disposed) throw new ObjectDisposedException();
156156
if (_socket.m_Handle == -1) throw new IOException();
157157

158158
return _socket.Available;
@@ -184,7 +184,7 @@ public virtual bool DataAvailable
184184
{
185185
get
186186
{
187-
if (_disposed == true) throw new ObjectDisposedException();
187+
if (_disposed) throw new ObjectDisposedException();
188188
if (_socket.m_Handle == -1) throw new IOException();
189189

190190
return (_socket.Available > 0);
@@ -255,14 +255,14 @@ public override void Flush()
255255
/// <exception cref="ObjectDisposedException">The <see cref="NetworkStream"/> is closed.</exception>
256256
/// <exception cref="ArgumentOutOfRangeException"><paramref name="offset"/> is less than 0 or greater than the length of <paramref name="buffer"/>. -or- <paramref name="count"/> is less than 0 or greater than the length of <paramref name="buffer"/> minus the value of the <paramref name="offset"/> parameter.</exception>
257257
/// <remarks>
258-
/// <para>This method reads data into the <paramref name="buffer"/> parameter and returns the number of bytes successfully read. The <see cref="Read"/> operation reads as much data as is available, up to the number of bytes specified by the <paramref name="count"/> parameter. If the remote host shuts down the connection, and all available data has been received, the Read method completes immediately and return zero bytes.</para>
258+
/// <para>This method reads data into the <paramref name="buffer"/> parameter and returns the number of bytes successfully read. The <see cref="Read(byte[], int, int)"/> operation reads as much data as is available, up to the number of bytes specified by the <paramref name="count"/> parameter. If the remote host shuts down the connection, and all available data has been received, the Read method completes immediately and return zero bytes.</para>
259259
/// <note type="important">
260260
/// Check to see if the <see cref="NetworkStream"/> is readable by calling the <see cref="CanRead"/> property. If you attempt to read from a <see cref="NetworkStream"/> that is not readable, you will get an <see cref="IOException"/>.
261261
/// </note>
262262
/// </remarks>
263263
public override int Read(byte[] buffer, int offset, int count)
264264
{
265-
if (_disposed) throw new ObjectDisposedException();
265+
if (_disposed) throw new ObjectDisposedException();
266266
if (_socket.m_Handle == -1) throw new IOException();
267267
if (buffer == null) throw new ArgumentNullException();
268268
if (offset < 0 || offset > buffer.Length) throw new ArgumentOutOfRangeException();
@@ -281,6 +281,12 @@ public override int Read(byte[] buffer, int offset, int count)
281281
return _socket.Receive(buffer, offset, count, SocketFlags.None);
282282
}
283283

284+
/// <inheritdoc/>
285+
public override int Read(SpanByte buffer)
286+
{
287+
throw new NotImplementedException();
288+
}
289+
284290
/// <summary>
285291
/// Sets the current position of the stream to the given value. This method is
286292
/// not currently supported and always throws a System.NotSupportedException.
@@ -320,7 +326,7 @@ public override void SetLength(long value)
320326
/// </remarks>
321327
public override void Write(byte[] buffer, int offset, int count)
322328
{
323-
if (_disposed) throw new ObjectDisposedException();
329+
if (_disposed) throw new ObjectDisposedException();
324330
if (_socket.m_Handle == -1) throw new IOException();
325331
if (buffer == null) throw new ArgumentNullException();
326332
if (offset < 0 || offset > buffer.Length) throw new ArgumentOutOfRangeException();
@@ -330,11 +336,5 @@ public override void Write(byte[] buffer, int offset, int count)
330336

331337
if (bytesSent != count) throw new IOException();
332338
}
333-
334-
/// <inheritdoc/>
335-
public override int Read(SpanByte buffer)
336-
{
337-
throw new NotImplementedException();
338-
}
339339
}
340340
}

0 commit comments

Comments
 (0)