Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ValidateArgumentsAttribute Class

 

Updated: April 27, 2016

Applies To: Windows PowerShell

Serves as the base class for all validation attributes that validate cmdlet parameter arguments.

Namespace:   System.Management.Automation
Assembly:  System.Management.Automation (in System.Management.Automation.dll)


<AttributeUsageAttribute(AttributeTargets.Property Or AttributeTargets.Field)>
Public MustInherit Class ValidateArgumentsAttribute
	Inherits CmdletMetadataAttribute

NameDescription
System_CAPS_protmethodValidateArgumentsAttribute()

Initializes a new instance of the ValidateArgumentsAttribute class.

NameDescription
System_CAPS_pubpropertyTypeId

(Inherited from Attribute.)

NameDescription
System_CAPS_pubmethodEquals(Object)

(Inherited from Attribute.)

System_CAPS_protmethodFinalize()

(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

(Inherited from Attribute.)

System_CAPS_pubmethodGetType()

(Inherited from Object.)

System_CAPS_pubmethodIsDefaultAttribute()

(Inherited from Attribute.)

System_CAPS_pubmethodMatch(Object)

(Inherited from Attribute.)

System_CAPS_protmethodMemberwiseClone()

(Inherited from Object.)

System_CAPS_pubmethodToString()

(Inherited from Object.)

System_CAPS_protmethodValidate(Object, EngineIntrinsics)

When overridden in a derived class, validates an argument value.

Validation attributes can be attached to cmdlet parameters to ensure that the cmdlet is not invoked with values that are not valid for its parameters. Validation attributes classes that derive from this class are listed in the Inheritance Hierarchy section of this topic.

Validation attribute classes can derive from two base classes. Attribute classes that derive from the ValidateArgumentsAttribute class validate the argument as a whole. Attribute classes that derive from the ValidateEnumeratedArgumentsAttribute class unroll enumerations and then validate each element individually.

When validation attributes are applied to a string parameter, the string command argument is validated. When validation attributes are applied to a string array parameter, the string array command argument is validated.

To create custom argument validation attributes, derive from the ValidateArgumentsAttribute class and override the following methods:

Validate

When this method is overridden, the attribute can be attached to a parameter to validate the argument value. Be aware that this method is protected, which means that the override must also be protected.

ToString

It is recommended to override ToString to return a readable string similar to the attribute declaration (for example, "[ValidateRangeAttribute(5,10)]").

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top

Community Additions

Show: