【发布时间】:2015-07-05 09:56:59
【问题描述】:
在 PowerShell 中,我创建了一个结构(HashTable 类型),如下所示:
$Structure = @{
"KeyOne" = "Value"
"KeyTwo" = "{Change.This.That}"
"KeyThree" = "{Change.This.Thing} With Stuff"
"Change" = @{
"This" = @{
"That" = "Another Value"
"Thing" = "Yogurt"
}
}
}
带有大括号的字符串是实际值的占位符/标记,以字符串格式存储作为对同一对象中其他值的点表示法的引用。
我编写了一个函数来获取该标记化的值并检索应该完美运行的实际值。唯一的问题是每次有标记化值时我都必须执行该函数。无论如何我可以简化这个,特别是而不是运行:
#I pass structure because I'd rather avoid assuming
#the hashtable will always be called $Structure
Convert-Token -String $Structure.KeyTwo -Obj $Structure #Another Value
有没有我可以通过拉括号符号自动做到这一点?
#Like this?
$Value = $Structure["KeyThree"]
$Value #Yogurt With Stuff
可能吗?不可能?
【问题讨论】:
标签: powershell hashtable