question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Member-Access enumeration doesn't work on enumerated values

See original GitHub issue

Prerequisites

Steps to reproduce

I see a lot of similar issues:

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:open
  • Created a year ago
  • Reactions:2
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
mklement0commented, Aug 26, 2022

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

2reactions
scriptingstudiocommented, Aug 26, 2022

Key does not work too (but Name “mystically” does)

@{a=1;b=2}.GetEnumerator().key
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found