I want to use a custom class I declared in a different file as a type:
emailhelper.ps1
class EmailInfo
{
[string]$subject;
[string]$body;
[System.Collections.Generic.List[string]]$distributionList;
}
myfile.ps1
."$PSScriptRoot\.\emailhelper.ps1"
class MyClass
{
[EmailInfo]$startEmailInfo;
...
MyClass([EmailInfo] $info)
{
...
}
}
But it seems not to find it:
En C:\xxx\yyyy\myscript.ps1: 64 Carácter: 6
+ [EmailInfo]$info;
+ ~~~~~~~~~ Cannot find the type [EmailInfo].
The strange thing is that I can create new objects without any problem:
$emailInfo = New-Object EmailInfo;
So the problem seems to be related to using "EmailInfo" as a type.
Finally, if I add "EmailInfo" to the myscript.ps1, that is, the same file where the class is being used, then I can use it as a type...
So, how can I use a class defined in a different file as a type?