Appendix A. Enumeration Extension Methods

Contents
[ ]

LINQ Reporting Engine enables you to perform common manipulations on a sequential data through the engine’s built-in extension methods for Iterable. These extension methods mimic some extension methods of IEnumerable<T> providing the same signatures and behavior features. Thus, you can group, sort, and perform other sequential data manipulations in template expressions in a common way.

The following table describes these built-in extension methods. The following notation conventions are used within the table:

  • Selector stands for a lambda function returning a value and taking an enumeration item as its single argument. See “Using Lambda Functions” for more information.
  • ComparableSelector stands for Selector returning Comparable.
  • EnumerationSelector stands for Selector returning Iterable.
  • Predicate stands for Selector returning a Boolean value.

Examples in the following table are given using persons and otherPersons, enumerations of instances of the Person class that is defined as follows.

public class Person
{
	public String getName() { ... }
	public int getAge() { ... }
	public Iterable<Person> getChildren() { ... }
	...
}
Extension Method Examples and Notes
all(Predicate)
 persons.all(p => p.getAge() < 50)
any()
 persons.any()
any(Predicate)
 persons.any(p => p.getName() == "John Smith")
average(Selector)
 persons.average(p => p.getAge())
The input selector must return a value of any type that has predefined addition and division operators.
concat(Iterable)
 persons.concat(otherPersons)
An implicit reference conversion must exist between types of items of concatenated enumerations.
contains(Object)
 persons.contains(otherPersons.first())
count()
 persons.count()
count(Predicate)
 persons.count(p => p.getAge() > 30)
distinct()
 persons.distinct()
first()
 persons.first()
first(Predicate)
 persons.first(p => p.getAge() > 30)
firstOrDefault()
 persons.firstOrDefault()
firstOrDefault(Predicate)
 persons.firstOrDefault(p => p.getAge() > 30)
groupBy(Selector)
 persons.groupBy(p => p.getAge())
Or
 persons.groupBy(p => new { age = p.getAge(), count = p.getChildren().count() })
This method returns an enumeration of group objects. Each group has a unique key defined by the input selector and contains items of the source enumeration associated with this key. You can access the key of a group instance using the Key field. You can treat a group itself as an enumeration of items that the group contains.
last()
 persons.last()
last(Predicate)
 persons.last(p => p.getAge() > 100)
lastOrDefault()
 persons.lastOrDefault()
lastOrDefault(Predicate)
 persons.lastOrDefault(p => p.getAge() > 100)
max(ComparableSelector)
 persons.max(p => p.getAge())
min(ComparableSelector)
 persons.min(p => p.getAge())
orderBy(ComparableSelector)
 persons.orderBy(p => p.getAge())
Or
 persons.orderBy(p => p.getAge()).thenByDescending(p => p.getName())
Or
 persons.orderBy(p => p.getAge()).thenByDescending(p => p.getName()).thenBy(p => p.getChildren().count())
This method returns an enumeration ordered by a single key. To specify additional ordering keys, you can use the following extension methods of an ordered enumeration:
- thenBy(ComparableSelector)
- thenByDescending(ComparableSelector)
orderByDescending(ComparableSelector)
 persons.orderByDescending(p => p.getAge())
Or
 persons.orderByDescending(p => p.getAge()).thenByDescending(p => p.getName())
Or
 persons.orderByDescending(p => p.getAge()).thenByDescending(p => p.getName())    .thenBy(p => p.getChildren().count())
See the previous note.
select(Selector)
persons.select(p => p.getName())
selectMany(EnumerationSelector)
persons.selectMany(p => p.getChildren())
single()
 persons.single()
single(Predicate)
 persons.single(p => p.getName() == "John Smith")
singleOrDefault()
 persons.singleOrDefault()
singleOrDefault(Predicate)
 persons.singleOrDefault(p => p.getName() == "John Smith")
skip(int)
 persons.skip(10)
skipWhile(Predicate)
 persons.skipWhile(p => p.getAge() < 21)
sum(Selector)
 persons.sum(p => p.getChildren().count())
The input selector must return a value of any type that has a predefined addition operator.
take(int)
 persons.take(5)
takeWhile(Predicate)
 persons.takeWhile(p => p.getAge() < 50)
union(Iterable)
 persons.union(otherPersons)
An implicit reference conversion must exist between types of items of united enumerations.
where(Predicate)
 persons.where(p => p.getAge() > 18)