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 鈥淪ign up for GitHub鈥, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ValidateNotNullOrWhiteSpace Attribute #17191
Add ValidateNotNullOrWhiteSpace Attribute #17191
Conversation
Acts identically to ValidateNotNullOrEmpty, except this attribute will now also check if argument consists entirely of white-space.
|
@JamesWTruher Can you please take a look and see if this change is something we want to take? My concern is that any commands using this attribute won't work on downlevel PowerShell versions, which may make this attribute less interesting to module authors, until all downlevel versions are out of support. |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
@JamesWTruher gentle ping :) |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
I think this is fine. We have plenty of examples of new behaviors which will not be available down level. |
|
@daxian-dbw gentle ping |
@wmentha Sorry for the long delay of review. The changes look good overall, thanks for that!
My comments are mainly about style changes and comment/error string improvements. Please take a look and let me know if you have any concerns.
Added extra ValidateAttributesTests to check for scalar values.
Added extra ValidateAttributesTests to check for scalar values.
鈥�.com/wmentha/PowerShell into ValidateNotNullOrWhiteSpaceAttribute
Added extra ValidateAttributesTests to check for scalar values.
鈥�.com/wmentha/PowerShell into ValidateNotNullOrWhiteSpaceAttribute
|
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? |
|
@daxian-dbw Apologies for the mess of commits. I got tripped up on the new |
|
Handy links: |


PR Summary
Adds
ValidateNotNullOrWhiteSpacetoSystem.Management.AutomationPR Context
Closes #10010
Currently, users who want to validate a string or collection of strings will add the
[ValidateNotNullOrEmpty()]attribute to it and then manually validate the string with[String]::IsNullOrWhiteSpace(my_string).Alternate implentation @vexx32 suggested could have been a bool argument to ValidateNotNullOrEmpy:
ValidateNotNullOrEmpty(WhiteSpace). However I have chosen to implement this as a seperate attribute as users who work with strings know to use a seperate attribute when validating them:ValidateNotNullOrEmptyas opposed toValidateNotNull.ValidateNotNullOrEmptyadds a further requirement for the validation overValidateNotNull. LikewiseValidateNotNullOrWhiteSpaceadds the further requirement of no strings consisting entirely of white-space overValidateNotNullOrEmpty.Also, this is my first commit馃槉
Class Diagram Before
classDiagram ValidateArgumentsAttribute <|-- NullValidationAttributeBase NullValidationAttributeBase <|-- ValidateNotNullAttribute NullValidationAttributeBase <|-- ValidateNotNullOrEmptyAttribute class ValidateArgumentsAttribute { <<abstract>> #Validate(object arguments, EngineIntrinsics engineIntrinsics)* void } class NullValidationAttributeBase { <<abstract>> #IsArgumentCollection(Type argumentType, out bool isElementValueType) bool } class ValidateNotNullAttribute{ #Validate(object arguments, EngineIntrinsics engineIntrinsics) void } class ValidateNotNullOrEmptyAttribute{ #Validate(object arguments, EngineIntrinsics engineIntrinsics) void }Class Diagram After
classDiagram ValidateArgumentsAttribute <|-- NullValidationAttributeBase NullValidationAttributeBase <|-- ValidateNotNullAttribute NullValidationAttributeBase <|-- ValidateNotNullOr ValidateNotNullOr <|-- ValidateNotNullOrEmptyAttribute ValidateNotNullOr <|-- ValidateNotNullOrWhiteSpaceAttribute class ValidateArgumentsAttribute { <<abstract>> #Validate(object arguments, EngineIntrinsics engineIntrinsics)* void } class NullValidationAttributeBase { <<abstract>> #IsArgumentCollection(Type argumentType, out bool isElementValueType) bool } class ValidateNotNullAttribute{ #Validate(object arguments, EngineIntrinsics engineIntrinsics) void } class ValidateNotNullOr{ <<abstract>> #bool _whiteSpace #ValidateNotNullOr(bool whiteSpace)* #Validate(object arguments, EngineIntrinsics engineIntrinsics) void } class ValidateNotNullOrEmptyAttribute { +ValidateNotNullOrEmptyAttribute(bool whiteSpace) } class ValidateNotNullOrWhiteSpaceAttribute { +ValidateNotNullOrWhiteSpaceAttribute(bool whiteSpace) }PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.