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.

ValidateLengthAttribute Class

 

Updated: April 27, 2016

Applies To: Windows PowerShell

Defines an attribute that uses minimum and maximum limits to validate the number of characters in a cmdlet parameter argument. (This attribute can also be used by Windows PowerShell functions.) This class cannot be inherited.

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


[AttributeUsageAttribute(AttributeTargets.Property | AttributeTargets.Field)]
public sealed class ValidateLengthAttribute : ValidateEnumeratedArgumentsAttribute

NameDescription
System_CAPS_pubmethodValidateLengthAttribute(Int32, Int32)

Initializes a new instance of the ValidateLengthAttribute class with the minimum and maximum lengths for the cmdlet parameter arguments.

NameDescription
System_CAPS_pubpropertyMaxLength

Gets the maximum number of characters (length) that is allowed for the cmdlet parameter argument.

System_CAPS_pubpropertyMinLength

Gets the minimum number of characters (length) that is allowed for the cmdlet parameter argument.

System_CAPS_pubpropertyTypeId

(Inherited from Attribute.)

NameDescription
System_CAPS_pubmethodEquals(Object)

(Inherited from Attribute.)

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_pubmethodToString()

(Inherited from Object.)

There are no established scenarios for explicitly creating a ValidateLengthAttribute object from within a cmdlet. The ValidateLengthAttribute object is created and used indirectly when the ValidateLength attribute is declared.

This attribute is declared when implementing a cmdlet parameter. For more information about the syntax used to declare this attribute, see ValidateLength Attribute Declaration.

For examples of declaring other validation attributes, see How to Declare Input Validation Rules.

The following code example shows how this attribute can be declared.

[Cmdlet(VerbsDiagnostic.Test, "ArgumentLength")]
public class TestArgumentLengthCommand : Cmdlet
{
  [ValidateLength(0, 10)]
  [Parameter(Position = 0, Mandatory = true)]
  public string UserName
  {
    get { return userName; }
    set { userName = value; }
  }
  private string userName;

  // Override input processing method.
  protected override void ProcessRecord()
  {
    WriteObject("Hello " + userName);
  }
}

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
Show: