CodeQL library for C#
codeql/csharp-all 3.1.1-dev (changelog, source)
Search

Module Helpers

Helpers.qll Provides helper classes and methods related to LINQ.

Import path

import Linq.Helpers

Predicates

isEnumerableType

Holds if the type’s qualified name is “System.Linq.Enumerable”

isIEnumerableType

Holds if the type’s qualified name starts with “System.Collections.Generic.IEnumerable”

missedAllOpportunity

Holds if foreach statement fes could be converted to a .All() call. That is, the ForeachStmt contains a single if with a condition that accesses the loop variable and with a body that assigns false to a variable and breaks out of the foreach.

missedCastOpportunity

Holds if the foreach statement fes can be converted to a .Cast() call. That is, the loop variable is accessed only in the first statement of the block, the access is a cast, and the first statement is a local variable declaration statement s.

missedOfTypeOpportunity

Holds if foreach statement fes can be converted to an .OfType() call. That is, the loop variable is accessed only in the first statement of the block, the access is a cast with the as operator, and the first statement is a local variable declaration statement s.

missedSelectOpportunity

Holds if foreach statement fes can be converted to a .Select() call. That is, the loop variable is accessed only in the first statement of the block, the access is not a cast, and the first statement is a local variable declaration statement s.

missedWhereOpportunity

Holds if foreach statement fes could be converted to a .Where() call. That is, first statement of the loop is an if, which accesses the loop variable, and the body of the if is either a continue or there’s nothing else in the loop than the if.

Classes

AnyCall

A LINQ Any(…) call.

CountCall

A LINQ Count(…) call.

ForeachStmtEnumerable

A class of foreach statements where the iterable expression supports the use of the LINQ extension methods on IEnumerable.

ForeachStmtGenericEnumerable

A class of foreach statements where the iterable expression supports the use of the LINQ extension methods on IEnumerable<T>.

IEnumerableSequence

A variable of type IEnumerable<T>, for some T.

SelectCall

A LINQ Select(…) call.