10
10
using System . Runtime . Serialization ;
11
11
using System . Threading ;
12
12
using ServiceStack . Text ;
13
- using ServiceStack . Text . Json ;
14
13
15
14
namespace ServiceStack
16
15
{
@@ -505,6 +504,7 @@ public class AssignmentEntry
505
504
public AssignmentMember To ;
506
505
public PropertyGetterDelegate GetValueFn ;
507
506
public PropertySetterDelegate SetValueFn ;
507
+ public PropertyGetterDelegate ConvertValueFn ;
508
508
509
509
public AssignmentEntry ( string name , AssignmentMember @from , AssignmentMember to )
510
510
{
@@ -514,6 +514,7 @@ public AssignmentEntry(string name, AssignmentMember @from, AssignmentMember to)
514
514
515
515
GetValueFn = From . GetGetValueFn ( ) ;
516
516
SetValueFn = To . GetSetValueFn ( ) ;
517
+ ConvertValueFn = TypeConverter . CreateTypeConverter ( From . Type , To . Type ) ;
517
518
}
518
519
}
519
520
@@ -632,13 +633,9 @@ public void Populate(object to, object from,
632
633
if ( ! valuePredicate ( fromValue , fromMember . PropertyInfo . PropertyType ) ) continue ;
633
634
}
634
635
635
- if ( fromType != toType )
636
+ if ( assignmentEntry . ConvertValueFn != null )
636
637
{
637
- var converterFn = TypeConverter . GetTypeConverter ( fromType , toType ) ;
638
- if ( converterFn != null )
639
- {
640
- fromValue = converterFn ( fromValue ) ;
641
- }
638
+ fromValue = assignmentEntry . ConvertValueFn ( fromValue ) ;
642
639
}
643
640
644
641
var setterFn = assignmentEntry . SetValueFn ;
@@ -685,17 +682,6 @@ public static PropertyGetterDelegate GetFieldGetterFn(this FieldInfo fieldInfo)
685
682
686
683
internal static class TypeConverter
687
684
{
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
-
699
685
public static PropertyGetterDelegate CreateTypeConverter ( Type fromType , Type toType )
700
686
{
701
687
if ( fromType == toType )
@@ -760,17 +746,4 @@ public static PropertyGetterDelegate CreateTypeConverter(Type fromType, Type toT
760
746
}
761
747
}
762
748
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
- }
776
749
}
0 commit comments