Skip to content

Commit

Permalink
ArgumentException.ThrowIfNullOrEmpty
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Nov 13, 2024
1 parent 148c7ba commit 2093095
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion api_list.include.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#### ConcurrentBag<T>

* `void Clear<T>(ConcurrentBag<T>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.concurrent.concurrentbag-1.clear)
* `void Clear<T>()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.concurrent.concurrentbag-1.clear)


#### ConcurrentDictionary<TKey, TValue>
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,9 @@ using System.Diagnostics.CodeAnalysis;
struct UnscopedRefUsage
{
int field;
int field1;

[UnscopedRef] ref int Prop1 => ref field;
[UnscopedRef] ref int Prop1 => ref field1;
}
```
<sup><a href='/src/Consume/UnscopedRefUsage.cs#L1-L9' title='Snippet source file'>snippet source</a> | <a href='#snippet-UnscopedRefUsage.cs' title='Start of snippet'>anchor</a></sup>
Expand Down
7 changes: 4 additions & 3 deletions src/Polyfill/Guard_NotEmpty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ static partial class Guard
{
public static void NotEmpty(string? value, [CallerArgumentExpression("value")] string argumentName = "")
{
#if NET7_0_OR_GREATER
ArgumentException.ThrowIfNullOrEmpty(value, argumentName);
#else
if (value is null)
{
return;
}

#if NET7_0_OR_GREATER
ArgumentException.ThrowIfNullOrEmpty(value, argumentName);
#else

if (value.Length == 0)
{
throw new ArgumentException("Argument cannot be empty.", argumentName);
Expand Down
5 changes: 5 additions & 0 deletions src/Polyfill/Guard_NotNullOrEmpty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public static string NotNullOrEmpty(
[NotNull] string? value,
[CallerArgumentExpression("value")] string argumentName = "")
{
#if NET7_0_OR_GREATER
ArgumentException.ThrowIfNullOrEmpty(value, argumentName);
return value;
#else
if (value is null)
{
throw new ArgumentNullException(argumentName);
Expand All @@ -30,6 +34,7 @@ public static string NotNullOrEmpty(
}

return value;
#endif
}

public static T NotNullOrEmpty<T>(
Expand Down
1 change: 0 additions & 1 deletion src/Polyfill/Guard_NotWhiteSpace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public static void NotWhiteSpace(
}
#if NET8_0_OR_GREATER
ArgumentException.ThrowIfNullOrWhiteSpace(value, argumentName);
return value;
#else

if (value.Length == 0)
Expand Down

0 comments on commit 2093095

Please sign in to comment.