誰もこの奇妙なpowershellの動作を説明できますか?私は次のように宣言した場合System.Collections.ArrayListはSystem.Collecitons.HashTableになります
:私はメンバーを取得する場合、あなたが私の全体のcollecitonが表示されますただし
System.Collections.Array.List
Index Item
0 {System.Collections.HashTable}
1 {System.Collections.HashTable}
2 {System.Collections.HashTable}
:
$MyCollection = New-Object System.Collections.ArrayList
$MyCollection.Add(@{'Val1'=1; 'Val2'=2; 'Val3'=3})
$MyCollection.Add(@{'Val1'=1; 'Val2'=2; 'Val3'=3})
$MyCollection.Add(@{'Val1'=1; 'Val2'=2; 'Val3'=3})
をので...私はこのようになりますオブジェクトを持つ必要があります1つの大きなハッシュテーブルになっています
$MyCollection | Get-Member
TypeName: System.Collections.Hashtable
Name MemberType Definition
---- ---------- ----------
Add Method void Add(System.Object key, System.Object value), void IDictionary.Add(System.Object key, System.Object value)
Clear Method void Clear(), void IDictionary.Clear()
Clone Method System.Object Clone(), System.Object ICloneable.Clone()
Contains Method bool Contains(System.Object key), bool IDictionary.Contains(System.Object key)
ContainsKey Method bool ContainsKey(System.Object key)
ContainsValue Method bool ContainsValue(System.Object value)
CopyTo Method void CopyTo(array array, int arrayIndex), void ICollection.CopyTo(array array, int index)
Equals Method bool Equals(System.Object obj)
GetEnumerator Method System.Collections.IDictionaryEnumerator GetEnumerator(), System.Collections.IDictionaryEnumerator IDictionary.GetEnumerator(), System.Collections.IEnumerator IEnumerable.GetEn...
GetHashCode Method int GetHashCode()
GetObjectData Method void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context), void ISerializable.GetObjectData(System.Runtime....
GetType Method type GetType()
OnDeserialization Method void OnDeserialization(System.Object sender), void IDeserializationCallback.OnDeserialization(System.Object sender)
Remove Method void Remove(System.Object key), void IDictionary.Remove(System.Object key)
ToString Method string ToString()
Item ParameterizedProperty System.Object Item(System.Object key) {get;set;}
Count Property int Count {get;}
IsFixedSize Property bool IsFixedSize {get;}
IsReadOnly Property bool IsReadOnly {get;}
IsSynchronized Property bool IsSynchronized {get;}
Keys Property System.Collections.ICollection Keys {get;}
SyncRoot Property System.Object SyncRoot {get;}
Values Property System.Collections.ICollection Values {get;}
そして、このような動作は次のとおりです。例えば、私は私の物私が望むようにアクセスできません:あなたが見ることができるように
$MyCollection | %{$_.Val1}
出力
1
1
1
の予想される出力
1
を、私たちは今、一つの大きなハッシュテーブルを持っています非常に奇妙な行動をします。誰もPowershellが実際にやっていることを説明できますか?なぜなら、ArrayListコレクション内のHashTableには挑戦的にアクセスしていないからです。
あなたはあなたの例ではGet-Member
が配列の内部、ハッシュテーブルを見ているので、それが巻き出されるパイプラインを経由して配列を渡すと、その任意のコマンドレットを呼び出すなどは単一のハッシュテーブル
'$ MyCollection | %{$ _。Val1} 'の例?現在の出力は、私が構文について期待しているものと同じです。 – Persistent13