-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API Proposal]: ArgumentException.ThrowIfNullOrEmpty
for collection
#86830
Comments
This was discussed and rejected in #62628 (comment) : We don't believe we need an overload of |
Tagging subscribers to this area: @dotnet/area-system-runtime Issue DetailsBackground and motivationSometimes, we may also need to check if a collection is empty just likes the for example: runtime/src/mono/wasm/host/RunConfiguration.cs Lines 46 to 47 in 7173823
API Proposalnamespace System;
public class ArgumentException : SystemException
{
public static void ThrowIfNullOrEmpty<T>([NotNull]ICollection<T>? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
{
ArgumentNullException.ThrowIfNull(argument, paramName);
if (argument.Count == 0)
{
throw new ArgumentException("The collection is empty...", paramName);
}
}
} API Usagevar arr = Array.Empty<int>();
ArgumentException.ThrowIfNullOrEmpty();
// throwing the ArgumentException out Alternative DesignsNo response RisksNo response
|
Also here: |
Background and motivation
Sometimes, we may also need to check if a collection is empty just likes the
string.IsNullOrEmpty
for example:
runtime/src/mono/wasm/host/RunConfiguration.cs
Lines 46 to 47 in 7173823
https://github.com/Azure/azure-sdk-for-net/blob/aea202adfea6f1dbb117ab9f8f3cde7028d8d2d1/sdk/core/Azure.Core/src/Shared/Argument.cs#L82-L84
API Proposal
API Usage
Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: