我创建了一个poweshell模块脚本'TestModule.psm1',其中我定义了一个带有数组的类。然后,在poswershell脚本“ TestScript.ps1”中使用Testmodule.psm1。现在,当我创建一个测试类的新对象时,总是出现错误“您不能在空值表达式上调用方法”。当我向数组中添加文本时。
TestModule.psm1
Class TestClass
{
[string[]] $texts = @()
}
TestScript.ps1
using module .\TestModule.psm1
$t = [TestClass]::new()
$t.texts += "text"