-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Suggestion: Duck-typing ValidateProperty attribute #7835
Copy link
Copy link
Closed
Labels
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime
Metadata
Metadata
Assignees
Labels
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime
I'd like to propose adding a
ValidatePropertiesattribute which would make it easier to validate that an incoming object had specific properties.Hypothetically, use of it might look something like this:
The idea being that this would ensure that the InputObject has a
SourceFileproperty of typestringand aSourceLineNumberproperty of typeint...Or you might even just do:
Which would just validate the properties exist, and not their types.
We might even extend it with a
NotNullOrEmptycheck ...Obviously I can add this in an external module, and I can do this validation with a
ValidateScript... but it seems like something that's generally useful (along the lines of the[PSTypeName()]attribute, but with the focus being on the shape of the object, rather than the name.Thoughts?