Convert to Method Group Resharper

前端 未结 3 858
盖世英雄少女心
盖世英雄少女心 2021-01-17 07:24

I have written a method below like this:

internal static IList GetEmpowerTaxViewsByLongAgencyAndAgencyTaxTypes(
   IList

        
相关标签:
3条回答
  • 2021-01-17 07:59

    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.

    0 讨论(0)
  • 2021-01-17 08:08

    Accept Resharper's suggestion to see what changes it makes. You can always undo them.

    If you aren't happy with the change and don't want Resharper suggesting it in future then you can disable that specific option - the others will remain available. See the answer here for details.

    Resharper: vars

    0 讨论(0)
  • 2021-01-17 08:12

    JaredPar already provided the correct answer, I just wanted to suggest a simpler implementation of the method:

    internal static IList<EmpowerTaxView> GetEmpowerTaxViewsByLongAgencyAndAgencyTaxTypes(
        IList<EmpowerCompanyTaxData> validEmpowerCompanyTaxDatas,
        IList<EmpowerTaxView> empowerTaxViews)
    {
        var results =
            from empowerCompanyTaxData in validEmpowerCompanyTaxDatas
            from etv in GetEmpowerTaxViewsByLongAgencyAndTaxType(
                empowerCompanyTaxData, empowerTaxViews)
            select etv;
        return results.ToList();
    }
    
    0 讨论(0)
提交回复
热议问题