我正在动态地生成某种类型的.net对象,比如这个$MyType=([System.Type]::GetType("System.String"),这对于标准.net对象来说很好。
我现在创建了这样一个自定义类
class InstanceName
{
[String] hidden $Val
InstanceName([String]$CVal)
{
$this.Val=$CVal
}
}在这里,此方法不起作用,因为powershell找不到类型。$MyType=([System.Type]::GetType("InstanceName")
知道如何获得自定义PS类的System.Type吗?
谢谢!
发布于 2021-11-04 16:14:54
使用-as类型转换操作符:
$instanceNameType = 'InstanceName' -as [type]
# test the type reference
$instanceNameType::new("")https://stackoverflow.com/questions/69842375
复制相似问题