I have a dynamic object that is generated from WebMatrix.Data:
dynamic obj; [WebMatrix.Data.DynamicRecord]
So doing something like this is fine:
int ID = obj.ID;
However, trying to access the property by string like this:
obj.GetType().GetProperty("ID").GetValue(obj, null);
and I gets the following error: Cannot perform runtime binding on a null reference
I am assuming the WebMatrix.Data.DynamicRecord type is not used the same as the dynamic type? But it is declared as dynamic.
The following does return a type of WebMatrix.Data.DynamicRecord w/ a whole array of values:
obj.GetType();
However, the following returns a type of dynamic with value of null:
obj.GetType().GetProperty("ID");
I'm guessing that's why the error, but why is it null when obj.ID does not return null?
How do I get the property by string?