Background and motivation
Inspired by ArgumentNullException.ThrowIfNull(object). string.IsNullOrEmpty(text) is a frequent check especially in web/Console project. At first I thought InvalidDataException would be the best name but it is in System.IO namespace, so I think the closest should be ArgumentException so user doesn't need to import that namespace.
Now:
if (string.IsNullOrEmpty(input)) { throw new ArgumentException($"{nameof(input)} must contain value."); }
If the API is approved:
ArgumentException.ThrowIfNullOrEmpty(input);
While we are at it, personally I rarely use it but maybe ThrowIfNullOrWhiteSpace may be useful for others as well?
API Proposal
namespace System
{
public class ArgumentException : SystemException
{
public static void ThrowIfNullOrEmpty([NotNull] string? argument, [CallerArgumentExpression("argument")] string? paramName = null)
}
}
API Usage
ArgumentException.ThrowIfNullOrEmpty(input);
Alternative Designs
No response
Risks
No response
Background and motivation
Inspired by
ArgumentNullException.ThrowIfNull(object).string.IsNullOrEmpty(text)is a frequent check especially in web/Console project. At first I thoughtInvalidDataExceptionwould be the best name but it is inSystem.IOnamespace, so I think the closest should beArgumentExceptionso user doesn't need to import that namespace.Now:
If the API is approved:
While we are at it, personally I rarely use it but maybe
ThrowIfNullOrWhiteSpacemay be useful for others as well?API Proposal
API Usage
Alternative Designs
No response
Risks
No response