@@ -82,24 +82,38 @@ private void InitializeConverters()
82
82
{
83
83
var converters = PropertyValueConvertersResolver . Current . Converters . ToArray ( ) ;
84
84
85
- // todo: remove Union() once we drop IPropertyEditorValueConverter support.
85
+ var defaultConverters = converters
86
+ . Where ( x => x . GetType ( ) . GetCustomAttribute < DefaultPropertyValueConverterAttribute > ( false ) != null )
87
+ . ToArray ( ) ;
88
+
86
89
_converter = null ;
87
- foreach ( var converter in converters . Union ( GetCompatConverters ( ) ) . Where ( x => x . IsConverter ( this ) ) )
90
+
91
+ //get all converters for this property type
92
+ // todo: remove Union() once we drop IPropertyEditorValueConverter support.
93
+ var foundConverters = converters . Union ( GetCompatConverters ( ) ) . Where ( x => x . IsConverter ( this ) ) . ToArray ( ) ;
94
+ if ( foundConverters . Length == 1 )
88
95
{
89
- if ( _converter == null )
90
- {
91
- _converter = converter ;
92
- }
93
- else
96
+ _converter = foundConverters [ 0 ] ;
97
+ }
98
+ else if ( foundConverters . Length > 1 )
99
+ {
100
+ //more than one was found, we need to first figure out if one of these is an Umbraco default value type converter
101
+ var nonDefault = foundConverters . Except ( defaultConverters ) . ToArray ( ) ;
102
+ if ( nonDefault . Length > 1 )
94
103
{
95
- throw new InvalidOperationException ( string . Format ( "Type '{2}' cannot be an IPropertyValueConverter"
96
- + " for property '{1}' of content type '{0}' because type '{3}' has already been detected as a converter"
97
- + " for that property, and only one converter can exist for a property." ,
98
- ContentType . Alias , PropertyTypeAlias ,
99
- converter . GetType ( ) . FullName , _converter . GetType ( ) . FullName ) ) ;
104
+ //this is not allowed, there cannot be more than 1 custom converter
105
+ throw new InvalidOperationException (
106
+ string . Format ( "Type '{2}' cannot be an IPropertyValueConverter"
107
+ + " for property '{1}' of content type '{0}' because type '{3}' has already been detected as a converter"
108
+ + " for that property, and only one converter can exist for a property." ,
109
+ ContentType . Alias , PropertyTypeAlias ,
110
+ nonDefault [ 1 ] . GetType ( ) . FullName , nonDefault [ 0 ] . GetType ( ) . FullName ) ) ;
100
111
}
101
- }
102
112
113
+ //there's only 1 custom converter registered that so use it
114
+ _converter = nonDefault [ 0 ] ;
115
+ }
116
+
103
117
// get the cache levels, quietely fixing the inconsistencies (no need to throw, really)
104
118
_sourceCacheLevel = GetCacheLevel ( _converter , PropertyCacheValue . Source ) ;
105
119
_objectCacheLevel = GetCacheLevel ( _converter , PropertyCacheValue . Object ) ;
0 commit comments