Title: Encourage using IDictionary interface for parameters · Issue #13852 · PowerShell/PowerShell · GitHub
Open Graph Title: Encourage using IDictionary interface for parameters · Issue #13852 · PowerShell/PowerShell
X Title: Encourage using IDictionary interface for parameters · Issue #13852 · PowerShell/PowerShell
Description: Encourage developers to use the IDictionary interface for the parameter type (if the [Hashtable] type is not explicitly required which I think it almost always the case) Currently, In most custom functions, the specific [Hashtable] dicti...
Open Graph Description: Encourage developers to use the IDictionary interface for the parameter type (if the [Hashtable] type is not explicitly required which I think it almost always the case) Currently, In most custom f...
X Description: Encourage developers to use the IDictionary interface for the parameter type (if the [Hashtable] type is not explicitly required which I think it almost always the case) Currently, In most custom f...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/13852
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Encourage using IDictionary interface for parameters","articleBody":"### Encourage developers to use the [`IDictionary`](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.idictionary-2) interface for the parameter type\r\n(if the `[Hashtable]` type is not explicitly required which I think it almost always the case)\r\n\r\nCurrently, In most custom functions, the specific `[Hashtable]` dictionary type is used for parameter type where it would be better to use the more generic `IDictionary` interface so that is would accept any `ICollection` or `IEnumerable` (as e.g. the `[Ordered]` type), knowing that the enumeration of all `IDictionary` Objects are common and most native PowerShell cmdlet accept the `IDictionary` interface.\r\nThe reason that specific `[Hashtable]` dictionary type is used is because the `[Hashtable]` type is more known (and default) within PowerShell and has simply a shorter type name.\r\n\r\n### Proposed technical implementation details (optional)\r\n* Add the `IDictionary` interface to the default list of type accelerators:\r\n\r\n```PowerShell\r\n$TypeAccelerators = [psobject].Assembly.GetType('System.Management.Automation.TypeAccelerators')\r\n$TypeAccelerators::Add('IDictionary', [System.Collections.IDictionary]) # Or just 'Dictionary'?\r\n```\r\nSo that a developer/user can use any dictionary object for input:\r\n```PowerShell\r\nFunction Test([IDictionary]$Dictionary) {\r\n [pscustomobject]$Dictionary\r\n}\r\nTest ([Ordered]@{ a = 1; b = 2; c = 3 })\r\n```\r\nPossibly also:\r\n* Add the recommendation to use the `IDictionary` interface to the best practice documentation\r\n* Create a PSScriptAnalyzer warning when an explicit `[Hashtable]` type is used for a parameter?\r\n\r\nRelated:\r\n* Feature Request: add [Ordered] type accelerator #10513\r\n* Enhance hash table syntax #13817","author":{"url":"https://github.com/iRon7","@type":"Person","name":"iRon7"},"datePublished":"2020-10-23T13:54:25Z","url":"https://github.com/PowerShell/PowerShell/issues/13852"}
| 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:510cd031-5d6e-d967-bef0-131faee59e73 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B278:26E91D:73F83:A25CD:6AFDA744 |
| html-safe-nonce | 97cf4270ae8c3dd298db7ab3eeb2d676e12cfa654c7eba1c5f9702406e819f3d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMjc4OjI2RTkxRDo3M0Y4MzpBMjVDRDo2QUZEQTc0NCIsInZpc2l0b3JfaWQiOiI4NDI0ODY3NTAyOTgyMjc2OTMyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 9d6887dc56b91ef73b5f1200e3613c42d9c9af1f262efc96e7781f521f90dec3 |
| hovercard-subject-tag | issue:728239341 |
| 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/13852/issue_layout |
| twitter:image | https://opengraph.githubassets.com/68e85fd0032e77d2cae9b4ed7b324db03fd11e2cca842fcf35d0aaa052956e99/PowerShell/PowerShell/issues/13852 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/68e85fd0032e77d2cae9b4ed7b324db03fd11e2cca842fcf35d0aaa052956e99/PowerShell/PowerShell/issues/13852 |
| og:image:alt | Encourage developers to use the IDictionary interface for the parameter type (if the [Hashtable] type is not explicitly required which I think it almost always the case) Currently, In most custom f... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | iRon7 |
| 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