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.

ValidateSetAttribute Class

 

Updated: April 27, 2016

Applies To: Windows PowerShell

Defines an attribute that uses a set of values to validate a cmdlet parameter argument.

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


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

NameDescription
System_CAPS_pubmethodValidateSetAttribute(String[])

Creates a new ValidateSetAttribute object.

NameDescription
System_CAPS_pubpropertyIgnoreCase

Gets and sets a Boolean value that indicates whether the case of the arguments is ignored.

System_CAPS_pubpropertyTypeId

(Inherited from Attribute.)

System_CAPS_pubpropertyValidValues

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

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

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: