Dela via


ValidateArgumentsAttribute Class

Definition

Serves as the base class for Validate attributes that validate parameter arguments.

public ref class ValidateArgumentsAttribute abstract : System::Management::Automation::Internal::CmdletMetadataAttribute
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property)]
public abstract class ValidateArgumentsAttribute : System.Management.Automation.Internal.CmdletMetadataAttribute
[<System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property)>]
type ValidateArgumentsAttribute = class
    inherit CmdletMetadataAttribute
Public MustInherit Class ValidateArgumentsAttribute
Inherits CmdletMetadataAttribute
Inheritance
ValidateArgumentsAttribute
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 may be an enumerable, you can derive from ValidateEnumeratedArgumentsAttribute which will take care of unrolling the enumerable 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()

Initializes a new instance of a class derived from ValidateArgumentsAttribute.

Methods

Validate(Object, EngineIntrinsics)

Verify that the value of arguments is valid.

Applies to

See also