views:

144

answers:

1

I am trying to do the following:

  1. Given TypeInfo after reflecting on a LINQ-to-SQL object with various EntitySet<> child collections, retrieve the collection
  2. Do some operations on the collection

The code below does not compile, obviously - just looking for another way to do this [Note, "Facade" is the L2S object in question). The things that don't compile are the usages of "itemType" becuase it's a variable, not a Type name, but you get the idea:

//itemType is the reflected Type of child object

EntitySet<itemType> list = (EntitySet<itemType>)type.InvokeMember(
                                       info.Name,
                                       BindingFlags.GetProperty,
                                       null,
                                       Facade,
                                       null);


foreach (itemType o in list)
    //do something with o

The closest possible dupe I come up with is here, but there is no ultimate solution.

Thanks in advance for any ideas.

A: 

Okay, this works:

var list = type.InvokeMember(
                             info.Name,
                             BindingFlags.GetProperty,
                             null,
                             Facade,
                             null);

IEnumerable e = list as IEnumerable;

if (e == null)
    continue;

foreach (object o in e)
    //do stuff with o
sydneyos