concept class member in category powershell

appears as: Class member, class members, class members
Windows PowerShell in Action, Third Edition

This is an excerpt from Manning's book Windows PowerShell in Action, Third Edition.

The hidden attribute makes a member, well, hidden. This means you won’t ever see the member by default; Get-Member won’t show it. You can force it to be shown by using -Force. Why would you want to hide a member? Hidden is intended to be used on class members that are used internally by the class but aren’t part of the end-user (public) signature of the class. In essence, these members are private to the class.

Along with the keyword attributes (hidden and static), you can use the data transformation and data translation attributes you’re familiar with from advanced function parameters (see section 7.2.6) on class members. Let’s see an example of a class using these attributes. The following example uses the [ValidateRange()] and [ValidateSet()] attributes to constrain the allowed values on the class members:

PS> class ApartmentPets
{
    [int]
    [ValidateRange(1,88)]
    $UnitNumber

    [string]
    [ValidateSet("cat", "dog", "bird")]
    $Type

    [int]
    [ValidateRange(0,3)]
    $Count
}

This class could be used to keep track of the type and number of pets in each apartment of a building. But this goes beyond merely keeping track; the attributes on the class members prevent an entry from containing more than three (or fewer than zero) pets as well as restricting the type of pet and ensuring that the apartment number is valid. You can create a valid instance of this class by casting a hashtable into an instance of [ApartmentPets]: