Consider the following code:
function f {
param (
[AllowNull()]
[string]
$x
)
return $x
}
$r = f -x $null
function f {
param (
[AllowNull()]$x
)
return $x
}
$r = f -x $null
By removing the [string]
and using [AllowNull()]
the above function will now allow you to pass in a null object or an empty string. You can check for the type using $x.GetType
with an if statement and determining if $x
is null or an empty string.