Enumeration Extension Methods

LINQ Reporting Engine enables you to perform common manipulations on a sequential data through the engine’s built-in extension methods for IEnumerable. 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 familiar 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 IComparable.
  • EnumerationSelector stands for Selector returning IEnumerable.
  • 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 Name { get { ... } }
    public int Age { get { ... } }
    public IEnumerable<Person> Children { get { ... } }
    ...
}
Extension MethodExamples and Notes
All(Predicate)
persons.All(p => p.Age < 50)
Any()
persons.Any()
Any(Predicate)
persons.Any(p => p.Name == "John Smith")
Average(Selector)
persons.Average(p => p.Age)
The input selector must return a value of any type that has predefined or user-defined addition and division operators.
Concat(IEnumerable)
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.Age > 30)
Distinct()
persons.Distinct()
First()
persons.First()
First(Predicate)
persons.First(p => p.Age > 30)
FirstOrDefault()
persons.FirstOrDefault()
FirstOrDefault(Predicate)
persons.FirstOrDefault(p => p.Age > 30)
GroupBy(Selector)
persons.GroupBy(p => p.Age)
Or
persons.GroupBy(    p => new { Age = p.Age, Count = p.Children.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 property. You can treat a group itself as an enumeration of items that the group contains.
Last()
persons.Last()
Last(Predicate)
persons.Last(p => p.Age > 100)
LastOrDefault()
persons.LastOrDefault()
LastOrDefault(Predicate)
persons.LastOrDefault(p => p.Age > 100)
Max(ComparableSelector)
persons.Max(p => p.Age)
Min(ComparableSelector)
persons.Min(p => p.Age)
OrderBy(ComparableSelector)
persons.OrderBy(p => p.Age)
Or
persons.OrderBy(p => p.Age).ThenByDescending(p => p.Name)
Or
persons.OrderBy(p => p.Age).ThenByDescending(p => p.Name).ThenBy(p => p.Children.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.Age)
Or
persons.OrderByDescending(p => p.Age).ThenByDescending(p => p.Name)
Or
persons.OrderByDescending(p => p.Age).ThenByDescending(p => p.Name).ThenBy(p => p.Children.Count())
See the previous note.
Select(Selector)
persons.Select(p => p.Name)
SelectMany(EnumerationSelector)
persons.SelectMany(p => p.Children)
Single()
persons.Single()
Single(Predicate)
persons.Single(p => p.Name == "John Smith")
SingleOrDefault()
persons.SingleOrDefault()
SingleOrDefault(Predicate)
persons.SingleOrDefault(p => p.Name == "John Smith")
Skip(int)
persons.Skip(10)
SkipWhile(Predicate)
persons.SkipWhile(p => p.Age < 21)
Sum(Selector)
persons.Sum(p => p.Children.Count())
The input selector must return a value of any type that has a predefined or user-defined addition operator.
Take(int)
persons.Take(5)
TakeWhile(Predicate)
persons.TakeWhile(p => p.Age < 50)
Union(IEnumerable)
persons.Union(otherPersons)
An implicit reference conversion must exist between types of items of united enumerations.
Where(Predicate)
persons.Where(p => p.Age > 18)

© Aspose Pty Ltd 2001-2022. All Rights Reserved.