这个ReSharper片段"转换为方法组"实际上是做什么的?

Onl*_*ere 8 .net c# resharper method-group

在此输入图像描述

更改前的代码:

List<ProductBrandModel> model = brands.Select(item => Mapper.Map<ProductBrand, ProductBrandModel>(item)).ToList();
Run Code Online (Sandbox Code Playgroud)

改进后的代码:

List<ProductBrandModel> model = brands.Select(Mapper.Map<ProductBrand, ProductBrandModel>).ToList();
Run Code Online (Sandbox Code Playgroud)

这是做什么的?它是否隐式在brands集合中的每个项目上运行映射?

Tho*_*que 10

由于您直接将lambda表达式的参数传递给Mapper.Map方法,因此它完全等同于直接将此方法指定为投影Select.签名Mapper.MapFunc<TSource, TResult>委托兼容,因此R#建议直接使用方法组而不是lambda表达式.