【发布时间】:2017-05-24 07:46:12
【问题描述】:
我需要重新定义函数中的对象吗?
我有以下 main.ps1
$MyDict = New-Object 'system.collections.generic.dictionary[string,string]'
loadDict([ref]$MyDict)
我有一个带有函数的functions.psm1
function loadDict([ref]$return)
{
#pseudo - load data from table
foreach ($TableRow in $LoadTable){
if($return.ContainsKey($TableRow.KEYID) -eq $false){
$return.Add($TableRow.KEYID, $TableRow.TEXT.Trim())
}
}
}
但我得到以下错误..
[System.Management.Automation.PSReference'1[[System.Collections.Generic.Dictionary'2[[System.String, mscorlib,版本=4.0.0.0,文化=中性, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, 版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089]], mscorlib,版本=4.0.0.0,文化=中性, PublicKeyToken=b77a5c561934e089]]] "ContainsKey" 方法未找到
当我不调用函数,而是在Main中使用函数代码时,没有问题。
(更正了“[”错字)
【问题讨论】:
标签: function powershell dictionary