2

I'm trying to use classes and reference them within each other. Unfortunately I can't seem to figure it out how. What I try to do is:

  • Create a module exporting classes in different files. One of the classes has a method which returns another class.
  • Import the module in another class and make use of the classes from the module.

What I tried (simplified example):

Item.ps1

class Item {

}

ItemList.ps1

. '.\Item.ps1' 

class ItemList {
    [Item] function Items () {
    // It goes wrong here. Visual studio code mentions type Item cannot be found.
    }
}

Utilities.psm1

. '.\Item.ps1'
. '.\ItemList.ps1'
// I'm not sure if this is the right way to export the classes via the module

Foo.ps1

using module '.\Utilities.psm1'

class Foo {
    [ItemList] function CreateItemList() {
     // It goes wrong here. Visual studio code mentions type ItemList cannot be found.
    }
}

I would really appreciate if some could help me figure this out!

Update

It looks like it can't be done. Here the following is mentioned:

In this release, you can't use a type literal (for example, [MyClass]) outside the script/module file in which the class is defined.

mattderi
  • 21
  • 4

0 Answers0