GetProperty method returns null, but I 100% sure that property I try to get exists, because I see it in debug.
I have List of dynamic rows that I get from CSV file. I need to get property value for specific row. To do that I use next code.
Type type = row.GetType();
PropertyInfo property = type.GetProperty("Site");
string propertyValue = property.GetValue(row);
But as result I receive "Object reference not set to an instance of an object." when GetValue runs. In debug I see this property and it's value for the row variable (screenshot attached). Also if I change code and try to get property directly everything works fine.
string propertyValue = row.Site;
But I can not use this approach because in the future I need to get property value by variable.
I am new in C# and .NET, please give an advice how to solve this problem.
Aucun commentaire:
Enregistrer un commentaire