Skip to content

Commit cda7474

Browse files
committed
Use nameof for ArgumentExceptions
1 parent 54aaa47 commit cda7474

19 files changed

+103
-103
lines changed

fNbt.Test/PartialReadStream.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public PartialReadStream([NotNull] Stream baseStream)
1212

1313

1414
public PartialReadStream([NotNull] Stream baseStream, int increment) {
15-
if (baseStream == null) throw new ArgumentNullException("baseStream");
15+
if (baseStream == null) throw new ArgumentNullException(nameof(baseStream));
1616
this.baseStream = baseStream;
1717
this.increment = increment;
1818
}

fNbt/NbtBinaryReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public override string ReadString() {
109109

110110
public void Skip(int bytesToSkip) {
111111
if (bytesToSkip < 0) {
112-
throw new ArgumentOutOfRangeException("bytesToSkip");
112+
throw new ArgumentOutOfRangeException(nameof(bytesToSkip));
113113
} else if (BaseStream.CanSeek) {
114114
BaseStream.Position += bytesToSkip;
115115
} else if (bytesToSkip != 0) {

fNbt/NbtBinaryWriter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public Stream BaseStream {
3939

4040

4141
public NbtBinaryWriter([NotNull] Stream input, bool bigEndian) {
42-
if (input == null) throw new ArgumentNullException("input");
43-
if (!input.CanWrite) throw new ArgumentException("Given stream must be writable", "input");
42+
if (input == null) throw new ArgumentNullException(nameof(input));
43+
if (!input.CanWrite) throw new ArgumentException("Given stream must be writable", nameof(input));
4444
stream = input;
4545
swapNeeded = (BitConverter.IsLittleEndian == bigEndian);
4646
}
@@ -163,7 +163,7 @@ public void Write(double value) {
163163
// Based on BinaryWriter.Write(String)
164164
public void Write([NotNull] string value) {
165165
if (value == null) {
166-
throw new ArgumentNullException("value");
166+
throw new ArgumentNullException(nameof(value));
167167
}
168168

169169
// Write out string length (as number of bytes)

fNbt/NbtFile.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public sealed class NbtFile {
2828
public NbtCompound RootTag {
2929
get { return rootTag; }
3030
set {
31-
if (value == null) throw new ArgumentNullException("value");
31+
if (value == null) throw new ArgumentNullException(nameof(value));
3232
if (value.Name == null) throw new ArgumentException("Root tag must be named.");
3333
rootTag = value;
3434
}
@@ -50,7 +50,7 @@ public static int DefaultBufferSize {
5050
get { return defaultBufferSize; }
5151
set {
5252
if (value < 0) {
53-
throw new ArgumentOutOfRangeException("value", value, "DefaultBufferSize cannot be negative.");
53+
throw new ArgumentOutOfRangeException(nameof(value), value, "DefaultBufferSize cannot be negative.");
5454
}
5555
defaultBufferSize = value;
5656
}
@@ -65,7 +65,7 @@ public int BufferSize {
6565
get { return bufferSize; }
6666
set {
6767
if (value < 0) {
68-
throw new ArgumentOutOfRangeException("value", value, "BufferSize cannot be negative.");
68+
throw new ArgumentOutOfRangeException(nameof(value), value, "BufferSize cannot be negative.");
6969
}
7070
bufferSize = value;
7171
}
@@ -96,7 +96,7 @@ public NbtFile() {
9696
/// <exception cref="ArgumentException"> If given <paramref name="rootTag"/> is unnamed. </exception>
9797
public NbtFile([NotNull] NbtCompound rootTag)
9898
: this() {
99-
if (rootTag == null) throw new ArgumentNullException("rootTag");
99+
if (rootTag == null) throw new ArgumentNullException(nameof(rootTag));
100100
RootTag = rootTag;
101101
}
102102

@@ -112,7 +112,7 @@ public NbtFile([NotNull] NbtCompound rootTag)
112112
/// <exception cref="IOException"> If an I/O error occurred while reading the file. </exception>
113113
public NbtFile([NotNull] string fileName)
114114
: this() {
115-
if (fileName == null) throw new ArgumentNullException("fileName");
115+
if (fileName == null) throw new ArgumentNullException(nameof(fileName));
116116
LoadFromFile(fileName, NbtCompression.AutoDetect, null);
117117
}
118118

@@ -149,7 +149,7 @@ public long LoadFromFile([NotNull] string fileName) {
149149
/// <exception cref="NbtFormatException"> If an error occurred while parsing data in NBT format. </exception>
150150
/// <exception cref="IOException"> If an I/O error occurred while reading the file. </exception>
151151
public long LoadFromFile([NotNull] string fileName, NbtCompression compression, [CanBeNull] TagSelector selector) {
152-
if (fileName == null) throw new ArgumentNullException("fileName");
152+
if (fileName == null) throw new ArgumentNullException(nameof(fileName));
153153

154154
using (
155155
var readFileStream = new FileStream(fileName,
@@ -183,7 +183,7 @@ public long LoadFromFile([NotNull] string fileName, NbtCompression compression,
183183
/// <exception cref="NbtFormatException"> If an error occurred while parsing data in NBT format. </exception>
184184
public long LoadFromBuffer([NotNull] byte[] buffer, int index, int length, NbtCompression compression,
185185
[CanBeNull] TagSelector selector) {
186-
if (buffer == null) throw new ArgumentNullException("buffer");
186+
if (buffer == null) throw new ArgumentNullException(nameof(buffer));
187187

188188
using (var ms = new MemoryStream(buffer, index, length)) {
189189
LoadFromStream(ms, compression, selector);
@@ -208,7 +208,7 @@ public long LoadFromBuffer([NotNull] byte[] buffer, int index, int length, NbtCo
208208
/// <exception cref="InvalidDataException"> If file compression could not be detected or decompressing failed. </exception>
209209
/// <exception cref="NbtFormatException"> If an error occurred while parsing data in NBT format. </exception>
210210
public long LoadFromBuffer([NotNull] byte[] buffer, int index, int length, NbtCompression compression) {
211-
if (buffer == null) throw new ArgumentNullException("buffer");
211+
if (buffer == null) throw new ArgumentNullException(nameof(buffer));
212212

213213
using (var ms = new MemoryStream(buffer, index, length)) {
214214
LoadFromStream(ms, compression, null);
@@ -231,7 +231,7 @@ public long LoadFromBuffer([NotNull] byte[] buffer, int index, int length, NbtCo
231231
/// <exception cref="InvalidDataException"> If file compression could not be detected, decompressing failed, or given stream does not support reading. </exception>
232232
/// <exception cref="NbtFormatException"> If an error occurred while parsing data in NBT format. </exception>
233233
public long LoadFromStream([NotNull] Stream stream, NbtCompression compression, [CanBeNull] TagSelector selector) {
234-
if (stream == null) throw new ArgumentNullException("stream");
234+
if (stream == null) throw new ArgumentNullException(nameof(stream));
235235

236236
FileName = null;
237237

@@ -280,7 +280,7 @@ public long LoadFromStream([NotNull] Stream stream, NbtCompression compression,
280280
break;
281281

282282
default:
283-
throw new ArgumentOutOfRangeException("compression");
283+
throw new ArgumentOutOfRangeException(nameof(compression));
284284
}
285285

286286
// report bytes read
@@ -375,7 +375,7 @@ void LoadFromStreamInternal([NotNull] Stream stream, [CanBeNull] TagSelector tag
375375
/// <exception cref="NbtFormatException"> If one of the NbtCompound tags contained unnamed tags;
376376
/// or if an NbtList tag had Unknown list type and no elements. </exception>
377377
public long SaveToFile([NotNull] string fileName, NbtCompression compression) {
378-
if (fileName == null) throw new ArgumentNullException("fileName");
378+
if (fileName == null) throw new ArgumentNullException(nameof(fileName));
379379

380380
using (
381381
var saveFile = new FileStream(fileName,
@@ -403,7 +403,7 @@ public long SaveToFile([NotNull] string fileName, NbtCompression compression) {
403403
/// <exception cref="NbtFormatException"> If one of the NbtCompound tags contained unnamed tags;
404404
/// or if an NbtList tag had Unknown list type and no elements. </exception>
405405
public long SaveToBuffer([NotNull] byte[] buffer, int index, NbtCompression compression) {
406-
if (buffer == null) throw new ArgumentNullException("buffer");
406+
if (buffer == null) throw new ArgumentNullException(nameof(buffer));
407407

408408
using (var ms = new MemoryStream(buffer, index, buffer.Length - index)) {
409409
return SaveToStream(ms, compression);
@@ -442,7 +442,7 @@ public byte[] SaveToBuffer(NbtCompression compression) {
442442
/// or if one of the NbtCompound tags contained unnamed tags;
443443
/// or if an NbtList tag had Unknown list type and no elements. </exception>
444444
public long SaveToStream([NotNull] Stream stream, NbtCompression compression) {
445-
if (stream == null) throw new ArgumentNullException("stream");
445+
if (stream == null) throw new ArgumentNullException(nameof(stream));
446446

447447
switch (compression) {
448448
case NbtCompression.AutoDetect:
@@ -452,7 +452,7 @@ public long SaveToStream([NotNull] Stream stream, NbtCompression compression) {
452452
case NbtCompression.None:
453453
break;
454454
default:
455-
throw new ArgumentOutOfRangeException("compression");
455+
throw new ArgumentOutOfRangeException(nameof(compression));
456456
}
457457

458458
if (rootTag.Name == null) {
@@ -546,13 +546,13 @@ public static string ReadRootTagName([NotNull] string fileName) {
546546
public static string ReadRootTagName([NotNull] string fileName, NbtCompression compression, bool bigEndian,
547547
int bufferSize) {
548548
if (fileName == null) {
549-
throw new ArgumentNullException("fileName");
549+
throw new ArgumentNullException(nameof(fileName));
550550
}
551551
if (!File.Exists(fileName)) {
552552
throw new FileNotFoundException("Could not find the given NBT file.", fileName);
553553
}
554554
if (bufferSize < 0) {
555-
throw new ArgumentOutOfRangeException("bufferSize", bufferSize, "DefaultBufferSize cannot be negative.");
555+
throw new ArgumentOutOfRangeException(nameof(bufferSize), bufferSize, "DefaultBufferSize cannot be negative.");
556556
}
557557
using (FileStream readFileStream = File.OpenRead(fileName)) {
558558
return ReadRootTagName(readFileStream, compression, bigEndian, bufferSize);
@@ -575,9 +575,9 @@ public static string ReadRootTagName([NotNull] string fileName, NbtCompression c
575575
[NotNull]
576576
public static string ReadRootTagName([NotNull] Stream stream, NbtCompression compression, bool bigEndian,
577577
int bufferSize) {
578-
if (stream == null) throw new ArgumentNullException("stream");
578+
if (stream == null) throw new ArgumentNullException(nameof(stream));
579579
if (bufferSize < 0) {
580-
throw new ArgumentOutOfRangeException("bufferSize", bufferSize, "DefaultBufferSize cannot be negative.");
580+
throw new ArgumentOutOfRangeException(nameof(bufferSize), bufferSize, "DefaultBufferSize cannot be negative.");
581581
}
582582
// detect compression, based on the first byte
583583
if (compression == NbtCompression.AutoDetect) {
@@ -611,7 +611,7 @@ public static string ReadRootTagName([NotNull] Stream stream, NbtCompression com
611611
}
612612

613613
default:
614-
throw new ArgumentOutOfRangeException("compression");
614+
throw new ArgumentOutOfRangeException(nameof(compression));
615615
}
616616
}
617617

fNbt/NbtReader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public NbtReader([NotNull] Stream stream)
3232
/// <exception cref="ArgumentNullException"> <paramref name="stream"/> is <c>null</c>. </exception>
3333
/// <exception cref="ArgumentException"> <paramref name="stream"/> is not readable. </exception>
3434
public NbtReader([NotNull] Stream stream, bool bigEndian) {
35-
if (stream == null) throw new ArgumentNullException("stream");
35+
if (stream == null) throw new ArgumentNullException(nameof(stream));
3636
SkipEndTags = true;
3737
CacheTagValues = false;
3838
ParentTagType = NbtTagType.Unknown;
@@ -902,7 +902,7 @@ public string ToString(bool includeValue) {
902902
/// <param name="includeValue"> If set to <c>true</c>, also reads and prints the current tag's value. </param>
903903
[NotNull]
904904
public string ToString(bool includeValue, [NotNull] string indentString) {
905-
if (indentString == null) throw new ArgumentNullException("indentString");
905+
if (indentString == null) throw new ArgumentNullException(nameof(indentString));
906906
var sb = new StringBuilder();
907907
for (int i = 0; i < Depth; i++) {
908908
sb.Append(indentString);

0 commit comments

Comments
 (0)