Title: When powershell class method has same name as property, the property disapear and is not accessible from any instance · Issue #7736 · PowerShell/PowerShell · GitHub
Open Graph Title: When powershell class method has same name as property, the property disapear and is not accessible from any instance · Issue #7736 · PowerShell/PowerShell
X Title: When powershell class method has same name as property, the property disapear and is not accessible from any instance · Issue #7736 · PowerShell/PowerShell
Description: Hi, When I have a powershell class, that has a method with the same name as one of it's properties, then the property disapear, and is not visible on any of the instances. See examples below. Steps to reproduce Class Folder { $Name $Path...
Open Graph Description: Hi, When I have a powershell class, that has a method with the same name as one of it's properties, then the property disapear, and is not visible on any of the instances. See examples below. Steps...
X Description: Hi, When I have a powershell class, that has a method with the same name as one of it's properties, then the property disapear, and is not visible on any of the instances. See examples below. S...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/7736
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"When powershell class method has same name as property, the property disapear and is not accessible from any instance","articleBody":"\u003c!--\r\n\r\nFor Windows PowerShell 5.1 issues, suggestions, or feature requests please use the following link instead:\r\n- Windows PowerShell [UserVoice](https://windowsserver.uservoice.com/forums/301869-powershell)\r\n\r\nIf it is a bug report:\r\n- make sure you are able to repro it on the latest released version. \r\nYou can install the latest version from https://github.com/PowerShell/PowerShell/releases\r\n- Search the existing issues.\r\n- Refer to the [FAQ](https://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md).\r\n- Refer to the [known issues](https://docs.microsoft.com/powershell/scripting/whats-new/known-issues-ps6?view=powershell-6).\r\n- Fill out the following repro template:\r\n\r\nIf it's not a bug, please remove the template and elaborate the issue in your own words.\r\n-->\r\n\r\nHi,\r\n\r\nWhen I have a powershell class, that has a method with the same name as one of it's properties, then the property disapear, and is not visible on any of the instances. \r\n\r\nSee examples below.\r\n\r\n\r\nSteps to reproduce\r\n------------------\r\n\r\n```powershell\r\n\r\nClass Folder {\r\n \r\n $Name\r\n $Path\r\n [bool]$IsPresent\r\n\r\n [string]IsPresent(){\r\n \r\n return \"woop\"\r\n }\r\n}\r\n\r\n\r\n```\r\n\r\nWhen looking using Get-Member, we can see that the property $IsPresent disapeared, but that method is still there:\r\n\r\n```powershell\r\n[Folder]::New() | gm\r\n\r\n\r\n TypeName: Folder\r\n\r\nName MemberType Definition \r\n---- ---------- ---------- \r\nEquals Method bool Equals(System.Object obj)\r\nGetHashCode Method int GetHashCode() \r\nGetType Method type GetType() \r\nIsPresent Method string IsPresent() \r\nToString Method string ToString() \r\nName Property System.Object Name {get;set;} \r\nPath Property System.Object Path {get;set;\r\n```\r\n\r\n\r\nExpected behavior\r\n-----------------\r\n\r\n\r\n```powershell\r\n\r\n[Folder]::New()\r\n\r\n#Should return\r\n\r\nName Path IsPresent\r\n---- ---- ---------\r\n False\r\n\r\n```\r\n\r\nActual behavior\r\n---------------\r\n\r\n```powershell\r\n\r\n[Folder]::New()\r\n\r\n#Returns\r\n\r\nName Path\r\n---- ----\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\r\nI had the same behaviour on:\r\n\r\n```powershell\r\n> $PSVersionTable\r\nName Value\r\n---- -----\r\nPSVersion 6.1.0-preview.1\r\nPSEdition Core\r\nGitCommitId v6.1.0-preview.1\r\nOS Microsoft Windows 10.0.14393\r\nPlatform Win32NT\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\nWSManStackVersion 3.0\r\n```\r\nand\r\n\r\n```powershell\r\n\r\nName Value \r\n---- ----- \r\nPSVersion 5.1.14393.2339 \r\nPSEdition Desktop \r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} \r\nBuildVersion 10.0.14393.2339 \r\nCLRVersion 4.0.30319.42000 \r\nWSManStackVersion 3.0 \r\nPSRemotingProtocolVersion 2.3 \r\nSerializationVersion 1.1.0.1 \r\n\r\n```\r\n\r\nOn Windows 10 and Windows Server 2012 R2\r\n\r\nWorkaround\r\n---------------\r\n\r\nThe workaround would be to change the name of the method and ensure it is not identical to the property anymore:\r\n\r\n```powershell\r\n\r\nClass Folder {\r\n \r\n $Name\r\n $Path\r\n [bool]$IsPresent\r\n\r\n [string]TestIsPresent(){\r\n \r\n return \"woop\"\r\n }\r\n}\r\n\r\n\r\n```\r\n","author":{"url":"https://github.com/Stephanevg","@type":"Person","name":"Stephanevg"},"datePublished":"2018-09-07T16:08:44Z","url":"https://github.com/PowerShell/PowerShell/issues/7736"}
| 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:6937d5a9-d145-237f-13b5-e3e2d3e38b91 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B470:96CB:5B4D9E:8449FA:6AFDD317 |
| html-safe-nonce | d9e36b93aa464cf7e583d8907f865698bdd69000324d26259ff74de059f9a901 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNDcwOjk2Q0I6NUI0RDlFOjg0NDlGQTo2QUZERDMxNyIsInZpc2l0b3JfaWQiOiIxMTM5NDQ4ODg1NDg0MDQ5MTc1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3c5e9dfe4393c24c9f839d7ad818bcab481a004d51a644975ab52526191ba49d |
| hovercard-subject-tag | issue:358127305 |
| 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/7736/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bac30f5f16b64ae0bf816fcf439c9182276feba66736254f322f898eefeff683/PowerShell/PowerShell/issues/7736 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bac30f5f16b64ae0bf816fcf439c9182276feba66736254f322f898eefeff683/PowerShell/PowerShell/issues/7736 |
| og:image:alt | Hi, When I have a powershell class, that has a method with the same name as one of it's properties, then the property disapear, and is not visible on any of the instances. See examples below. Steps... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Stephanevg |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9918bd4004419458bcd838065ac2a76b76ebd11705d73909fff5ab99e996fa23 |
| 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 | a231c174493a6a442c0b0544475c918b30128208 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width