2

I got this code:

    //Group by week
    if (datarows.All(row => row.Date!= null))
    {
        List<IGrouping<string, ZeErwDto>> groupByWeek =
            datarows.GroupBy(row => row.Week.ToString() + row.Date.Value.Year.ToString())
                .ToList();

The part "row.Date.Value" remaines underlined regardless of my null-check with a "Possible 'System.InvalidOperationException'" warning.

Is this a false positive warning or have I missed something?

L. Schmidt
  • 31
  • 3
  • I just stop reading and cant read past the first underscore, sorry – TheGeneral Mar 06 '18 at 09:11
  • Resharper doesn't do path analysing, it's simply not clever enough to see that `Enumerable.All` handles it. But since it's looping a (possibly large) collection, it could be that the information is outdated at the `GroupBy`, so resharper does it right to warn you. – Tim Schmelter Mar 06 '18 at 09:13
  • the "null check" in the `All` operation does not semantically survive until two lines later. – Cee McSharpface Mar 06 '18 at 09:13
  • Yes that's just false positive. Side note: underscore is typically used for variables you don't care about and don't use. Here, you use that variable, so underscore is not an appropriate name for it. – Evk Mar 06 '18 at 09:16
  • Thank you @Evk (and other helpful answers)! So I am going to suppress the warning! – L. Schmidt Mar 06 '18 at 09:17
  • Some user deleted his comments so two of mine lost the context: "datarows" is of type IList and CustomType is mainly populated by one datatable of a database but enriched with other joined data via EF. – L. Schmidt Mar 06 '18 at 09:55
  • Edit: Exchanged the underscore with "row", hope that's a little better readable. Thanks for the hint! – L. Schmidt Mar 06 '18 at 10:15

0 Answers0