neubs007

neubs007

  • NA
  • 4
  • 0

Casting & Reflection

Jan 27 2005 3:24 PM
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?

Answers (3)