EliziumNet/Loopz

Review hashtable.Count access

Closed this issue · 2 comments

It has been discovered that when dealing with hashtables, it is best not to use the Count property on the hashtable as it is unreliable and can sometimes cause the following error:

Cannot compare "System.Collections.Hashtable" because it is not IComparable.

The better way to check this is to use the Count property on keys ie:

$hash.Keys.Count

not

$hash.Count

Actually, the best way going forward is to use PSBase to accesss a hashtable's properies in a reliable fashion. So:

$Hash.PSBase.Count

rather than

$Hash.Keys.Count

because even direct use of 'Keys' on Hashtable could fail, if the hashtable itself contains a key named 'Keys'.