Member-Access enumeration doesn't work on enumerated values
See original GitHub issuePrerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
I see a lot of similar issues:
- #17649 Intrinsic .ForEach() method doesn’t work with methods / parameterized properties of hashtables
- #17520 Member-access enumeration doesn’t work with numeric hashtable keys
- #17514 Member-access enumeration on arrays of hashtables (dictionaries) works with dot notation, but not with index notation
- #17190 A dictionary type that only implements the generic IDictionary interface doesn’t support dot notation (property-access syntax)
so this one might be a duplicate (or have a similar cause).
@{a=1;b=2}.GetEnumerator().Name
a
b
@{a=1;b=2}.GetEnumerator().Value
Expected behavior
1
2
Actual behavior
Nothing return for the `value` property
Error details
No errors
Workarround
Use the Array subexpression operator @( )
or simply @{a=1;b=2}.values
😊.
@(@{a=1;b=2}.GetEnumerator()).Value
1
2
Environment data
Name Value
---- -----
PSVersion 7.2.6
PSEdition Core
GitCommitId 7.2.6
OS Microsoft Windows 10.0.22000
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:5 (4 by maintainers)
Top Results From Across the Web
about Member-Access Enumeration - PowerShell
Describes the automatic enumeration of list collection items when using the member-access operator.
Read more >c++ - enum type declared inside a class access confusion
Your enum MyType is inside the class, so its values are expected to be accessed through the class and the enumeration.
Read more >INT50-CPP. Do not cast to an out-of-range enumeration ...
It is possible to define an enumeration that has values not defined by any of its enumerators. If the enumerator-list is empty, the...
Read more >Enumeration declaration
An enumeration is a distinct type whose value is restricted to a range of values (see below for details), which may include several ......
Read more >Using enums
Flow Enums are not a syntax for union types. They are their own type, and each member of a Flow Enum has the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It seems that
$null
is returned, as you would get with a nonexistent property (with strict mode turned off).The fact that
Set-StrictMode -Version 2; @{a=1;b=2}.GetEnumerator().Value
does not complain - it recognizes the property as existing on all enumerated items, yet returns$null
instead of the values - suggests that the intent is for@{a=1;b=2}.GetEnumerator().Value
to work and that we’re simply dealing with a bug.Another indication: It works fine with
.GetEnumerator()
called on an array:('a', 'bc').GetEnumerator().Length
Key
does not work too (butName
“mystically” does)