CommunityToolkit / dotnet

.NET Community Toolkit is a collection of helpers and APIs that work for all .NET developers and are agnostic of any specific UI platform. The toolkit is maintained and published by Microsoft, and part of the .NET Foundation.
https://docs.microsoft.com/dotnet/communitytoolkit/?WT.mc_id=dotnet-0000-bramin
Other
2.99k stars 294 forks source link

Fix Guard IsWhiteSpace and IsNotWhiteSpace Methods #650

Open GabrieleMessina opened 1 year ago

GabrieleMessina commented 1 year ago

Closes #441

Fixed Guard IsWhiteSpace and IsNotWhiteSpace methods adding a check for null before calling string.IsNullOrWhiteSpace. Added some tests for both methods.

PR Checklist

Other information

I don't know if this can be considered a breaking change.

cremor commented 1 year ago

In my opinion those methods are still confusing with this PR. Why does "white space" include an empty string, but doesn't include null? Neither are white-space characters. Just from the method name I'd assume that an empty string would fail the Guard.IsWhiteSpace call.

But I can see how the method name is similar to String.IsNullOrWhiteSpace, which also includes empty strings. But that method also explicitly mentions empty strings in its documentation.

So, at least I'd suggest to change the documentation of those methods to also mention empty strings. For even better distinction I would suggest to only allow white-space characters in Guard.IsWhiteSpace and add additional methods for Guard.IsEmptyOrWhiteSpace.

GabrieleMessina commented 1 year ago

@cremor I think you have a point. I'll change the code as soon as I can. I'm not so sure, though, about the new Guard.IsEmptyOrWhiteSpace method because it can be achieved using a combination of the other Guard methods and I don't think it'll be widely used.