Title: Extend Get-Member to support inspecting a type directly, without needing an instance · Issue #6382 · PowerShell/PowerShell · GitHub
Open Graph Title: Extend Get-Member to support inspecting a type directly, without needing an instance · Issue #6382 · PowerShell/PowerShell
X Title: Extend Get-Member to support inspecting a type directly, without needing an instance · Issue #6382 · PowerShell/PowerShell
Description: To see instance members of a type, Get-Member currently requires that an instance of that type be specified. It would be convenient if a type (name) could be specified directly, because: an instance isn't always (readily) available. crea...
Open Graph Description: To see instance members of a type, Get-Member currently requires that an instance of that type be specified. It would be convenient if a type (name) could be specified directly, because: an instanc...
X Description: To see instance members of a type, Get-Member currently requires that an instance of that type be specified. It would be convenient if a type (name) could be specified directly, because: an instanc...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/6382
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Extend Get-Member to support inspecting a type directly, without needing an instance","articleBody":"To see _instance_ members of a type, `Get-Member` currently requires that an _instance of that type_ be specified.\r\n\r\nIt would be convenient if a _type_ (name) could be specified directly, because:\r\n\r\n* an instance isn't always (readily) available.\r\n* creating one on demand is not only cumbersome but can be tricky, if the type has no parameterless constructor (you'd then have to know how many parameters of what type are needed and invent sample values in order to create an instance).\r\n\r\n**Wishful thinking**:\r\n\r\n```powershell\r\n# The following should be equivalent to both: \r\n# 'a string' | Get-Member -MemberType Property\r\n# Get-Member -InputObject 'a string' -MemberType Property\r\n# I.e., it should list the type's instance members (or, with -Static, the static members).\r\nPS> Get-Member -InputType System.String -MemberType Property\r\n\r\n TypeName: System.String\r\n\r\nName MemberType Definition \r\n---- ---------- ---------- \r\nLength Property int Length {get;}\r\n```\r\n\r\nThe new `-InputType` parameter should be of type `[System.Type]` and allow binding by value from the pipeline, so that you could alternatively write:\r\n\r\n```\r\nPS> [System.String] | Get-Member\r\n```\r\n\r\nNote: Currently, `[System.String]` binds to `-InputObject`, which means you get the instance members _of the type used to represent types_, i.e., you get `[System.RuntimeType]`'s instance members; (`[System.RuntimeType]` is a private type derived from `[System.Type]`).\r\n\r\nTherefore, this proposal is technically a breaking change, after which you'd have to use `[System.String].GetType() | Get-Member` if you really wanted to see `[System.RuntimeType]`'s members.\r\n\r\nNote that `Get-Member` _situationally_ - and therefore inconsistently - already acts as proposed here, namely if you use the `-Static` switch; e.g., `[System.String] | Get-Member -Static` already returns the `[System.String]` type's static members, not `[System.RuntimeType]`'s.\r\n\r\nThe current workaround is to call `[System.RuntimeType]`'s methods directly, such as `.GetMembers()` or `.GetProperties()` (e.g., `[System.String].GetMembers() | Select MemberType, Name, @{ n='Definition'; e={$_} }`); however, this isn't obvious, always includes static members too, and results in a different representation from `Get-Member`'s output, notably in that a given method's overloads are listed individually.\r\n\r\nEnvironment data\r\n----------------\r\n\r\nOriginally written as of:\r\n\r\n```\r\nPowerShell Core v6.0.1\r\n```\r\n\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2018-03-13T18:14:36Z","url":"https://github.com/PowerShell/PowerShell/issues/6382"}
| 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:777c3e9a-1b7a-0d1b-98fa-e0c590894891 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 80D2:5C8B1:D5A65F:134B2D4:6AFDB10F |
| html-safe-nonce | 999c15e0b156af495de934b13c5bd942930f2bd74de4cf4b844a704763d2d912 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MEQyOjVDOEIxOkQ1QTY1RjoxMzRCMkQ0OjZBRkRCMTBGIiwidmlzaXRvcl9pZCI6IjYxNDQ4Njk5MTA0NDM4MzE1NjciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 5821191b88ba10bcc9a1ed7a3cf59f9f61c87111e6f13cafa998ce1846b32a96 |
| hovercard-subject-tag | issue:304879230 |
| 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/6382/issue_layout |
| twitter:image | https://opengraph.githubassets.com/718779029a4e3c6cbc5d57eaf142f3b4cd34e432d4b05b694041790ae272e3a4/PowerShell/PowerShell/issues/6382 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/718779029a4e3c6cbc5d57eaf142f3b4cd34e432d4b05b694041790ae272e3a4/PowerShell/PowerShell/issues/6382 |
| og:image:alt | To see instance members of a type, Get-Member currently requires that an instance of that type be specified. It would be convenient if a type (name) could be specified directly, because: an instanc... |
| 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 | 3c532f4d069d6fbe9b1837450343d1b9e0619a7d5c4ba0b3b64fd8e0bae67c7e |
| 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 | 5396ad00d1c6d19097aee7fc4d00a2eb03432c8f |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width