Iterate through custom collections using Reflection
-
This question has probably been asked a million times here but I'll be danged if I can't find any answers to this. I am trying to write a couple of methods that I can pass any custom class or collection into and using reflection it will pull out the properties of the class and format things out into a report. I've got the method for handling an individual class. What I'm having trouble with is the collection. Does anybody know of how to take a custom collection and use reflection to pull out each individual item from the collection? Once I have the item, I will pass it into my other method for pulling out the properties. Most of the collections I will be dealing with are derived from List. Could the collection method accept an object array (Object[]) without any conversion issues or should it accept the collection as a single Object?
My mind is like an aluminum trap. Some things get caught in the trap, and some things bend the trap and get away.
-
This question has probably been asked a million times here but I'll be danged if I can't find any answers to this. I am trying to write a couple of methods that I can pass any custom class or collection into and using reflection it will pull out the properties of the class and format things out into a report. I've got the method for handling an individual class. What I'm having trouble with is the collection. Does anybody know of how to take a custom collection and use reflection to pull out each individual item from the collection? Once I have the item, I will pass it into my other method for pulling out the properties. Most of the collections I will be dealing with are derived from List. Could the collection method accept an object array (Object[]) without any conversion issues or should it accept the collection as a single Object?
My mind is like an aluminum trap. Some things get caught in the trap, and some things bend the trap and get away.
Sounds to me like you would want to have the method take IEnumerable<T>