This topic has not yet been rated - Rate this topic

ValidateLengthAttribute Class

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

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.)


Namespace: System.Management.Automation
Assembly: System.Management.Automation (in System.Management.Automation)
'Usage
Dim instance As ValidateLengthAttribute

[AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field)] 
public sealed class ValidateLengthAttribute : ValidateEnumeratedArgumentsAttribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field) */ 
public final class ValidateLengthAttribute extends ValidateEnumeratedArgumentsAttribute
AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field) 
public final class ValidateLengthAttribute extends ValidateEnumeratedArgumentsAttribute

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);
  }
}

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. the syntax used to declare this attribute, see ValidateLengthAttribute Declaration.

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


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.
Did you find this helpful?
(1500 characters remaining)