ValidateArgumentsAttribute
Class
Definition
Serves as the base class for Validate attributes that validate parameter arguments.
[System.AttributeUsage(System.AttributeTargets.Property | System.AttributeTargets.Field)]
public abstract class ValidateArgumentsAttribute : System.Management.Automation.Internal.CmdletMetadataAttribute
- Inheritance
- Derived
- Attributes
Remarks
Argument validation attributes can be attached to Cmdlet and CmdletProvider parameters to ensure that the Cmdlet or CmdletProvider will not be invoked with invalid values of the parameter. Existing validation attributes include ValidateCountAttribute, ValidateNotNullAttribute, ValidateNotNullOrEmptyAttribute, ValidateArgumentsAttribute, ValidateLengthAttribute, ValidateRangeAttribute, ValidatePatternAttribute, and ValidateSetAttribute.
PSSnapins wishing to create custom argument validation attributes
should derive from
<xref href="System.Management.Automation.ValidateArgumentsAttribute"></xref>
and override the
<xref href="System.Management.Automation.ValidateArgumentsAttribute.Validate(System.Object,System.Management.Automation.EngineIntrinsics)"></xref>
abstract method, after which they can apply the
attribute to their parameters.
<xref href="System.Management.Automation.ValidateArgumentsAttribute"></xref> validates the argument
as a whole. If the argument value is potentially an enumeration,
you can derive from <xref href="System.Management.Automation.ValidateEnumeratedArgumentsAttribute"></xref>
which will take care of unrolling the enumeration
and validate each element individually.
It is also recommended to override
<xref href="System.Object.ToString"></xref> to return a readable string
similar to the attribute declaration, for example
"[ValidateRangeAttribute(5,10)]".
If this attribute is applied to a string parameter, the string command argument will be validated.
If this attribute is applied to a string[] parameter, the string[] command argument will be validated.
Constructors
| ValidateArgumentsAttribute() |
Initializes a new instance of a class derived from ValidateArgumentsAttribute |
Methods
| Validate(Object, EngineIntrinsics) |
Overridden by subclasses to implement the validation of the parameter arguments |