Enum or ValidateSet

In some cases, only the name of the value is important; enumerations are occasionally used in place of ValidateSet.

Class-based Desired State Configuration (DSC) resources provide one of the more obvious cases for this style. The Ensure parameter has two possible values: Absent and Present. Ensure can be expressed using an enumeration:

enum Ensure {
Absent
Present
}

Absent is placed first as this has the value of 0, which might also be interpreted as false when casting to a Boolean:

[Boolean][Ensure]::Absent

The advantage of using an enumeration is that it can be shared across a script or module and would only need to be updated once in the event of a change.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.140.5