Skip to content

Commit 923558e

Browse files
authored
Updated code to use the ArgumentException throw helper (#8320)
1 parent e4ac690 commit 923558e

File tree

60 files changed

+811
-812
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+811
-812
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ dotnet_naming_style.static_prefix_style.capitalization = camel_case
152152

153153
# Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance.
154154
dotnet_diagnostic.CA1510.severity = warning
155+
# Use 'ArgumentException.ThrowIfNullOrEmpty' instead of explicitly throwing a new exception instance.
156+
dotnet_diagnostic.CA1511.severity = warning
155157

156158
[src/HotChocolate/Language/**/*.cs]
157159
dotnet_diagnostic.CA1510.severity = none
160+
dotnet_diagnostic.CA1511.severity = none

src/CookieCrumble/src/CookieCrumble/Snapshot.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,21 +183,15 @@ public Snapshot Add(SnapshotValue value)
183183

184184
public Snapshot SetExtension(string extension)
185185
{
186-
if (string.IsNullOrEmpty(extension))
187-
{
188-
throw new ArgumentNullException(nameof(extension));
189-
}
186+
ArgumentException.ThrowIfNullOrEmpty(extension);
190187

191188
_extension = extension;
192189
return this;
193190
}
194191

195192
public Snapshot SetPostFix(string postFix)
196193
{
197-
if (string.IsNullOrEmpty(postFix))
198-
{
199-
throw new ArgumentNullException(nameof(postFix));
200-
}
194+
ArgumentException.ThrowIfNullOrEmpty(postFix);
201195

202196
_postFix = postFix;
203197
return this;

src/GreenDonut/src/GreenDonut/DataLoaderBase.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,7 @@ public IDataLoader Branch<TState>(
278278
CreateDataLoaderBranch<TKey, TValue, TState> createBranch,
279279
TState state)
280280
{
281-
if (string.IsNullOrEmpty(key))
282-
{
283-
throw new ArgumentException("Value cannot be null or empty.", nameof(key));
284-
}
285-
281+
ArgumentException.ThrowIfNullOrEmpty(key);
286282
ArgumentNullException.ThrowIfNull(createBranch);
287283

288284
if (!AllowBranching)

src/GreenDonut/src/GreenDonut/Extensions/DataLoaderExtensions.cs

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -295,13 +295,7 @@ public static IDataLoader<TKey, TValue> SetState<TKey, TValue, TState>(
295295
where TKey : notnull
296296
{
297297
ArgumentNullException.ThrowIfNull(dataLoader);
298-
299-
if (string.IsNullOrEmpty(key))
300-
{
301-
throw new ArgumentException(
302-
"The key must not be null or empty.",
303-
nameof(key));
304-
}
298+
ArgumentException.ThrowIfNullOrEmpty(key);
305299

306300
dataLoader.ContextData = dataLoader.ContextData.SetItem(key, value);
307301
return dataLoader;
@@ -378,13 +372,7 @@ public static IDataLoader<TKey, TValue> TrySetState<TKey, TValue, TState>(
378372
where TKey : notnull
379373
{
380374
ArgumentNullException.ThrowIfNull(dataLoader);
381-
382-
if (string.IsNullOrEmpty(key))
383-
{
384-
throw new ArgumentException(
385-
"The key must not be null or empty.",
386-
nameof(key));
387-
}
375+
ArgumentException.ThrowIfNullOrEmpty(key);
388376

389377
if (!dataLoader.ContextData.ContainsKey(key))
390378
{
@@ -475,13 +463,7 @@ public static TState GetOrSetState<TKey, TValue, TState>(
475463
where TKey : notnull
476464
{
477465
ArgumentNullException.ThrowIfNull(dataLoader);
478-
479-
if (string.IsNullOrEmpty(key))
480-
{
481-
throw new ArgumentException(
482-
"The key must not be null or empty.",
483-
nameof(key));
484-
}
466+
ArgumentException.ThrowIfNullOrEmpty(key);
485467

486468
if(!dataLoader.ContextData.TryGetValue(key, out var internalValue))
487469
{
@@ -563,13 +545,7 @@ public static IDataLoader<TKey, TValue> AddStateEnumerable<TKey, TValue, TState>
563545
where TKey : notnull
564546
{
565547
ArgumentNullException.ThrowIfNull(dataLoader);
566-
567-
if (string.IsNullOrEmpty(key))
568-
{
569-
throw new ArgumentException(
570-
"The key must not be null or empty.",
571-
nameof(key));
572-
}
548+
ArgumentException.ThrowIfNullOrEmpty(key);
573549

574550
if (dataLoader.ContextData.TryGetValue(key, out var internalValue)
575551
&& internalValue is ImmutableArray<TState> values)

0 commit comments

Comments
 (0)