Object->HasProperty()? Is there any function to find out? RRS feed

  • Question

  • Hi,
    with the following line
    String ^s = dynamic_cast<String^>(o->GetType()->GetProperty("Name")->GetValue(o,nullptr));
    it is possible to read out the property "Name" of the object "o".
    With o->GetType()->GetPropery("...")->GetValue(...) you are able to read out and with SetValue(...) you can write the property of the object o.

    But how can I find out, if the object "o" has a property named "Name". When I try to access a property name that doesn't exist, I get a runtime error. I was hoping the dynamic_cast would return a nullptr. So how can I check in advance if the given property names existes in the object o?

    • Edited by wannabe_2 Wednesday, October 1, 2008 3:22 PM
    Wednesday, October 1, 2008 3:22 PM


  • Break up that statement.  Type.GetProperty() will return null if the property doesn't exist.
    Hans Passant.
    • Marked as answer by wannabe_2 Thursday, October 2, 2008 2:02 PM
    Thursday, October 2, 2008 1:20 AM

All replies