Rather than doing what is essentially a large switch statement for every possible type, is there a better more generic way of converting to a specific type with reflection? I've looked up TypeConverter but don't understand the documentation.
if (header.Property.PropertyType == typeof(Int32))
{
header.Property.SetValue(instanceOfTrade, value.ToInt(), null);
}
else if (header.Property.PropertyType == typeof(decimal))
{
header.Property.SetValue(instanceOfTrade, value.ToDecimal(), null);
}
else if (header.Property.PropertyType == typeof(DateTime))
{
header.Property.SetValue(instanceOfTrade, value.TryToDateTime(), null);
}
else
{
header.Property.SetValue(instanceOfTrade, value.ToString(), null);
}