Skip to content

Commit 6523559

Browse files
committed
Support IReadOnlyDictionary
1 parent 7f353d5 commit 6523559

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/TypeGen/TypeGen.Core/Generator/Services/TypeService.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)