Confused about using Reflection to examine a collection



I'm trying to write a utility that will use Reflection to examine any data
model I pass it and correctly map out this model into a tree structure. When
I say "any" [data model], in fact there will only be 3 types of items in the
very hierarchical data model:
- Classes (and nested classes)
- Collections
- Properties

I've successfully written the Reflection code to handle any combination of
classes and properties but I'm confused about what to do when I encounter a
collection. Here's some starting code I've written:

-----------------------------------------------------------------------------
Type modelType = model.GetType();
FieldInfo[] fields = modelType.GetFields();

for(int i = 0; i < fields.Length; i++)
{
Type fieldType = fields[i].FieldType;
object obj = fields[i].GetValue(model);
}
-----------------------------------------------------------------------------

Remember that I don't know ahead of time what types of collections I'll be
encountering. So though the 'fieldType' variable seems to correctly identify
the type of the collection, I can't figure out how to cast 'obj' to its true
type ... and then from there I could examine the elements that populate the
collection.

So I'm wondering two things:
1. Is what I'm asking to do possible?
2. Am I close or barking up the wrong tree?

--
Robert W.
Vancouver, BC
www.mwtech.com

.



Relevant Pages

  • Re: Reflection problem?
    ... Is this tree directly in the line ... If we dial the power output on AP 1 down ... I'm assuming that we are getting a reflection ... I get a fade margin of 18.8dB. ...
    (alt.internet.wireless)
  • Reflection problem?
    ... AP 1 18 ft agl ... There is one tree partially blocking line of site 75 feet from AP 1. ... If we dial the power output on AP 1 down ... I'm assuming that we are getting a reflection ...
    (alt.internet.wireless)
  • Re: In rubber boots with the Canon S2
    ... As for sundowns, or sunrises, they are just ... The thought of the tree reflection was ... lesson in trying to see the finished picture as it is taken. ...
    (rec.photo.digital)
  • Re: In rubber boots with the Canon S2
    ... you're a lucky guy to be able to live there. ... treelake.jpg would have benefited from full reflection of the tree, ... less feature. ...
    (rec.photo.digital)