Vorrei impostare una proprietà di un oggetto tramite Reflection, con un valore di tipo string. Quindi, per esempio, supponiamo che io abbia una Shipclasse, con una proprietà di Latitude, che è a double.
Ecco cosa mi piacerebbe fare:
Ship ship = new Ship();
string value = "5.5";
PropertyInfo propertyInfo = ship.GetType().GetProperty("Latitude");
propertyInfo.SetValue(ship, value, null);
Come è, questo genera un ArgumentException:
L'oggetto di tipo 'System.String' non può essere convertito nel tipo 'System.Double'.
Come posso convertire il valore nel tipo corretto, basato su propertyInfo?