0

I am using reflection to dynamically generate forms in my application. When dealing with properties that have relationships I need to be able to dynamically call a collection.

How can I replace:

foreach (Customer c in Db.Customers)
{

}

With something like this:

foreach (dynamic d in Db["Customers"])
{

}

or like this

foreach (dynamic d in Db.typeof(Customer))
{

}
Tom Crosman
  • 1,137
  • 1
  • 12
  • 37

1 Answers1

0

Would this work for you?

foreach (dynamic d in (DB.GetType().GetProperty("Customers")).GetValue(DB, null)){
}

In more understandable way

var propertyInfo = DB.GetType().GetProperty("Customers");
var value = propertyInfo.GetValue(DB, null);
Lasal Sethiya
  • 201
  • 1
  • 4
  • 17