ValidateArgumentsAttribute ValidateArgumentsAttribute 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
type ValidateArgumentsAttribute = class
    inherit CmdletMetadataAttribute
Public MustInherit Class ValidateArgumentsAttribute
Inherits CmdletMetadataAttribute
Inheritance
ValidateArgumentsAttributeValidateArgumentsAttributeValidateArgumentsAttribute
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 ValidateArgumentsAttribute and override the Validate(Object, EngineIntrinsics) abstract method, after which they can apply the attribute to their parameters.

ValidateArgumentsAttribute validates the argument as a whole. If the argument value is potentially an enumeration, you can derive from ValidateEnumeratedArgumentsAttribute which will take care of unrolling the enumeration and validate each element individually.

It is also recommended to override ToString() 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() ValidateArgumentsAttribute() ValidateArgumentsAttribute()

Initializes a new instance of a class derived from ValidateArgumentsAttribute

Methods

Validate(Object, EngineIntrinsics) Validate(Object, EngineIntrinsics) Validate(Object, EngineIntrinsics)

Overridden by subclasses to implement the validation of the parameter arguments

Applies to