U4-2824 - Type Converter for string type

Created by Dirk 10 Sep 2013, 10:24:01 Updated by Shannon Deminick 11 Sep 2013, 01:57:42

Relates to: U4-2713

I suggest that Umbraco.Core.ObjectExtensions.TryConvertTo checks for destinationType == typeof(string) and returns input.ToString() in this case. Thus a PEVC can implement the ToString method. This should simply return the property value as string. Just add the following line: public static Attempt TryConvertTo(this object input, Type destinationType) { if (input == null) return Attempt.False; //new line if (destinationType == typeof(string)) return new Attempt(true, input.ToString());

if (destinationType == typeof(object)) return new Attempt(true, input); Without this views that parse property values as string (e.g. var crops = mediaItem.GetPropertyValue("crops");) will break in version 6.2.0, where the issue U4-2713 is resolved.


Dirk 10 Sep 2013, 10:24:01

fix of issue U4-2713 is kind of breaking change ?

Shannon Deminick 11 Sep 2013, 01:48:35

@Dirk, it's more of an un-breaking change but really more of a bug that has been fixed, it was never supposed to be that way. I'll chat to @Seb, it would be a shame to not release this code and just leave it broken until v7. There's really no other way around it and we're not about to go creating configuration sections for compatibility modes since that essentially means we not only have to start checking versions but also compatibility flags when doing support.

Shannon Deminick 11 Sep 2013, 01:50:47

I like this request regarding the string check, it makes good sense.

Shannon Deminick 11 Sep 2013, 01:53:58

I'm moving the logic to the bottom of the sequence though:

if (input == null) return Attempt<object>.False;

if (destinationType == typeof(object)) return new Attempt<object>(true, input);

if (input.GetType() == destinationType) return new Attempt<object>(true, input);

if (destinationType == typeof(string)) return new Attempt<object>(true, input.ToString());

Logically we should check the string after we've checked if it is already a string

Shannon Deminick 11 Sep 2013, 01:57:30

Done in 9f1d212375058cd784e6bdaf6dddf8527be8cb70

Priority: Normal

Type: Bug

State: Fixed

Assignee: Shannon Deminick

Difficulty: Normal

Category: Extensibility

Backwards Compatible: True

Fix Submitted:

Affected versions: 6.2.0

Due in version: 6.2.0


Story Points: