我想通过Reflection设置对象的属性,值为type string.所以,举个例子,假设我有Ship一个属性为的类Latitude,它是一个double.
这是我想做的事情:
Ship ship = new Ship();
string value = "5.5";
PropertyInfo propertyInfo = ship.GetType().GetProperty("Latitude");
propertyInfo.SetValue(ship, value, null);
Run Code Online (Sandbox Code Playgroud)
这样就抛出了ArgumentException:
"System.String"类型的对象无法转换为"System.Double"类型.
如何将值转换为正确的类型,基于propertyInfo?