I am using reflection to populate the properties of an object.
These properties have different types: String, Nullable(double) and Nullable(long) (don\'t know how t
If the values are already of the correct type, then no: you don't have to do anything. If they might not be right (int vs float, etc), the a simple approach might be:
(edit adjusted for nulls)
Type propertyType = info.PropertyType;
if (thisPropertyValue != null)
{
Type underlyingType = Nullable.GetUnderlyingType(propertyType);
thisPropertyValue = Convert.ChangeType(
thisPropertyValue, underlyingType ?? propertyType);
}
info.SetValue(this, thisPropertyValue, null);