Casting & Reflection
I have to perform a cast of an object based on the type of another object.
I can get it to work for one instance by coding in the objects.
eg.
Person p = (Person)dgi.DataItem;
If I look at dgi.DataItem.getType() I can see that, in this case, it is a person object.
Now what do I need to do to abstract that out so dgi.DataItem can be a different objects within my solution?
I figure I can use reflection from dgi.DataItem to fill in the ???'s below, but I'm not sure how.
??? p = (???)dgi.DataItem
So if dgi.DataItem.getType()... is a Dog object it would render the statement as such:
Dog p =(Dog)dgi.DataItem
Any Ideas?
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.

holy_bins7 pointsPosted Jan 27, 2005, 11:01 AM EST
neubs0074 pointsPosted Jan 27, 2005, 11:15 AM EST
bilnaadRank #2,169 · 655 pointsPosted Jan 27, 2005, 11:40 AM EST