Skip to content

Commit 7caa832

Browse files
committed
Implemented GetValidatedMappingType() for collection mapping
The `PopulateTargetCollectionAsync()` method takes topics from a collection on the source topic and maps them to models in a collection property on the target model. If the mapped topic type isn't compatible with the collection property type, then it is excluded, as a way of filtering out incompatible types. By incorporating the new `GetValidatedMappingType()` method (88c7fba), we pre-validate the type compatibility, instead of requiring that the model first be mapped—a potentially expensive operation. This satisfies relationships, children, and other collections, as called for by #83.
1 parent 88c7fba commit 7caa832

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

OnTopic/Mapping/TopicMappingService.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -978,13 +978,11 @@ configuration.ContentTypeFilter is not null &&
978978
}
979979

980980
//Map child topic to target DTO
981-
var childDto = (object)childTopic;
981+
var childDto = (object)childTopic;
982982
if (!typeof(Topic).IsAssignableFrom(listType)) {
983-
if (configuration.MapAs != null) {
984-
taskQueue.Add(MapAsync(childTopic, configuration.MapAs, configuration.IncludeAssociations, cache));
985-
}
986-
else {
987-
taskQueue.Add(MapAsync(childTopic, configuration.IncludeAssociations, cache));
983+
var mappingType = GetValidatedMappingType(configuration.MapAs, listType)?? GetValidatedMappingType(childTopic, listType);
984+
if (mappingType is not null) {
985+
taskQueue.Add(MapAsync(childTopic, mappingType, configuration.IncludeAssociations, cache));
988986
}
989987
}
990988
else {
@@ -1009,7 +1007,7 @@ configuration.ContentTypeFilter is not null &&
10091007
| Function: Add to List
10101008
\-----------------------------------------------------------------------------------------------------------------------*/
10111009
void AddToList(object dto) {
1012-
if (dto is not null && listType.IsAssignableFrom(dto.GetType())) {
1010+
if (dto is not null) {
10131011
try {
10141012
targetList.Add(dto);
10151013
}

0 commit comments

Comments
 (0)