ValidateSetAttribute Constructor
Collapse the table of content
Expand the table of content

ValidateSetAttribute Constructor (String[])

 

Updated: April 27, 2016

Applies To: Windows PowerShell

Creates a new ValidateSetAttribute object.

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

public ValidateSetAttribute(
	params string[] validValues
)

Parameters

validValues
Type: System.String[]

The set of the valid values for the cmdlet parameter argument.

Exception Condition
ArgumentException

The validValues parameter contains arguments that are not valid.

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

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

The following lines of code show how this attribute may be declared.

[Cmdlet(VerbsDiagnostic.Test, "ArgumentSet")]
public class TestArgumentSetCommand : Cmdlet
{
  [ValidateSet("Steve", "Mary", "Carl", IgnoreCase = true)]
  [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(userName + " is a valid input.");
  }
}

Return to top

Community Additions

ADD
Show:
© 2016 Microsoft