Title: Member-access enumeration works with setter methods, but not with property assignments · Issue #5271 · PowerShell/PowerShell · GitHub
Open Graph Title: Member-access enumeration works with setter methods, but not with property assignments · Issue #5271 · PowerShell/PowerShell
X Title: Member-access enumeration works with setter methods, but not with property assignments · Issue #5271 · PowerShell/PowerShell
Description: You can use member enumeration to get property values from all members of a collection, but you cannot currently set them (to a given, single value). By contrast, you can use a setter method to do so. # Create 2 temporary files and colle...
Open Graph Description: You can use member enumeration to get property values from all members of a collection, but you cannot currently set them (to a given, single value). By contrast, you can use a setter method to do ...
X Description: You can use member enumeration to get property values from all members of a collection, but you cannot currently set them (to a given, single value). By contrast, you can use a setter method to do ...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/5271
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Member-access enumeration works with setter methods, but not with property assignments","articleBody":"You can use member enumeration to _get_ property values from all members of a collection, but you cannot currently _set_ them (to a given, single value).\r\nBy contrast, you _can_ use a setter _method_ to do so.\r\n\r\n```powershell\r\n# Create 2 temporary files and collect their [System.IO.FileInfo] representations\r\n# in an array.\r\n$files = (New-Item -Type File -Force '/tmp/t1.txt'), (New-Item -Force -Type File '/tmp/t2.txt')\r\n\r\n# Using member enumeration, try to set a property on all elements of the array\r\n# to the same value:\r\n\r\n# Try to to *assign to a property*.\r\n# !! FAILS with error \"The property 'LastWriteTime' cannot be found on this object.\"\r\n$files.LastWriteTime = (Get-Date).AddDays(-1) \r\n\r\n# Try the property's *setter method* - this works.\r\n$files.set_LastWriteTime((Get-Date).AddDays(-1))\r\n\r\n# Verify that the date was set to yesterday.\r\n$files\r\n```\r\n\r\nGiven that using the setter method works, I suggest also allowing the property-assignment form.\r\n(Note that `NoteProperty` members, such as found on `[pscustomobject]` instances, do not have setter methods.)\r\n\r\nIf there are good reasons not to allow that, I suggest making the error message less confusing (if `$someColl.foo` finds property `foo` on the collection members, then `$someColl.foo = ...` should indicate that assignment is disallowed rather than claiming that the property doesn't exist).\r\n\r\n\r\n\r\nEnvironment data\r\n----------------\r\n\r\n\u003c!-- provide the output of $PSVersionTable -->\r\n\r\n```powershell\r\nPowerShell Core v6.0.0-beta.9 on macOS 10.13\r\nPowerShell Core v6.0.0-beta.9 on Ubuntu 16.04.3 LTS\r\nPowerShell Core v6.0.0-beta.9 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)\r\nWindows PowerShell v5.1.15063.674 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)\r\n```\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2017-10-29T13:27:18Z","url":"https://github.com/PowerShell/PowerShell/issues/5271"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:4249fa5a-377c-7f11-84c5-73c6a4ce015b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C836:1976FB:3E06E:56873:6AFDA892 |
| html-safe-nonce | b2d19742f277c082f21875aad2fdce97129f772910fe0176c31f4969744c4502 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDODM2OjE5NzZGQjozRTA2RTo1Njg3Mzo2QUZEQTg5MiIsInZpc2l0b3JfaWQiOiI3ODk2MDI0NDEzMTM5NDc4Njc0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 63032bcd314cee083aeabff86ef8960c70c9e56358c22ec0cdfa22ef17f23e0c |
| hovercard-subject-tag | issue:269399070 |
| 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/5271/issue_layout |
| twitter:image | https://opengraph.githubassets.com/be18569efe6cc6658131cf5da7aec9b8e861c0f99b2e5e7426cb194e1e9c482d/PowerShell/PowerShell/issues/5271 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/be18569efe6cc6658131cf5da7aec9b8e861c0f99b2e5e7426cb194e1e9c482d/PowerShell/PowerShell/issues/5271 |
| og:image:alt | You can use member enumeration to get property values from all members of a collection, but you cannot currently set them (to a given, single value). By contrast, you can use a setter method to do ... |
| 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 | bc86424ef34a73b386237872800e922d149d65ba907f63d6f150a2dcb8433bea |
| 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 | 0ddf53eb35c87f1f8df13dbf75c3bdadbfc6e969 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width