If all of the properties in question implement IEnumerable<string>
then it's pretty easy. Just package the "given a child, access one of its properties" logic into a lambda:
public IEnumerable<string>
GetAggregatedValues(Func<Child, IEnumerable<string>> selector)
{
var aggregatedValues = new List<string>();
return Children.Aggregate(
aggregatedValues ,
(current, child) => current.Union(selector(child)).ToList()
);
}
and call it with
GetAggregatedValues(c => c.MyList);
You can even generalize this further by making string
a type argument wherever it appears in the above code, then the same construct would also work for IEnumerable<int>
etc.