René's URL Explorer Experiment


Title: Improve discoverability and support for (de)registering event handlers · Issue #12926 · PowerShell/PowerShell · GitHub

Open Graph Title: Improve discoverability and support for (de)registering event handlers · Issue #12926 · PowerShell/PowerShell

X Title: Improve discoverability and support for (de)registering event handlers · Issue #12926 · PowerShell/PowerShell

Description: Summary of the new feature/enhancement Currently, finding event metadata is pretty difficult in PS. The event members are deliberately hidden from autocompletion, can't be directly accessed from objects like methods can to reveal metadat...

Open Graph Description: Summary of the new feature/enhancement Currently, finding event metadata is pretty difficult in PS. The event members are deliberately hidden from autocompletion, can't be directly accessed from ob...

X Description: Summary of the new feature/enhancement Currently, finding event metadata is pretty difficult in PS. The event members are deliberately hidden from autocompletion, can't be directly accessed fro...

Opengraph URL: https://github.com/PowerShell/PowerShell/issues/12926

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Improve discoverability and support for (de)registering event handlers","articleBody":"## Summary of the new feature/enhancement\r\n\r\nCurrently, finding event metadata is pretty difficult in PS. The event members are deliberately hidden from autocompletion, can't be directly accessed from objects like methods can to reveal metadata which is often useful in determining how you want to work with them, and aren't available for autocompletion.\r\n\r\nAdditionally, while `Register-EngineEvent` and `Register-ObjectEvent` do exist, they won't always work. For example, using some GUI-centric script patterns, many users can run into deadlocks using `Register-ObjectEvent` and some Forms classes.\r\n\r\nTo work around this, many scripters resort to using the hidden `$obj.add_EventName($handler)` methods which are not discoverable, not well-documented (as they are generally considered an implementation detail), and difficult to work with in PS.\r\n\r\nMost documentation around events is C#-centric and will recommend the C# syntax for registering and deregistering delegates; `obj.EventName += eventHandler;`\r\n\r\nThis creates friction and confusion; users have neither appropriate access to event metadata to determine how to work with them in PS, nor appropriate documentation to fill in the gaps where Register-ObjectEvent isn't a workable solution. Additionally, even discovering event names for use with Register-ObjectEvent is difficult since the members aren't directly available.\r\n\r\n## Proposed technical implementation details (optional)\r\n\r\n1. Expose event members as actual object members, allowing their names to register for tab completion, and the PSEvent metadata to be shown to users accessing the event.\r\n2. Implement a custom binder for use with `+=` / `-=` which bridges the gap by calling the appropriate `add_*` / `remove_*` method for the targeted event.\r\n3. Add some logic into the Compiler to perform a runtime check for LHS being a PSEvent when handling expressions with `+=` or `-=` operators (this will be dependent on #1 being implemented, or this check cannot be relied on). If the LHS is PSEvent, call out to the binder from #2 and (de)register the event. Naturally, fall back to standard `+=` behaviour if the LHS is not `PSEvent`.\r\n\r\n### Demonstration\r\n\r\n```ps1\r\nPS> $ps = [powershell]::Create()\r\nPS> $handler = { Write-Host \"event triggered!\" }\r\n# Tab completion lists the event member as well\r\nPS> $ps.Invo\r\nInvocationStateInfo     Invoke                  InvokeAsync             InvocationStateChanged  \r\nPS> $ps.InvocationStateChanged += $handler\r\nPS> $ps.AddScript('Write-Output \"data from pipe\"').Invoke()\r\nevent triggered!\r\nevent triggered!\r\ndata from pipe\r\nPS> $ps.InvocationStateChanged -= $handler\r\nPS> $ps.AddScript('Write-Output \"data from pipe\"').Invoke()\r\ndata from pipe\r\n```\r\n\r\nI have working code for this that I can submit as a PR if there is interest in having this be a part of PowerShell. Just have to put some tests together 😎 \r\n\r\nBelow illustrates the metadata event members would show if users attempt to examine them, once the aforementioned changes are in place.\r\n\r\n```\r\nPS> $ps.InvocationStateChanged\r\n\r\nMemberType      : Event\r\nValue           : System.EventHandler`1[System.Management.Automation.PSInvocationStateChangedEventArgs] InvocationStateChanged\r\nTypeNameOfValue : System.Management.Automation.PSEvent\r\nName            : InvocationStateChanged\r\nIsInstance      : True\r\n\r\n\r\nPS /Users/joelfrancis/repos/Github/powershell> $ps.InvocationStateChanged.Value\r\n\r\nMemberType       : Event\r\nName             : InvocationStateChanged\r\nDeclaringType    : System.Management.Automation.PowerShell\r\nReflectedType    : System.Management.Automation.PowerShell\r\nMetadataToken    : 335544336\r\nModule           : System.Management.Automation.dll\r\nAttributes       : None\r\nIsSpecialName    : False\r\nAddMethod        : Void add_InvocationStateChanged(System.EventHandler`1[System.Management.Automation.PSInvocationStateChangedEventArgs])\r\nRemoveMethod     : Void remove_InvocationStateChanged(System.EventHandler`1[System.Management.Automation.PSInvocationStateChangedEventArgs])\r\nRaiseMethod      : \r\nIsMulticast      : True\r\nEventHandlerType : System.EventHandler`1[System.Management.Automation.PSInvocationStateChangedEventArgs]\r\nCustomAttributes : {}\r\nIsCollectible    : True\r\n\r\n\r\nPS> $ps.InvocationStateChanged.GetType()\r\n\r\nIsPublic IsSerial Name                                     BaseType\r\n-------- -------- ----                                     --------\r\nTrue     False    PSEvent                                  System.Management.Automation.PSMemberInfo\r\n\r\nPS> $ps.InvocationStateChanged.Value.GetType()\r\n\r\nIsPublic IsSerial Name                                     BaseType\r\n-------- -------- ----                                     --------\r\nFalse    False    RuntimeEventInfo                         System.Reflection.EventInfo\r\n```\r\n","author":{"url":"https://github.com/vexx32","@type":"Person","name":"vexx32"},"datePublished":"2020-06-09T14:13:49Z","url":"https://github.com/PowerShell/PowerShell/issues/12926"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:be2c0ace-35f8-ad73-8a5f-2359b98fc1cb
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idDF46:24F1E7:E10425:142A161:6AFDB3E5
html-safe-nonce7fbc62b4778209b65ad6e99fb88db5287299e24f59b552f3e46507be46d2a683
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERjQ2OjI0RjFFNzpFMTA0MjU6MTQyQTE2MTo2QUZEQjNFNSIsInZpc2l0b3JfaWQiOiI1NjI2MDUwMDY3Mzg0MDg3NTI1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac12980f373155a82eb66ca378567e3e6029ac553704d7752990a193a91b99a62d
hovercard-subject-tagissue:635467452
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/12926/issue_layout
twitter:imagehttps://opengraph.githubassets.com/0d80c51b96c8f65ef07d7a4f0f0d87ebd84ba9b3bb362a9369515a3846effc7b/PowerShell/PowerShell/issues/12926
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/0d80c51b96c8f65ef07d7a4f0f0d87ebd84ba9b3bb362a9369515a3846effc7b/PowerShell/PowerShell/issues/12926
og:image:altSummary of the new feature/enhancement Currently, finding event metadata is pretty difficult in PS. The event members are deliberately hidden from autocompletion, can't be directly accessed from ob...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamevexx32
hostnamegithub.com
expected-hostnamegithub.com
None3c532f4d069d6fbe9b1837450343d1b9e0619a7d5c4ba0b3b64fd8e0bae67c7e
turbo-cache-controlno-preview
go-importgithub.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git
octolytics-dimension-user_id11524380
octolytics-dimension-user_loginPowerShell
octolytics-dimension-repository_id49609581
octolytics-dimension-repository_nwoPowerShell/PowerShell
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id49609581
octolytics-dimension-repository_network_root_nwoPowerShell/PowerShell
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release5396ad00d1c6d19097aee7fc4d00a2eb03432c8f
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/PowerShell/PowerShell/issues/12926#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FPowerShell%2FPowerShell%2Fissues%2F12926
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FPowerShell%2FPowerShell%2Fissues%2F12926
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=PowerShell%2FPowerShell
Reloadhttps://github.com/PowerShell/PowerShell/issues/12926
Reloadhttps://github.com/PowerShell/PowerShell/issues/12926
Reloadhttps://github.com/PowerShell/PowerShell/issues/12926
PowerShellhttps://github.com/PowerShell
PowerShellhttps://github.com/PowerShell/PowerShell
Codehttps://github.com/PowerShell/PowerShell
Issues1.3k (1.3k)https://github.com/PowerShell/PowerShell/issues
Pull requests366 (366)https://github.com/PowerShell/PowerShell/pulls
Discussionshttps://github.com/PowerShell/PowerShell/discussions
Actionshttps://github.com/PowerShell/PowerShell/actions
Projectshttps://github.com/PowerShell/PowerShell/projects
Security and quality3 (3)https://github.com/PowerShell/PowerShell/security
Insightshttps://github.com/PowerShell/PowerShell/insights
https://github.com/PowerShell/PowerShell
New issuehttps://github.com/login?return_to=https://github.com/PowerShell/PowerShell/issues/12926
New issuehttps://github.com/login?return_to=https://github.com/PowerShell/PowerShell/issues/12926
Improve discoverability and support for (de)registering event handlershttps://github.com/PowerShell/PowerShell/issues/12926#top
In-PRIndicates that a PR is out for the issuehttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22In-PR%22
Issue-Enhancementthe issue is more of a feature request than a bughttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Issue-Enhancement%22
Resolution-No ActivityIssue has had no activity for 6 months or morehttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Resolution-No%20Activity%22
WG-Enginecore PowerShell engine, interpreter, and runtimehttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22WG-Engine%22
https://github.com/vexx32
Rain Sallow (/u/ta11ow) (vexx32)https://github.com/vexx32
on Jun 9, 2020https://github.com/PowerShell/PowerShell/issues/12926#issue-635467452
Update readme #1https://github.com/PowerShell/PowerShell/issues/1
Import issues from VSO #2https://github.com/PowerShell/PowerShell/issues/2
Rain Sallow (/u/ta11ow) (vexx32)https://github.com/vexx32
Issue-Enhancementthe issue is more of a feature request than a bughttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Issue-Enhancement%22
on Jun 9, 2020https://github.com/PowerShell/PowerShell/issues/12926#event-3425118585
Ilya (iSazonov)https://github.com/iSazonov
WG-Enginecore PowerShell engine, interpreter, and runtimehttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22WG-Engine%22
on Jun 10, 2020https://github.com/PowerShell/PowerShell/issues/12926#event-3429320393
microsoft-github-policy-servicehttps://github.com/apps/microsoft-github-policy-service
Resolution-No ActivityIssue has had no activity for 6 months or morehttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Resolution-No%20Activity%22
on Nov 16, 2023https://github.com/PowerShell/PowerShell/issues/12926#event-10974886432
microsoft-github-policy-servicehttps://github.com/apps/microsoft-github-policy-service
completedhttps://github.com/PowerShell/PowerShell/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Nov 23, 2023https://github.com/PowerShell/PowerShell/issues/12926#event-11046782741
https://github.com/MrDRamos
David R. (MrDRamos)https://github.com/MrDRamos
on Aug 3, 2024https://github.com/PowerShell/PowerShell/issues/12926#issuecomment-2266336525
microsoft-github-policy-servicehttps://github.com/apps/microsoft-github-policy-service
In-PRIndicates that a PR is out for the issuehttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22In-PR%22
on Aug 26, 2024https://github.com/PowerShell/PowerShell/issues/12926#event-14019472955
Sign up for freehttps://github.com/signup?return_to=https://github.com/PowerShell/PowerShell/issues/12926
Sign in to commenthttps://github.com/login?return_to=https://github.com/PowerShell/PowerShell/issues/12926
In-PRIndicates that a PR is out for the issuehttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22In-PR%22
Issue-Enhancementthe issue is more of a feature request than a bughttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Issue-Enhancement%22
Resolution-No ActivityIssue has had no activity for 6 months or morehttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22Resolution-No%20Activity%22
WG-Enginecore PowerShell engine, interpreter, and runtimehttps://github.com/PowerShell/PowerShell/issues?q=state%3Aopen%20label%3A%22WG-Engine%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.