File tree 1 file changed +16
-2
lines changed
1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ public class TypeConverter : ITypeConverter
13
13
{
14
14
private readonly List < ITypeDigester > _digesters = new ( ) ;
15
15
private readonly List < ITypeConverter > _converters = new ( ) ;
16
+ private readonly Dictionary < Tuple < Type , Type > , IList < Type > > _conversionPathCache = new ( ) ;
16
17
17
18
public TypeConverter ( )
18
19
{
@@ -111,10 +112,23 @@ bool TestSpecialConvert(out object convertedValue)
111
112
return true ;
112
113
}
113
114
115
+ /// <summary>
116
+ /// Clears the internal cache of conversion paths.
117
+ /// </summary>
118
+ public void ClearCache ( )
119
+ {
120
+ _conversionPathCache . Clear ( ) ;
121
+ }
122
+
114
123
private IList < Type > GetCachedConversionPath ( Type sourceType , Type destType )
115
124
{
116
- // TODO implement GetCachedConversionPath properly
117
- return GetConversionPath ( sourceType , destType ) ;
125
+ var typeTuple = new Tuple < Type , Type > ( sourceType , destType ) ;
126
+ if ( _conversionPathCache . TryGetValue ( typeTuple , out var path ) )
127
+ return path ;
128
+
129
+ path = GetConversionPath ( sourceType , destType ) ;
130
+ _conversionPathCache [ typeTuple ] = path ;
131
+ return path ;
118
132
}
119
133
120
134
private IList < Type > GetConversionPath ( Type sourceType , Type destType )
You can’t perform that action at this time.
0 commit comments