我想在PowerShell腳本中使用HashSet。我想我已經找到了如何做實例化泛型集合對象:可以在PowerShell中使用System.Core.dll/System.Collections.Generic.HashSet嗎?
[type] $strType = "string"
$listClass = [System.Collections.Generic.List``1]
$listObject = $base.MakeGenericType(@($t))
$myList = New-Object $setObject
這工作正常列表和字典,但是當我嘗試創建一個HashSet的,我得到:
Unable to find type [System.Collections.Generic.HashSet`1]: make sure that the assembly containing this type is loaded.
所以它看起來像現在我需要加載System.Core.dll,但我似乎無法得到加載該程序集的PowerShell。例如主叫[System.Reflection.Assembly] :: LoadWithPartialName( 「System.Core程序」)導致該異常:
"LoadWithPartialName" with "1" argument(s): "Could not load file or assembly 'System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified."
任何指針?
你在PowerShell中v1或v2? – x0n 2010-07-23 18:56:52
我在Win2k8 R2上,並得到主機說版本2.0 – nick 2010-07-23 19:11:34
可能的重複:請參閱答案http://stackoverflow.com/questions/184476/powershell-generic-collections – zdan 2010-07-23 19:18:03