I want to test if an object is a string or any type of array or list (not hashtable or dictionary, etc.) It seems impossible to test for every type of collection in .NET. I must be missing some ICollection type.
I have tried something like:
($list -is [Collections.IEnumerable]) -and ($list -isnot [Collections.IDictionary])
But a stack or queue would return true in that test.
Technically a
hashtable
and other Dictionary types are Collections.Queue
andStack
are also Collections, they implement theICollection
interafce.The interface you could target in this case, if I understood correctly what you're looking for, is
IList
.array
,ArrayList
,List<T>
and other collection types have this interface in common:There is also a great module you can use called ClassExplorer to find all types implementing this interface: