1010using System . Runtime . Serialization ;
1111using System . Threading ;
1212using ServiceStack . Text ;
13- using ServiceStack . Text . Json ;
1413
1514namespace ServiceStack
1615{
@@ -505,6 +504,7 @@ public class AssignmentEntry
505504 public AssignmentMember To ;
506505 public PropertyGetterDelegate GetValueFn ;
507506 public PropertySetterDelegate SetValueFn ;
507+ public PropertyGetterDelegate ConvertValueFn ;
508508
509509 public AssignmentEntry ( string name , AssignmentMember @from , AssignmentMember to )
510510 {
@@ -514,6 +514,7 @@ public AssignmentEntry(string name, AssignmentMember @from, AssignmentMember to)
514514
515515 GetValueFn = From . GetGetValueFn ( ) ;
516516 SetValueFn = To . GetSetValueFn ( ) ;
517+ ConvertValueFn = TypeConverter . CreateTypeConverter ( From . Type , To . Type ) ;
517518 }
518519 }
519520
@@ -632,13 +633,9 @@ public void Populate(object to, object from,
632633 if ( ! valuePredicate ( fromValue , fromMember . PropertyInfo . PropertyType ) ) continue ;
633634 }
634635
635- if ( fromType != toType )
636+ if ( assignmentEntry . ConvertValueFn != null )
636637 {
637- var converterFn = TypeConverter . GetTypeConverter ( fromType , toType ) ;
638- if ( converterFn != null )
639- {
640- fromValue = converterFn ( fromValue ) ;
641- }
638+ fromValue = assignmentEntry . ConvertValueFn ( fromValue ) ;
642639 }
643640
644641 var setterFn = assignmentEntry . SetValueFn ;
@@ -685,17 +682,6 @@ public static PropertyGetterDelegate GetFieldGetterFn(this FieldInfo fieldInfo)
685682
686683 internal static class TypeConverter
687684 {
688- internal static ConcurrentDictionary < string , PropertyGetterDelegate > TypeConvertersCache
689- = new ConcurrentDictionary < string , PropertyGetterDelegate > ( ) ;
690-
691- public static PropertyGetterDelegate GetTypeConverter ( Type fromType , Type toType )
692- {
693- var cacheKey = AutoMappingUtils . CreateCacheKey ( fromType , toType ) ;
694-
695- return TypeConvertersCache . GetOrAdd ( cacheKey ,
696- ( Func < string , PropertyGetterDelegate > ) ( key => CreateTypeConverter ( fromType , toType ) ) ) ;
697- }
698-
699685 public static PropertyGetterDelegate CreateTypeConverter ( Type fromType , Type toType )
700686 {
701687 if ( fromType == toType )
@@ -760,17 +746,4 @@ public static PropertyGetterDelegate CreateTypeConverter(Type fromType, Type toT
760746 }
761747 }
762748
763- internal class TypeConverter < From , To >
764- {
765- static TypeConverter ( )
766- {
767- ConvertFn = TypeConverter . CreateTypeConverter ( typeof ( From ) , typeof ( To ) ) ;
768- }
769-
770- public static PropertyGetterDelegate ConvertFn ;
771- public PropertyGetterDelegate GetConvertFn ( )
772- {
773- return ConvertFn ;
774- }
775- }
776749}
0 commit comments