@@ -284,7 +284,19 @@ private static bool ListParamTypeIsValid(Type listType, FillerSetupItem currentS
284
284
/// </returns>
285
285
private static bool TypeIsDictionary ( Type type )
286
286
{
287
- return type . GetImplementedInterfaces ( ) . Any ( x => x == typeof ( IDictionary ) ) ;
287
+ Type interfaceType = typeof ( IDictionary ) ;
288
+ Type genericType = typeof ( IDictionary < , > ) ;
289
+
290
+ if ( type . IsInterface ( ) )
291
+ {
292
+ return type . IsGenericType ( ) &&
293
+ (
294
+ type . GetGenericTypeDefinition ( ) == genericType ||
295
+ type . GetImplementedInterfaces ( ) . Any ( x => x . IsGenericType ( ) && x . GetGenericTypeDefinition ( ) == typeof ( IDictionary < , > ) )
296
+ ) ;
297
+ }
298
+
299
+ return type . GetImplementedInterfaces ( ) . Any ( x => x == interfaceType ) ;
288
300
}
289
301
290
302
/// <summary>
@@ -751,7 +763,6 @@ private IDictionary GetFilledDictionary(
751
763
FillerSetupItem currentSetupItem ,
752
764
HashStack < Type > typeTracker )
753
765
{
754
- IDictionary dictionary = ( IDictionary ) Activator . CreateInstance ( propertyType ) ;
755
766
756
767
bool derivedType = ! propertyType. GetGenericTypeArguments( ) . Any ( ) ;
757
768
@@ -763,6 +774,24 @@ private IDictionary GetFilledDictionary(
763
774
? propertyType . GetGenericTypeArguments ( ) [ 1 ]
764
775
: propertyType . GetTypeInfo ( ) . BaseType . GetGenericTypeArguments ( ) [ 1 ] ;
765
776
777
+ IDictionary dictionary;
778
+ if ( ! propertyType . IsInterface ( )
779
+ && propertyType . GetImplementedInterfaces ( ) . Any ( x => x == typeof ( IDictionary ) ) )
780
+ {
781
+ dictionary = ( IDictionary) Activator. CreateInstance( propertyType) ;
782
+ }
783
+ else if ( propertyType. IsGenericType( ) && propertyType. GetGenericTypeDefinition( ) == typeof ( IDictionary< , > )
784
+ || propertyType. GetImplementedInterfaces( ) . Any( x => x. IsGenericType( ) && x. GetGenericTypeDefinition( ) == typeof ( IDictionary< , > ) ) )
785
+ {
786
+ Type openDictionaryType = typeof ( Dictionary< , > ) ;
787
+ Type genericDictionaryType = openDictionaryType. MakeGenericType( keyType, valueType) ;
788
+ dictionary = ( IDictionary) Activator. CreateInstance( genericDictionaryType) ;
789
+ }
790
+ else
791
+ {
792
+ dictionary = ( IDictionary) Activator. CreateInstance( propertyType) ;
793
+ }
794
+
766
795
int maxDictionaryItems = 0 ;
767
796
768
797
if ( keyType. IsEnum( ) )
0 commit comments