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.

ValidateCountAttribute Class

 

Updated: April 27, 2016

Applies To: Windows PowerShell

Defines an attribute that uses maximum and minimum limits to validate the number of arguments that a cmdlet parameter accepts. (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)

System.Object
  System.Attribute
    System.Management.Automation.Internal.CmdletMetadataAttribute
      System.Management.Automation.ValidateArgumentsAttribute
        System.Management.Automation.ValidateCountAttribute

<AttributeUsageAttribute(AttributeTargets.Property Or AttributeTargets.Field)>
Public NotInheritable Class ValidateCountAttribute
	Inherits ValidateArgumentsAttribute

NameDescription
System_CAPS_pubmethodValidateCountAttribute(Int32, Int32)

Initializes a new instance of the ValidateCountAttribute class with the minimum and maximum number of allowed arguments for the cmdlet parameter.

NameDescription
System_CAPS_pubpropertyMaxLength

Gets the maximum number of allowed arguments for the cmdlet parameter.

System_CAPS_pubpropertyMinLength

Gets the minimum number of allowed arguments for the cmdlet parameter.

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 ValidateCountAttribute object from within a cmdlet. The ValidateCountAttribute object is created and used indirectly when the attribute is declared.

The cmdlet declares this attribute when implementing a cmdlet parameter. For more information about the syntax and parameters that are used when declaring this, see ValidateCount Attribute Declaration.

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

[ValidateCount(1, 3)]
[Parameter(Position = 0, Mandatory = true)]
public string[] UserNames
{
  get { return userNames; }
  set { userNames = value; }
}

private string[] userNames;

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: