Title: A dictionary type that only implements the generic IDictionary interface is unexpectedly enumerated in the pipeline · Issue #15204 · PowerShell/PowerShell · GitHub
Open Graph Title: A dictionary type that only implements the generic IDictionary interface is unexpectedly enumerated in the pipeline · Issue #15204 · PowerShell/PowerShell
X Title: A dictionary type that only implements the generic IDictionary interface is unexpectedly enumerated in the pipeline · Issue #15204 · PowerShell/PowerShell
Description: PowerShell makes a hard-coded exception for types that implement the non-generic System.Collections.IDictionary interface with respect to behavior in the pipeline: even though such types are enumerable, PowerShell sends them as a whole t...
Open Graph Description: PowerShell makes a hard-coded exception for types that implement the non-generic System.Collections.IDictionary interface with respect to behavior in the pipeline: even though such types are enumer...
X Description: PowerShell makes a hard-coded exception for types that implement the non-generic System.Collections.IDictionary interface with respect to behavior in the pipeline: even though such types are enumer...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/15204
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"A dictionary type that only implements the generic IDictionary interface is unexpectedly enumerated in the pipeline","articleBody":"PowerShell makes a hard-coded exception for types that implement the _non-generic_ `System.Collections.IDictionary` interface with respect to behavior in the pipeline: even though such types are _enumerable_, PowerShell sends them _as a whole_ through the pipeline.\r\n\r\nSource code here: https://github.com/PowerShell/PowerShell/blob/48c7e112db8f0506a74555c83ecb8bec509b6597/src/System.Management.Automation/engine/LanguagePrimitives.cs#L523-L543\r\n\r\nHowever, some types _only_ implement the _generic_ equivalent of this interface, `System.Collections.Generic.IDictionary\u003cTKey, TValue\u003e`.\r\nSuch type are therefore unexpectedly _enumerated_ in the pipeline, i.e their _key-value_ pairs are sent rather than the dictionary itself.\r\n\r\nNote that while with the `IEnumerable` / `IEnumerable\u003cType\u003e` interface pair implementing the generic version _implicitly_ also implements the non-generic one, this does _not_ apply to the `IDictionary` / `IDictionary\u003cTKey, TValue\u003e` pair.\r\n\r\nI don't know what the official recommendations are in this case, but at least one notable example of a type that _only_ implements the generic interface is [`System.Dynamic.ExpandoObject`](https://docs.microsoft.com/en-US/dotnet/api/System.Dynamic.ExpandoObject), used in the repro below.\r\n\r\n## Steps to reproduce\r\n\r\n```powershell\r\n$o = [System.Dynamic.ExpandoObject]::new(); $o.one = 1; $o.two = 2\r\n\r\n($o | Measure-Object).Count | Should -Be 1\r\n```\r\n\r\n## Expected behavior\r\n\r\nThe test should succeed: the `IDictionary`2`-implementing type's instance should be sent _as a whole_ through the pipeline.\r\n\r\n## Actual behavior\r\n\r\nThe test fails, because the instance is enumerated and its key-value pairs are sent through the pipeline.\r\n\r\n```none\r\nInvalidResult: Expected 1, but got 2.\r\n```\r\n\r\n## Environment data\r\n\r\n```none\r\nPowerShell Core 7.2.0-preview.4\r\n```\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2021-04-11T19:58:53.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":21},"url":"https://github.com/15204/PowerShell/issues/15204"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f265be06-1d85-7199-da0a-5928431b550a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C14E:2BB05E:2FF1098:44FC293:6A552B4A |
| html-safe-nonce | ae525d08307b9f8386a6d5428aa537678fe9fc2381ef6ffab588ac5c135ae82a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMTRFOjJCQjA1RToyRkYxMDk4OjQ0RkMyOTM6NkE1NTJCNEEiLCJ2aXNpdG9yX2lkIjoiNDk5NjkzNjA3MDI2MTQzNDYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | ff0d3937c0d58d0434b930ca9122f3c5b7037c626ade37bc5430b6e823931ca7 |
| hovercard-subject-tag | issue:855394269 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/15204/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d01a6371f1fff82baef281a68a6d4146ce0a55ebd164466222240de4489e520c/PowerShell/PowerShell/issues/15204 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d01a6371f1fff82baef281a68a6d4146ce0a55ebd164466222240de4489e520c/PowerShell/PowerShell/issues/15204 |
| og:image:alt | PowerShell makes a hard-coded exception for types that implement the non-generic System.Collections.IDictionary interface with respect to behavior in the pipeline: even though such types are enumer... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mklement0 |
| hostname | github.com |
| expected-hostname | github.com |
| None | fbd8fce4d63ac394c5405faa20aa50d5c9e56b979ac43ee1b26f8e7c47c4cd89 |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cf96660b44878f418b09d3d6ecde00ad62332910 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width