English 中文(简体)
同步d哈希表对PowerShell显示不友好。尝试:[HashTable]::已同步(@{})
原标题:Sync d Hashtable not PowerShell display-friendly. Try: [HashTable]::Synchronized(@{})

我有一个来自.Net的对象,它具有SyncHashTable类型的属性,该属性在没有引发异常的情况下无法查看。

单线复制:

[HashTable]::Synchronized(@{})

多行播放更容易:

$ht = new-object hashtable
$ht.add("foo", "bar")
$hts = [Hashtable]::Synchronized($ht)
$hts

错误:

format-default : Object reference not set to an instance of an object.
    + CategoryInfo          : NotSpecified: (:) [format-default], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.FormatDefaultCommand

有人对此有什么见解吗?

最佳回答

从微软那里得到消息,这是可以实现的:

PS> $r = [hashtable]::Synchronized(@{})
PS> $r|format-table -expand coreonly -autoSize

Count IsReadOnly IsFixedSize IsSynchronized SyncRoot      Keys Values
----- ---------- ----------- -------------- --------      ---- ------
    0      False       False           True System.Object {}   {}

PS> $r.Add("key","value")
PS> $r["key"]
value

显然,这是一个错误的方式,在格式化的类型显示。

问题回答

暂无回答




相关问题
Anagram Hash Function

I know something like this has been asked before, but the answer was sort of side tracked. I want to develop a hash function which will take a word and spit out an address of an array. So, for ...

Frequently Used metadata Hashmap

Are there any implementations of a static size hashtable that limits the entries to either the most recently or most frequently used metadata? I would prefer not to keep track of this information ...

热门标签