types - Powershell parameter block accepting an array of [PSTypeName("MyType")] -
if create object pstypename can enforce parameters function being of type, so:
function new-nugetdependency{ param( [string]$id, [string]$version ) [pscustomobject]@{ pstypename = "nugetdependency" id = $id version = $version } } and
function show-nuggetdependency{ param( [pstypename("nugetdependency")]$dependency ) write-host ("dependency " + $dependency.id + " - " + $dependency.version) } however! there doesn't seem way of saying $dependency array of nugetdependency. if wanted function take in multiple dependencies i'm stuck.
what missing?
got there, think.
replacing second function works:
function show-nuggetdependency{ param( [pstypename("nugetdependency")][object[]]$dependency ) foreach($dependencyitem in $dependency){ write-host ("dependency " + $dependencyitem.id + " - " + $dependencyitem.version) } } and allow array consists solely of nugetdependency types. won't allow array consists of nugetdependency types , other types. wanted.
Comments
Post a Comment