Created
July 25, 2019 18:33
-
-
Save congyiwu/bcb8200aae90b204ec957d872364e3c4 to your computer and use it in GitHub Desktop.
MapCalleeToCallerParams
This file contains 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
# Builds an [ordered] containing only params that were explicitly passed in. With splatting, this | |
# this lets us call another script without overriding its default params. | |
function MapCalleeToCallerParams { | |
param( | |
# An [ordered] where the keys are param names in the script being called (the callee) and | |
# values are param names in this script (the caller). | |
[System.Collections.Specialized.OrderedDictionary][Parameter(Mandatory=$true)] $Mappings | |
) | |
$result = [ordered]@{} | |
foreach ($mapping in $Mappings.GetEnumerator()) { | |
$value = $null | |
if ($MyInvocation.BoundParameters.TryGetValue($mapping.Value, [ref]$value)) { | |
$result.Add($mapping.Key, $value); | |
} | |
} | |
return $result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment