PropertyInfo.GetValue() returns an object. I need to cast that object to the type returned from PropertyInfo.PropertyType. How can I do it? The only way I think is a switch on PropertyType.ToString(). Is there another way? TIA
It IS possible. With the PropertyInfo Value and PropertyType you can: var typedPropertyVal = Convert.ChangeType(propertyVal, propertyType); This is the post that helped me: technico.qnownow.com/reflection-setvalue-type-conversion
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