Quantcast
Viewing all articles
Browse latest Browse all 21975

Passing a mix of optional & and empty arguments

I have three pairs of arguments I need to pass to a function. Each pair is made up of an ID and a Type as strings. Of the three pairs, one pair is optional, and the other two are not, and in one required pair (Task), the ID is could be null, but the type will always be present. In addition, two of the three get passed along a chain, with parts used along the way.

In an attempt to keep things readable, I had intended make all three arrays, so the parameters for a given function would be

[Parameter(Mandatory=$false)][string[]]$RootPackage,
[Parameter(Mandatory=$true)][string[]]$Package,
[Parameter(Mandatory=$true)][string[]]$Task

Then I could call a function with something like this, where $TaskID is sometimes $Null

Add-PxTaskHistory -RootPackage:$RootPackage -Package:$Package -Task:@($TaskID, $TaskType)

Unfortunately, it seems that there is an issue with casting $Null to a String, so this is not working as well as I might like, and before I go add a bunch of code to address those conditions, I wonder if there is a better option. The one that comes to mind is an object with the six values, and just pass the object along. Or, since no value will ever have a dot or pipe, just join the pairs and split them up again as needed. But that gets into glue code again.

Or am I better off just having 6 arguments and really long calls?

Thanks!
Gordon



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>