79097277

Date: 2024-10-17 09:01:43
Score: 1
Natty:
Report link

Putting aside why you implement custom mapper, when there are many solutions available, you can try following:

    private static List<TDestination> MapToList<TSource, TDestination>(List<TSource> source)
    {
        var target = new List<TDestination>(source.Count);

        var addMethod = target.GetType().GetMethod("Add");

        foreach (var item in source)
        {          
            TDestination mappedObj = //DOMAP

            addMethod.Invoke(target, new object[] { mappedObj });
        }
        return target;
    }
Reasons:
  • Blacklisted phrase (1.5): any solution
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Robert