После некоторого эмпирического тестирования, обходной путь должен изменить свойство временного объекта, а затем присвоить его обратно массиву:
> $x = $a[0,0]
> $x.ForegroundColor = [System.ConsoleColor]::Blue
> $x.ForegroundColor
Blue
> $a[0, 0] = $x
> $a[0, 0].ForegroundColor
Blue
Я не знаю всех подробностей, но это, вероятно, связаноBufferCell является структурой, а не классом (см. source на GitHub ), поэтому передача по значению, а не по ссылке и / или NewBufferCellArray возвращает типизированный массив BufferCell [,].
Для сравнения посмотрите следующее:
$type = @"
public struct MyStruct
{
System.ConsoleColor foregroundColor;
public System.ConsoleColor ForegroundColor
{
get { return foregroundColor; }
set { foregroundColor = value; }
}
}
"@
Add-Type -TypeDefinition $type;
$a = new-object -TypeName "MyStruct[]" 5;
$a[0].ForegroundColor = "Blue"
$a[0].ForegroundColor # Black
$a = new-object -TypeName "MyStruct[]" 5;
$x = $a[0];
$x.ForegroundColor = "Blue"
$a[0] = $x
$a[0].ForegroundColor # Blue
$a = @((new-object MyStruct))
$a[0].ForegroundColor = "Blue"
$a[0].ForegroundColor # Blue