I have different objects like: CallingItem
, TransferItem
or FlowItem
and I have an appropriated String containing the needed property of the object e.g. Message.Start.MsgNumber
or Data.Name
Examples of my objects with property:
TransferItem.Message.Start.MsgNumber = 5;
CallingItem.Data.Name = "Mike"
Method call:
GetProperty(TransferItem, "Message.Start.MsgNumber");
GetProperty(CallingItem, "Data.Name");
Method GetProperty:
public void GetProperty(object myObject, string propertyString)
{
Type t = myObject.GetType();
PropertyInfo pinfo = t.GetProperty(propertyString);
if (pinfo == null)
return;
object value = pinfo.GetValue(null, null);
}
But pinfo is always null. How can I get the property value of my object?