【发布时间】:2021-03-15 23:30:00
【问题描述】:
我有一个应用程序,我在其中使用来自 System.Collections.Generic.HashSet 的 HashSet,但想为其添加功能。
我正在尝试使用类继承来创建HashSet 的子类,但失败得很惨。
我一定是错误地声明了类名,但找不到从集合类型类继承的其他示例。
using namespace System.Collections.Generic
class StatusBucket : System.Collections.Generic.HashSet[HashSet[object]] {
[array] toArray() {
$array = [object[]]::new($this.count)
foreach ($value in $this) {
$array.Add($value)
}
return $array
}
}
$setValues = @('1', '2')
$testHashSet = [HashSet[object]]::new($ids) # Works as expected
Write-Host $testHashSet
$testStatusBucket = [StatusBucket[object]]::new($ids) # Fails
【问题讨论】:
标签: .net powershell inheritance collections subclass