I’m trying to get the value from a PropertyInfo[], but I can’t get it to work:
foreach (var propertyInfo in foo.GetType().GetProperties())
{
var value = propertyInfo.GetValue(this, null);
}
Exception:
Object does not match target type.
Isn’t this how it’s supposed to be done?
You’re trying to get properties from
thiswhen you originally fetched thePropertyInfos fromfoo.GetType(). So this would be more appropriate:That’s assuming you want to effectively get
foo.SomePropertyetc.