ValidateArgumentsAttribute Class
Namespace: System.Management.Automation
Assembly: System.Management.Automation (in System.Management.Automation)
[AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field)] public abstract class ValidateArgumentsAttribute : CmdletMetadataAttribute
/** @attribute 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[] parameter, the string[] command argument is validated.
To create custom argument validation attributes, derive from the ValidateArgumentsAttribute class and override the following methods:
ValidateWhen 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.
ToStringIt is recommended to override ToString to return a readable string similar to the attribute declaration (for example, "[ValidateRangeAttribute(5,10)]").
System.Attribute
System.Management.Automation.Internal.CmdletMetadataAttribute
System.Management.Automation.ValidateArgumentsAttribute
System.Management.Automation.ValidateCountAttribute
System.Management.Automation.ValidateEnumeratedArgumentsAttribute
System.Management.Automation.ValidateNotNullAttribute
System.Management.Automation.ValidateNotNullOrEmptyAttribute
Target Platforms
Windows Developer Preview, Windows Server Developer PreviewSend comments about this topic to Microsoft.