This is a segue to my previous question:
Looking for a better way to sort my List<T>
Basically, I have a similar situation where I need to do a .GroupBy() on about 40 different fields.
The original code would have used a giant switch statement, but I’d like to know if there’s a better way to this.
What I’d really like to do is something like:
// not sure what the GroupBy selector function def should be...
Dictionary<PortfolioMapping, Func<Holding, ???>> groupByMappings;
which I can use to group by like:
myPortfolioHoldings.GroupBy(groupByMaping[frmGroupBySelector.SelectedColumn]);
What would be the correct way to go about this?
You should be able to group by
object:This will work as long as your mapping functions return either:
IEquatable<T>EqualsandGetHashCodecorrectly