I saw the post on ways to handle an infinite IEnumerable, but I didn't see a good answer for testing if an enumerable is infinite.
My end goal is to write a function for all collection types in .NET, but to safely traverse the whole collection without the risk of long wait times due to some infinite collection.
OPT1: I thought I might be able tell if an enumerable is infinite and throw an exception. However, I figure this would be the approach for .NET aggregate LINQ expressions (e.g. Max, Count) if it were possible.
- EDIT: As suspected, another question was suggested that directly declares this option impossible
OPT2: Is there some other abstraction that supports most all enumerable types, but disallows infinite elements? ICollection
looks promising, supports lists and arrays, but not Queues or many custom IEnumerables.
I'm also having a hard time determining if ICollection can be infinite or not.
Suggestions?