Skip to content

Commit 7248f6d

Browse files
committed
follow the code analyzer rules
1 parent fc14525 commit 7248f6d

File tree

4 files changed

+56
-47
lines changed

4 files changed

+56
-47
lines changed

src/Smdn.Fundamental.Stream.BinaryReaderWriter/Smdn.IO.Binary/BinaryConversion.cs

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,21 @@ public static UInt16 ToUInt16LE(byte[] @value, int startIndex)
114114
{
115115
CheckSourceArray(@value, startIndex, 2);
116116

117-
return (UInt16)(@value[startIndex] |
118-
@value[startIndex + 1] << 8);
117+
return (UInt16)(
118+
@value[startIndex] |
119+
(@value[startIndex + 1] << 8)
120+
);
119121
}
120122

121123
[CLSCompliant(false)]
122124
public static UInt16 ToUInt16BE(byte[] @value, int startIndex)
123125
{
124126
CheckSourceArray(@value, startIndex, 2);
125127

126-
return (UInt16)(@value[startIndex] << 8 |
127-
@value[startIndex + 1]);
128+
return (UInt16)(
129+
(@value[startIndex] << 8) |
130+
@value[startIndex + 1]
131+
);
128132
}
129133

130134
[CLSCompliant(false)]
@@ -153,21 +157,25 @@ public static UInt32 ToUInt32LE(byte[] @value, int startIndex)
153157
{
154158
CheckSourceArray(@value, startIndex, 4);
155159

156-
return (UInt32)(@value[startIndex] |
157-
@value[startIndex + 1] << 8 |
158-
@value[startIndex + 2] << 16 |
159-
@value[startIndex + 3] << 24);
160+
return (UInt32)(
161+
@value[startIndex] |
162+
(@value[startIndex + 1] << 8) |
163+
(@value[startIndex + 2] << 16) |
164+
(@value[startIndex + 3] << 24)
165+
);
160166
}
161167

162168
[CLSCompliant(false)]
163169
public static UInt32 ToUInt32BE(byte[] @value, int startIndex)
164170
{
165171
CheckSourceArray(@value, startIndex, 4);
166172

167-
return (UInt32)(@value[startIndex] << 24 |
168-
@value[startIndex + 1] << 16 |
169-
@value[startIndex + 2] << 8 |
170-
@value[startIndex + 3]);
173+
return (UInt32)(
174+
(@value[startIndex] << 24) |
175+
(@value[startIndex + 1] << 16) |
176+
(@value[startIndex + 2] << 8) |
177+
@value[startIndex + 3]
178+
);
171179
}
172180

173181
[CLSCompliant(false)]
@@ -196,33 +204,41 @@ public static UInt64 ToUInt64LE(byte[] @value, int startIndex)
196204
{
197205
CheckSourceArray(@value, startIndex, 8);
198206

199-
UInt64 low = (UInt32)(@value[startIndex] |
200-
@value[startIndex + 1] << 8 |
201-
@value[startIndex + 2] << 16 |
202-
@value[startIndex + 3] << 24);
203-
UInt64 high = (UInt32)(@value[startIndex + 4 ] |
204-
@value[startIndex + 5] << 8 |
205-
@value[startIndex + 6] << 16 |
206-
@value[startIndex + 7] << 24);
207+
UInt64 low = (UInt32)(
208+
@value[startIndex] |
209+
(@value[startIndex + 1] << 8) |
210+
(@value[startIndex + 2] << 16) |
211+
(@value[startIndex + 3] << 24)
212+
);
213+
UInt64 high = (UInt32)(
214+
@value[startIndex + 4 ] |
215+
(@value[startIndex + 5] << 8) |
216+
(@value[startIndex + 6] << 16) |
217+
(@value[startIndex + 7] << 24)
218+
);
207219

208-
return high << 32 | low;
220+
return (high << 32) | low;
209221
}
210222

211223
[CLSCompliant(false)]
212224
public static UInt64 ToUInt64BE(byte[] @value, int startIndex)
213225
{
214226
CheckSourceArray(@value, startIndex, 8);
215227

216-
UInt64 high = (UInt32)(@value[startIndex] << 24 |
217-
@value[startIndex + 1] << 16 |
218-
@value[startIndex + 2] << 8 |
219-
@value[startIndex + 3]);
220-
UInt64 low = (UInt32)(@value[startIndex + 4] << 24 |
221-
@value[startIndex + 5] << 16 |
222-
@value[startIndex + 6] << 8 |
223-
@value[startIndex + 7]);
224-
225-
return high << 32 | low;
228+
UInt64 high = (UInt32)(
229+
(@value[startIndex] << 24) |
230+
(@value[startIndex + 1] << 16) |
231+
(@value[startIndex + 2] << 8) |
232+
@value[startIndex + 3]
233+
);
234+
UInt64 low = (UInt32)(
235+
(@value[startIndex + 4] << 24) |
236+
(@value[startIndex + 5] << 16) |
237+
(@value[startIndex + 6] << 8) |
238+
(@value[startIndex + 7])
239+
);
240+
241+
return (high << 32) | low;
226242
}
227243

228244
[CLSCompliant(false)]

src/Smdn.Fundamental.Stream.BinaryReaderWriter/Smdn.IO.Binary/BinaryReaderBase.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public virtual bool EndOfStream {
1717
CheckDisposed();
1818

1919
if (stream.CanSeek) {
20-
var eos = (stream.ReadByte() < 0);
20+
var eos = stream.ReadByte() < 0;
2121

2222
if (!eos)
2323
stream.Seek(-1L, SeekOrigin.Current);
@@ -34,9 +34,7 @@ public Stream BaseStream {
3434
get { CheckDisposed(); return stream; }
3535
}
3636

37-
protected bool Disposed {
38-
get { return disposed; }
39-
}
37+
protected bool Disposed { get; private set; } = false;
4038

4139
protected BinaryReaderBase(Stream baseStream, bool leaveBaseStreamOpen)
4240
{
@@ -68,10 +66,10 @@ protected virtual void Dispose(bool disposing)
6866
stream = null;
6967
}
7068

71-
disposed = true;
69+
Disposed = true;
7270
}
7371

74-
public virtual Byte ReadByte()
72+
public virtual byte ReadByte()
7573
{
7674
CheckDisposed();
7775

@@ -232,7 +230,7 @@ public virtual byte[] ReadToEnd()
232230
}
233231
else {
234232
var bufferSize = (int)Math.Min(4096L, remain);
235-
var initialCapacity = (int)Math.Min((long)int.MaxValue, remain);
233+
var initialCapacity = (int)Math.Min(int.MaxValue, remain);
236234

237235
return stream.ReadToEnd(bufferSize, initialCapacity);
238236
}
@@ -244,12 +242,11 @@ public virtual byte[] ReadToEnd()
244242

245243
protected void CheckDisposed()
246244
{
247-
if (disposed)
245+
if (Disposed)
248246
throw new ObjectDisposedException(GetType().FullName);
249247
}
250248

251249
private Stream stream;
252250
private readonly bool leaveBaseStreamOpen;
253-
private bool disposed = false;
254251
}
255252
}

src/Smdn.Fundamental.Stream.BinaryReaderWriter/Smdn.IO.Binary/BinaryWriterBase.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ public Stream BaseStream {
1717
get { CheckDisposed(); return stream; }
1818
}
1919

20-
protected bool Disposed {
21-
get { return disposed; }
22-
}
20+
protected bool Disposed { get; private set; } = false;
2321

2422
protected BinaryWriterBase(Stream baseStream, bool leaveBaseStreamOpen)
2523
{
@@ -51,7 +49,7 @@ protected virtual void Dispose(bool disposing)
5149
stream = null;
5250
}
5351

54-
disposed = true;
52+
Disposed = true;
5553
}
5654

5755
public void Flush()
@@ -165,12 +163,11 @@ public void WriteZero(long count)
165163

166164
protected void CheckDisposed()
167165
{
168-
if (disposed)
166+
if (Disposed)
169167
throw new ObjectDisposedException(GetType().FullName);
170168
}
171169

172170
private Stream stream;
173171
private readonly bool leaveBaseStreamOpen;
174-
private bool disposed = false;
175172
}
176173
}

src/Smdn.Fundamental.Stream.BinaryReaderWriter/Smdn.IO.Binary/EmptyByteArray.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// SPDX-FileCopyrightText: 2010 smdn <smdn@smdn.jp>
22
// SPDX-License-Identifier: MIT
3-
using System;
43

54
namespace Smdn.IO.Binary {
65
#if !SYSTEM_ARRAY_EMPTY

0 commit comments

Comments
 (0)