Skip to content
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.ThrowIfNullOrWhiteSpace(string) #80986

Closed
Marusyk opened this issue Jan 22, 2023 · 2 comments
Closed

[API Proposal]: ArgumentException.ThrowIfNullOrWhiteSpace(string) #80986

Marusyk opened this issue Jan 22, 2023 · 2 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation

Comments

@Marusyk
Copy link
Member

Marusyk commented Jan 22, 2023

Background and motivation

Inspired by ArgumentNullException.ThrowIfNull(object) and ArgumentException.ThrowIfNullOrEmpty from #62628.
string.IsNullOrWhiteSpace(text) is a frequent check, especially in Web/Console projects.

Now:

if (string.IsNullOrWhiteSpace(input))
{ 
     throw new ArgumentException($"{nameof(input)} must contain value.");
}

API Proposal

namespace System
{
    public class ArgumentException : SystemException
    {
        public static void ThrowIfNullOrWhiteSpace([NotNull] string? argument, [CallerArgumentExpression("argument")] string? paramName = null)
    }
}

API Usage

string input = " ";
ArgumentException.ThrowIfNullOrWhiteSpace(input);

Alternative Designs

Define it as an extension method

public static void ThrowIfNullOrWhiteSpace(this [NotNull] string? argument, [CallerArgumentExpression("argument")] string? paramName = null)

Risks

No response

@Marusyk Marusyk added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Jan 22, 2023
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jan 22, 2023
@stephentoub
Copy link
Member

Duplicate of #77749

@stephentoub stephentoub marked this as a duplicate of #77749 Jan 22, 2023
@stephentoub stephentoub closed this as not planned Won't fix, can't repro, duplicate, stale Jan 22, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Jan 22, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Feb 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation
Projects
None yet
Development

No branches or pull requests

2 participants