Created
July 25, 2017 15:01
-
-
Save adamdriscoll/5b88d3f85ce222851817eef3be2ae7e8 to your computer and use it in GitHub Desktop.
PSeudoParameterBinding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-BoundParameter { | |
param($commandAst) | |
$psuedoParameterBinderType = [System.Management.Automation.AliasInfo].Assembly.GetType('System.Management.Automation.Language.PseudoParameterBinder') | |
$bindingTypeType = [System.Management.Automation.AliasInfo].Assembly.GetType('System.Management.Automation.Language.PseudoParameterBinder+BindingType') | |
$psuedoParameterBinder = [Activator]::CreateInstance($psuedoParameterBinderType) | |
$DoPseudoParameterBinding = $psuedoParameterBinderType.GetMethod('DoPseudoParameterBinding', [System.Reflection.BindingFlags]::Instance -bor [System.Reflection.BindingFlags]::NonPublic) | |
$pseudoBindingInfoType = [System.Management.Automation.AliasInfo].Assembly.GetType('System.Management.Automation.Language.PseudoBindingInfo') | |
$bindingInfo = $DoPseudoParameterBinding.Invoke($psuedoParameterBinder, @($commandAst, $null, $null, $bindingTypeType.GetEnumValues()[0])) | |
$boundArgumentsProperty = $pseudoBindingInfoType.GetProperty("BoundArguments", [System.Reflection.BindingFlags]::Instance -bor [System.Reflection.BindingFlags]::NonPublic) | |
$boundArgumentsProperty.GetValue($bindingInfo).GetEnumerator() | % { @{ Name = $_.Key; Ast = $_.Value.Argument } } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment