Link to home
Start Free TrialLog in
Avatar of ipjyo
ipjyoFlag for United States of America

asked on

Reflection GetValue method throwing an exception when there is no value in the property?

hi,

I am using Reflection to check if a property exists and get the value.
It is working fine when there is a value in that property. But "GetValue" is throwing an exception "Object reference not set to instance of an object" when there is no value.

How can I make sure it does not throw exception if there is no value. It looks like I need to check some other property before invoking GetValue. Thanks for any help.

PropertyInfo info = null;
info = Parties[i - 1].GetType().GetProperty(partyfield.Node);
if (info != null)
{
fieldvalue = info.GetValue(Parties[i - 1], null).ToString();
}
ASKER CERTIFIED SOLUTION
Avatar of Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs)
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ipjyo

ASKER

Thank you.
Avatar of ipjyo

ASKER

It is working now.