in src/DeloitteDigital.Atlas/Mapping/ChildrenMapping/ChildrenMapper.cs [12:41]
public void HandleMapping<TModel>(TModel model, Item item, IPropertyMeta propertyMeta, ICache cache, IItemMapper itemMapper)
{
var childMapPropertyMeta = propertyMeta as IChildMappingPropertyMeta;
if (childMapPropertyMeta == null || model.GetType().GetProperty(propertyMeta.PropertyName).Equals(null))
{
return;
}
var property = model.GetType().GetProperty(propertyMeta.PropertyName);
var listType = property.PropertyType.GetGenericArguments()[0];
var genericList = typeof(List<>).MakeGenericType(listType);
var collection = Activator.CreateInstance(genericList) as IList;
if (collection == null)
{
return;
}
var parentItem = GetParentItemForChildCollection(item, childMapPropertyMeta);
if (parentItem != null)
{
foreach (Item childItem in parentItem.Children)
{
var childObject = Activator.CreateInstance(listType) as dynamic;
itemMapper.Map(childObject, childItem);
collection.Add(childObject);
}
}
property.SetValue(model, collection);
}