Skip to content

Commit 91162b1

Browse files
authored
Updated code to use the ArgumentOutOfRangeException throw helper (#8321)
1 parent 923558e commit 91162b1

File tree

11 files changed

+64
-77
lines changed

11 files changed

+64
-77
lines changed

.editorconfig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,14 @@ dotnet_naming_symbols.static_fields.applicable_accessibilities = private, intern
150150
dotnet_naming_style.static_prefix_style.required_prefix = s_
151151
dotnet_naming_style.static_prefix_style.capitalization = camel_case
152152

153-
# Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance.
153+
# Use ArgumentNullException throw helper.
154154
dotnet_diagnostic.CA1510.severity = warning
155-
# Use 'ArgumentException.ThrowIfNullOrEmpty' instead of explicitly throwing a new exception instance.
155+
# Use ArgumentException throw helper.
156156
dotnet_diagnostic.CA1511.severity = warning
157+
# Use ArgumentOutOfRangeException throw helper.
158+
dotnet_diagnostic.CA1512.severity = warning
157159

158160
[src/HotChocolate/Language/**/*.cs]
159161
dotnet_diagnostic.CA1510.severity = none
160162
dotnet_diagnostic.CA1511.severity = none
163+
dotnet_diagnostic.CA1512.severity = none

src/HotChocolate/Core/src/Execution.Abstractions/IndexerPathSegment.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ public sealed class IndexerPathSegment : Path
99
internal IndexerPathSegment(Path parent, int index)
1010
: base(parent)
1111
{
12-
if (index < 0)
13-
{
14-
throw new ArgumentOutOfRangeException(nameof(index));
15-
}
12+
ArgumentOutOfRangeException.ThrowIfNegative(index);
1613

1714
Index = index;
1815
}

src/HotChocolate/Core/src/Execution/Processing/Result/ResultData.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ public abstract class ResultData
4545
/// </param>
4646
public void SetParent(ResultData parent, int index)
4747
{
48-
if (index < 0)
49-
{
50-
throw new ArgumentOutOfRangeException(nameof(index));
51-
}
48+
ArgumentOutOfRangeException.ThrowIfNegative(index);
5249

5350
Parent = parent ?? throw new ArgumentNullException(nameof(parent));
5451
ParentIndex = index;

src/HotChocolate/Core/src/Features/FeatureCollection.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ public FeatureCollection()
3535
/// </exception>
3636
public FeatureCollection(int initialCapacity)
3737
{
38-
if (initialCapacity < 0)
39-
{
40-
throw new ArgumentOutOfRangeException(nameof(initialCapacity));
41-
}
38+
ArgumentOutOfRangeException.ThrowIfNegative(initialCapacity);
4239

4340
_initialCapacity = initialCapacity;
4441
}

src/HotChocolate/Core/src/Validation/DocumentValidatorContext.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,7 @@ public void Initialize(
146146
{
147147
ArgumentNullException.ThrowIfNull(schema);
148148
ArgumentNullException.ThrowIfNull(document);
149-
150-
if (maxAllowedErrors < 1)
151-
{
152-
throw new ArgumentOutOfRangeException(
153-
nameof(maxAllowedErrors),
154-
"The maximum allowed errors must be greater than 0.");
155-
}
149+
ArgumentOutOfRangeException.ThrowIfLessThan(maxAllowedErrors, 1);
156150

157151
_schema = schema;
158152
DocumentId = documentId;

src/HotChocolate/Fusion-vnext/src/Fusion.Language/Properties/FusionLanguageResources.Designer.cs

Lines changed: 47 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/HotChocolate/Fusion-vnext/src/Fusion.Language/Properties/FusionLanguageResources.resx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
<data name="MaxAllowedTokensExceeded" xml:space="preserve">
3131
<value>Source text contains more than {0} tokens. Parsing aborted.</value>
3232
</data>
33-
<data name="NewLineMustBeGreaterThanOrEqualToOne" xml:space="preserve">
34-
<value>Must be greater than or equal to 1.</value>
35-
</data>
3633
<data name="SourceTextCannotBeEmpty" xml:space="preserve">
3734
<value>The source text cannot be empty.</value>
3835
</data>

src/HotChocolate/Fusion-vnext/src/Fusion.Language/Readers/FieldSelectionMapReader.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,7 @@ private void NewLine()
237237
[MethodImpl(MethodImplOptions.AggressiveInlining)]
238238
private void NewLine(int lines)
239239
{
240-
if (lines < 1)
241-
{
242-
throw new ArgumentOutOfRangeException(
243-
nameof(lines),
244-
lines,
245-
NewLineMustBeGreaterThanOrEqualToOne);
246-
}
240+
ArgumentOutOfRangeException.ThrowIfLessThan(lines, 1);
247241

248242
Line += lines;
249243
LineStart = Position;

src/HotChocolate/Utilities/src/Utilities.Buffers/PooledArrayWriter.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ public void Advance(int count)
7878
throw new ObjectDisposedException(nameof(PooledArrayWriter));
7979
}
8080

81-
if (count < 0)
82-
{
83-
throw new ArgumentOutOfRangeException(nameof(count));
84-
}
81+
ArgumentOutOfRangeException.ThrowIfNegative(count);
8582

8683
if (count > _capacity)
8784
{
@@ -114,10 +111,7 @@ public Memory<byte> GetMemory(int sizeHint = 0)
114111
throw new ObjectDisposedException(nameof(PooledArrayWriter));
115112
}
116113

117-
if (sizeHint < 0)
118-
{
119-
throw new ArgumentOutOfRangeException(nameof(sizeHint));
120-
}
114+
ArgumentOutOfRangeException.ThrowIfNegative(sizeHint);
121115

122116
var size = sizeHint < 1
123117
? _initialBufferSize
@@ -145,10 +139,7 @@ public Span<byte> GetSpan(int sizeHint = 0)
145139
throw new ObjectDisposedException(nameof(PooledArrayWriter));
146140
}
147141

148-
if (sizeHint < 0)
149-
{
150-
throw new ArgumentOutOfRangeException(nameof(sizeHint));
151-
}
142+
ArgumentOutOfRangeException.ThrowIfNegative(sizeHint);
152143

153144
var size = sizeHint < 1 ? _initialBufferSize : sizeHint;
154145
EnsureBufferCapacity(size);

src/StrawberryShake/Client/src/Core/Internal/ArrayWriter.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ public void Advance(int count)
7676
throw new ObjectDisposedException(nameof(ArrayWriter));
7777
}
7878

79-
if (count < 0)
80-
{
81-
throw new ArgumentOutOfRangeException(nameof(count));
82-
}
79+
ArgumentOutOfRangeException.ThrowIfNegative(count);
8380

8481
if (count > _capacity)
8582
{
@@ -112,10 +109,7 @@ public Memory<byte> GetMemory(int sizeHint = 0)
112109
throw new ObjectDisposedException(nameof(ArrayWriter));
113110
}
114111

115-
if (sizeHint < 0)
116-
{
117-
throw new ArgumentOutOfRangeException(nameof(sizeHint));
118-
}
112+
ArgumentOutOfRangeException.ThrowIfNegative(sizeHint);
119113

120114
var size = sizeHint < 1
121115
? _initialBufferSize
@@ -143,10 +137,7 @@ public Span<byte> GetSpan(int sizeHint = 0)
143137
throw new ObjectDisposedException(nameof(ArrayWriter));
144138
}
145139

146-
if (sizeHint < 0)
147-
{
148-
throw new ArgumentOutOfRangeException(nameof(sizeHint));
149-
}
140+
ArgumentOutOfRangeException.ThrowIfNegative(sizeHint);
150141

151142
var size = sizeHint < 1
152143
? _initialBufferSize

0 commit comments

Comments
 (0)