Reputation: 33850
This article says that the parameter declaration must be the first executable line of code in a script.
So then how can I declare a parameter of a custom type that I create?
For e.g. I'd like to create a script like so:
param
(
[MyCustomTypesNamespace.Cat] $myCat
)
Should the Cat
class be declared in the same file after the parameter definition?
Or should I have to define the Cat
class in a separate file and reference that file in here?
Upvotes: 0
Views: 67
Reputation: 19684
You need to have a module or profile loaded that has that type previously. I would suggest using a function declaration, though.
Class Cat { Cat() {} }
Function Action
{
Param([Cat]$MyCat)
<# ... #>
}
$BlueCat = [Cat]::New()
Action $BlueCat
Upvotes: 1