Skip to content

Commit 560aaca

Browse files
committed
Added mapping support for derived collections
Previously, the collection support of the `TopicMappingService` expected that the collection would be generic, and that's where it would determine the compatible list type. That works fine if, in fact, the collection type _is_ generic. It fails, however, if the class derives from a generic type. In that case, instead, we need to loop through the available interfaces, identify the `IList<T>` interface, and then get the generic type from _that_ interface, since we won't be able to get it off the actual non-generic type. This implements that support.
1 parent 3dc0de2 commit 560aaca

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

OnTopic/Mapping/TopicMappingService.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,9 +635,11 @@ MappedTopicCache cache
635635
| Determine the type of item in the list
636636
\-----------------------------------------------------------------------------------------------------------------------*/
637637
var listType = typeof(ITopicViewModel);
638-
if (configuration.Property.PropertyType.IsGenericType) {
639-
//Uses last argument in case it's a KeyedCollection; in that case, we want the TItem type
640-
listType = configuration.Property.PropertyType.GetGenericArguments().Last();
638+
foreach (var type in configuration.Property.PropertyType.GetInterfaces()) {
639+
if (type.IsGenericType && typeof(IList<>) == type.GetGenericTypeDefinition()) {
640+
//Uses last argument in case it's a KeyedCollection; in that case, we want the TItem type
641+
listType = type.GetGenericArguments().Last();
642+
}
641643
}
642644

643645
/*------------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)