Skip to content

Instantly share code, notes, and snippets.

@Jaykul
Created October 21, 2019 22:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Jaykul/874a1688209a4f027a23264bec7ec932 to your computer and use it in GitHub Desktop.
Save Jaykul/874a1688209a4f027a23264bec7ec932 to your computer and use it in GitHub Desktop.
More LINQ Helpers for PowerShell
# Add a .ToDictionary(KeyType,ValueType) for all hashtables
Update-TypeData -TypeName Hashtable -MemberType ScriptMethod -MemberName ToDictionary -Value {
param([Type]$KeyType,[Type]$ValueType)
[Scriptblock]::Create(
"[Enumerable]::ToDictionary(
[DictionaryEntry[]]@(`$this.GetEnumerator()),
[Func[DictionaryEntry,$($KeyType.FullName)]]{ `$args.Key },
[Func[DictionaryEntry,$($ValueType.FullName)]]{ `$args.Value })"
).Invoke()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment