I want to get value for a dynamic property of a dynamic object. Here is my Code..
public string ReturnProperty(object ob, string prop) { Type type = ob.GetType(); PropertyInfo pr = type.GetProperty(prop); //Here pr is null..Dont know whats wrong return pr.GetValue(ob, null).ToString(); }
My guess is that either it isn't a public property, or you've got the name wrong, or it isn't a property at all (but a public field).
It's impossible to say more without knowing what the actual type is, but that should be a start.
You mention that this is a "dynamic object" but that's not really very descriptive. Bear in mind that the CLR itself doesn't know anything about the DLR - if you mean this is a type which implements IDynamicMetaObjectProvider or extends DynamicObject, then you won't be able to get at the properties with "normal" reflection like this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With