Water Cooler v2
Water Cooler v2

Reputation: 33850

How to include a parameter of a custom type I declared?

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

Answers (1)

Maximilian Burszley
Maximilian Burszley

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

Related Questions