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

Module Helpers

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

Import path

import Linq.Helpers

Imports

csharp

The default C# QL library.

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 foreach statement fes could be converted to a .Cast() call. That is, the loop variable is accessed only in the first statement of the block, and the access is a cast. The first statement needs to be a LocalVariableDeclStmt.

missedOfTypeOpportunity

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

missedSelectOpportunity

Holds if foreach statement fes could be converted to a .Select() call. That is, the loop variable is accessed only in the first statement of the block, and the access is not a cast. The first statement needs to be a LocalVariableDeclStmt.

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.

IEnumerableSequence

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

SelectCall

A LINQ Select(…) call.