Export (0) Print
Expand All

ValidateArgumentsAttribute Class

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)

'Usage
Dim instance As ValidateArgumentsAttribute

'Declaration
<AttributeUsageAttribute(AttributeTargets.Property Or AttributeTargets.Field)> _
Public MustInherit Class ValidateArgumentsAttribute
	Inherits CmdletMetadataAttribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field) */ 
public abstract class ValidateArgumentsAttribute extends CmdletMetadataAttribute
AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field) 
public abstract class ValidateArgumentsAttribute extends CmdletMetadataAttribute

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.

 

Target Platforms

Windows Developer Preview, Windows Server Developer Preview

Send comments about this topic to Microsoft.
Show:
© 2014 Microsoft