I am storing object values in strings e.g.,
string[] values = new string[] { \"213.4\", \"10\", \"hello\", \"MyValue\"};
is there any way to ge
Perhaps the first thing to try is:
object value = Convert.ChangeType(text, info.PropertyType);
However, this doesn't support extensibility via custom types; if you need that, how about:
TypeConverter tc = TypeDescriptor.GetConverter(info.PropertyType);
object value = tc.ConvertFromString(null, CultureInfo.InvariantCulture, text);
info.SetValue(obj, value, null);
Or:
info.SetValue(obj, AwesomeFunction("20.53", info.PropertyType), null);
with
public object AwesomeFunction(string text, Type type) {
TypeConverter tc = TypeDescriptor.GetConverter(type);
return tc.ConvertFromString(null, CultureInfo.InvariantCulture, text);
}