Collect types that implement a specific non-cast interface?
Basically, I want to know if all the types in a particular namespace implements a particular interface, for example IEnumerable
.
I know I can:
foreach type ...
if type is IEnumerable
...
But I don't want the type to just be queried if it implements the interface, because the cast will be thrown anyway.
0
source to share
3 answers
Assuming I read it correctly, you want a list of types in an enum that implement a specific interface or supertype. Perhaps Enumerable.OfType (this IEnumerable source) is helpful?
var enumerables = myListOfThingsToCheck.OfType<IEnumerable>();
+3
source to share