Enums without [Flags]
attribute may be formally created from several enum
member names, ether joined with ,
or array of names. This may work or not,
depending on the used member names. The fact that this works sometimes may
lead to mistakes discovered later.
These expressions successfully create [DayOfWeek]::Wednesday
:
[DayOfWeek]'Monday,Tuesday'
[DayOfWeek]('Monday', 'Tuesday')
This result is consistent with [Enum]::Parse([DayOfWeek], 'Monday,Tuesday')
.
But these expressions fail:
[DayOfWeek]'Monday,Saturday'
[DayOfWeek]('Monday', 'Saturday')
with these errors:
Cannot convert value "Monday,Saturday" to type "System.DayOfWeek" due to enumeration values that are not valid.
Specify one of the following enumeration values and try again.
The possible enumeration values are "Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday".
This result is inconsistent with [Enum]::Parse([DayOfWeek], 'Monday,Saturday')
which works and creates the value 7
.