I'm converting collection of types to collection of wrapper types
var buying = ord.Buying == null ? null : ord.Buying.Any() ? ord.Buying.Select<PurchasedBox, XXX.PurchasedBox>(x => x).ToList()
: new List<XXX.PurchasedBox>();
var trading = ord.Trading == null ? null : ord.Trading.Any() ? ord.Trading.Select<TradedBox, XXX.TradedBox>(x => x).ToList()
: new List<XXX.TradedBox>();
and also dictionary
(Any and null check) foo.ToDictionary(x => x.Key, x => (XXX.Summary)x.Value)
The types are converted using implicit conversion
implicit operator XXX.TradedBox(TradedBox box)
This pattern is repeated serval times, but I'm not sure if it's possible to write generic helper with implicit conversions e.g.
public static List<TE> ConvertList<T, TE>(List<T> list)
{
if (list == null)
return null;
// compilation error cannot convert expression
return list.Any() ? list.Select<T, TE>(x => x).ToList() : new List<TE>();
}