是不是可以在powershell中用双引号扩展.tostring()?
以下代码按预期工作
foreach($j in $i.data) {
if (!(Get-Member -inputobject $item -name $j.attribute -Membertype Properties)) {
$item | add-member -type NoteProperty -name $j.attribute -value $j.attribute_data
} else {
$after = $j.attribute.tostring()
$item."$after" += (";" + $j.attribute_data)
}
}
这失败了:
$item."$j.attribute.tostring()" += (";" + $j.attribute_data)
有:
在此对象上找不到属性'System.Xml.XmlElement.attribute.tostring()';确保它存在且可设置 . 在行:9 char:27 $ item . <<<<“$ j.attribute.tostring()”=(“;”$ j.attribute_data)CategoryInfo:InvalidOperation:(:) [],RuntimeException FullyQualifiedErrorId:PropertyAssignmentException