cezarypiatek / MappingGenerator

:arrows_counterclockwise: "AutoMapper" like, Roslyn based, code fix provider that allows to generate mapping code in design time.
https://marketplace.visualstudio.com/items?itemName=54748ff9-45fc-43c2-8ec5-cf7912bc3b84.mappinggenerator
MIT License
1.03k stars 120 forks source link

Improve naming for lambda parameter in collection mapping #38

Closed cezarypiatek closed 5 years ago

cezarypiatek commented 5 years ago

1) Convert plural to singular form

 public static List<YY> Map(List<XX> categories)
        {
            return categories.Select(category => new YY()
            {
                Id = category.Id,
                Name = category.Name
            }).ToList();
        }

2) Use lambda parameter name as a prefix

 public static List<ZZ> Map(List<XX> categories)
        {
            return categories.Select(category => new ZZ()
            {
                CategoryId = category.Id,
                CategoryName = category.Name
            }).ToList();
        }

3) Use item for lambda parameter name for generic collection name

public static List<ZZ> MapNew(List<XX> dictionary)
        {
            return dictionary.Select(item => new ZZ()
            {
                Id = item.Id,
                Name = item.Name
            }).ToList();
        }

4) Convert plural to singular from name postfixed with generic collection name

public static List<ZZ> MapNew(List<XX> usersList)
        {
            return usersList.Select(user => new ZZ()
            {
                Id = user.Id,
                Name = user.Name
            }).ToList();
        }