string
。
因此,例如,假设我有一个Ship
类,其属性为Latitude
,这是一个double
.
这是我想做的:
Ship ship = new Ship();
string value = "5.5";
PropertyInfo propertyInfo = ship.GetType().GetProperty("Latitude");
propertyInfo.SetValue(ship, value, null);
就像这样,这会抛出ArgumentException
:
类型为System的对象。字符串'不能转换为'System.Double'类型。
如何将值转换为适当的类型,基于propertyInfo
?