@@ -165,6 +165,8 @@ public bool IsDictionaryType(Type type)
165165
166166 return type . GetInterface ( "System.Collections.Generic.IDictionary`2" ) != null
167167 || ( type . FullName != null && type . FullName . StartsWith ( "System.Collections.Generic.IDictionary`2" ) )
168+ || type . GetInterface ( "System.Collections.Generic.IReadOnlyDictionary`2" ) != null
169+ || ( type . FullName != null && type . FullName . StartsWith ( "System.Collections.Generic.IReadOnlyDictionary`2" ) )
168170 || type . GetInterface ( "System.Collections.IDictionary" ) != null
169171 || ( type . FullName != null && type . FullName . StartsWith ( "System.Collections.IDictionary" ) ) ;
170172 }
@@ -338,10 +340,14 @@ public IEnumerable<string> GetTypeUnions(MemberInfo memberInfo)
338340 /// <returns></returns>
339341 private string GetTsDictionaryTypeName ( Type type )
340342 {
341- // handle IDictionary<,>
343+ // handle IDictionary<,> and IReadOnlyDictionary<,>
342344
343- Type dictionary2Interface = type . GetInterface ( "System.Collections.Generic.IDictionary`2" ) ;
344- if ( dictionary2Interface != null || ( type . FullName != null && type . FullName . StartsWith ( "System.Collections.Generic.IDictionary`2" ) ) )
345+ Type [ ] dictionary2Interfaces = new [ ] {
346+ type . GetInterface ( "System.Collections.Generic.IDictionary`2" ) ,
347+ type . GetInterface ( "System.Collections.Generic.IReadOnlyDictionary`2" )
348+ } ;
349+ Type dictionary2Interface = dictionary2Interfaces . LastOrDefault ( i => i != null ) ;
350+ if ( dictionary2Interface != null || ( type . FullName != null && ( type . FullName . StartsWith ( "System.Collections.Generic.IDictionary`2" ) || type . FullName . StartsWith ( "System.Collections.Generic.IReadOnlyDictionary`2" ) ) ) )
345351 {
346352 Type dictionaryType = dictionary2Interface ?? type ;
347353 Type keyType = dictionaryType . GetGenericArguments ( ) [ 0 ] ;
0 commit comments