Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert to Method Group Resharper

Tags:

c#

resharper

I have written a method below like this:

internal static IList<EmpowerTaxView> GetEmpowerTaxViewsByLongAgencyAndAgencyTaxTypes(    IList<EmpowerCompanyTaxData> validEmpowerCompanyTaxDatas,    IList<EmpowerTaxView> empowerTaxViews) {     IList<EmpowerTaxView> result = new List<EmpowerTaxView>();      foreach (EmpowerCompanyTaxData empowerCompanyTaxData in validEmpowerCompanyTaxDatas)     {          IList<EmpowerTaxView> validEmpowerTaxViews =            GetEmpowerTaxViewsByLongAgencyAndTaxType(              empowerCompanyTaxData, empowerTaxViews);           validEmpowerTaxViews.ToList().ForEach(delegate(EmpowerTaxView etv)          {               result.Add(etv);             });        }      return result; } 

And for this method, the resharper says:

validEmpowerTaxViews.ToList().ForEach(delegate(EmpowerTaxView etv) {     result.Add(etv);    }); 

Convert to Method Group. What does this mean and what should be done to get rid of this.

like image 392
SaiBand Avatar asked Aug 08 '11 21:08

SaiBand


1 Answers

What Resharper means is that you can express the ForEach code more simply by using the method group Add. Example:

validEmpowerTaxViews.ToList().Foreach(result.Add); 

The method group defined by Add is compatible with the delegate expected by ForEach and hence the C# compiler will take care of doing the conversion. The default in Resharper is to prefer method groups over lambdas and explicit delegate creation statements.

like image 62
JaredPar Avatar answered Sep 17 '22 11:09

JaredPar