using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace System.Linq
{
/// Provides a set of static (Shared in Visual Basic) methods for querying objects that implement .
// Token: 0x02000032 RID: 50
public static class Enumerable
{
/// Applies an accumulator function over a sequence.
/// The final accumulator value.
/// An to aggregate over.
/// An accumulator function to be invoked on each element.
/// The type of the elements of .
///
/// or is null.
///
/// contains no elements.
// Token: 0x0600027B RID: 635 RVA: 0x0000CE3C File Offset: 0x0000B03C
public static TSource Aggregate(this IEnumerable source, Func func)
{
Check.SourceAndFunc(source, func);
TSource tsource3;
using (IEnumerator enumerator = source.GetEnumerator())
{
if (!enumerator.MoveNext())
{
throw new InvalidOperationException("No elements in source list");
}
TSource tsource = enumerator.Current;
while (enumerator.MoveNext())
{
TSource tsource2 = enumerator.Current;
tsource = func(tsource, tsource2);
}
tsource3 = tsource;
}
return tsource3;
}
/// Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value.
/// The final accumulator value.
/// An to aggregate over.
/// The initial accumulator value.
/// An accumulator function to be invoked on each element.
/// The type of the elements of .
/// The type of the accumulator value.
///
/// or is null.
// Token: 0x0600027C RID: 636 RVA: 0x0000CEC8 File Offset: 0x0000B0C8
public static TAccumulate Aggregate(this IEnumerable source, TAccumulate seed, Func func)
{
Check.SourceAndFunc(source, func);
TAccumulate taccumulate = seed;
foreach (TSource tsource in source)
{
taccumulate = func(taccumulate, tsource);
}
return taccumulate;
}
/// Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.
/// The transformed final accumulator value.
/// An to aggregate over.
/// The initial accumulator value.
/// An accumulator function to be invoked on each element.
/// A function to transform the final accumulator value into the result value.
/// The type of the elements of .
/// The type of the accumulator value.
/// The type of the resulting value.
///
/// or or is null.
// Token: 0x0600027D RID: 637 RVA: 0x0000CF34 File Offset: 0x0000B134
public static TResult Aggregate(this IEnumerable source, TAccumulate seed, Func func, Func resultSelector)
{
Check.SourceAndFunc(source, func);
if (resultSelector == null)
{
throw new ArgumentNullException("resultSelector");
}
TAccumulate taccumulate = seed;
foreach (TSource tsource in source)
{
taccumulate = func(taccumulate, tsource);
}
return resultSelector(taccumulate);
}
/// Determines whether all elements of a sequence satisfy a condition.
/// true if every element of the source sequence passes the test in the specified predicate, or if the sequence is empty; otherwise, false.
/// An that contains the elements to apply the predicate to.
/// A function to test each element for a condition.
/// The type of the elements of .
///
/// or is null.
// Token: 0x0600027E RID: 638 RVA: 0x0000CFB8 File Offset: 0x0000B1B8
public static bool All(this IEnumerable source, Func predicate)
{
Check.SourceAndPredicate(source, predicate);
foreach (TSource tsource in source)
{
if (!predicate(tsource))
{
return false;
}
}
return true;
}
/// Determines whether a sequence contains any elements.
/// true if the source sequence contains any elements; otherwise, false.
/// The to check for emptiness.
/// The type of the elements of .
///
/// is null.
// Token: 0x0600027F RID: 639 RVA: 0x0000D02C File Offset: 0x0000B22C
public static bool Any(this IEnumerable source)
{
Check.Source(source);
ICollection collection = source as ICollection;
if (collection != null)
{
return collection.Count > 0;
}
bool flag;
using (IEnumerator enumerator = source.GetEnumerator())
{
flag = enumerator.MoveNext();
}
return flag;
}
/// Determines whether any element of a sequence satisfies a condition.
/// true if any elements in the source sequence pass the test in the specified predicate; otherwise, false.
/// An whose elements to apply the predicate to.
/// A function to test each element for a condition.
/// The type of the elements of .
///
/// or is null.
// Token: 0x06000280 RID: 640 RVA: 0x0000D098 File Offset: 0x0000B298
public static bool Any(this IEnumerable source, Func predicate)
{
Check.SourceAndPredicate(source, predicate);
foreach (TSource tsource in source)
{
if (predicate(tsource))
{
return true;
}
}
return false;
}
/// Returns the input typed as .
/// The input sequence typed as .
/// The sequence to type as .
/// The type of the elements of .
// Token: 0x06000281 RID: 641 RVA: 0x0000D10C File Offset: 0x0000B30C
public static IEnumerable AsEnumerable(this IEnumerable source)
{
return source;
}
/// Computes the average of a sequence of values.
/// The average of the sequence of values.
/// A sequence of values to calculate the average of.
///
/// is null.
///
/// contains no elements.
/// The sum of the elements in the sequence is larger than .
// Token: 0x06000282 RID: 642 RVA: 0x0000D110 File Offset: 0x0000B310
public static double Average(this IEnumerable source)
{
Check.Source(source);
long num = 0L;
int num2 = 0;
foreach (int num3 in source)
{
checked
{
num += unchecked((long)num3);
}
num2++;
}
if (num2 == 0)
{
throw new InvalidOperationException();
}
return (double)num / (double)num2;
}
/// Computes the average of a sequence of values.
/// The average of the sequence of values.
/// A sequence of values to calculate the average of.
///
/// is null.
///
/// contains no elements.
/// The sum of the elements in the sequence is larger than .
// Token: 0x06000283 RID: 643 RVA: 0x0000D18C File Offset: 0x0000B38C
public static double Average(this IEnumerable source)
{
Check.Source(source);
long num = 0L;
long num2 = 0L;
foreach (long num3 in source)
{
num += num3;
num2 += 1L;
}
if (num2 == 0L)
{
throw new InvalidOperationException();
}
return (double)num / (double)num2;
}
/// Computes the average of a sequence of values.
/// The average of the sequence of values.
/// A sequence of values to calculate the average of.
///
/// is null.
///
/// contains no elements.
// Token: 0x06000284 RID: 644 RVA: 0x0000D20C File Offset: 0x0000B40C
public static double Average(this IEnumerable source)
{
Check.Source(source);
double num = 0.0;
long num2 = 0L;
foreach (double num3 in source)
{
double num4 = num3;
num += num4;
num2 += 1L;
}
if (num2 == 0L)
{
throw new InvalidOperationException();
}
return num / (double)num2;
}
/// Computes the average of a sequence of values.
/// The average of the sequence of values.
/// A sequence of values to calculate the average of.
///
/// is null.
///
/// contains no elements.
// Token: 0x06000285 RID: 645 RVA: 0x0000D290 File Offset: 0x0000B490
public static float Average(this IEnumerable source)
{
Check.Source(source);
float num = 0f;
long num2 = 0L;
foreach (float num3 in source)
{
float num4 = num3;
num += num4;
num2 += 1L;
}
if (num2 == 0L)
{
throw new InvalidOperationException();
}
return num / (float)num2;
}
/// Computes the average of a sequence of values.
/// The average of the sequence of values.
/// A sequence of values to calculate the average of.
///
/// is null.
///
/// contains no elements.
/// The sum of the elements in the sequence is larger than .
// Token: 0x06000286 RID: 646 RVA: 0x0000D310 File Offset: 0x0000B510
public static decimal Average(this IEnumerable source)
{
Check.Source(source);
decimal num = 0m;
long num2 = 0L;
foreach (decimal num3 in source)
{
num += num3;
num2 += 1L;
}
if (num2 == 0L)
{
throw new InvalidOperationException();
}
return num / num2;
}
/// Computes the average of a sequence of nullable values.
/// The average of the sequence of values, or null if the source sequence is empty or contains only values that are null.
/// A sequence of nullable values to calculate the average of.
///
/// is null.
/// The sum of the elements in the sequence is larger than .
// Token: 0x06000287 RID: 647 RVA: 0x0000D39C File Offset: 0x0000B59C
public static double? Average(this IEnumerable source)
{
Check.Source(source);
long num = 0L;
long num2 = 0L;
foreach (int? num3 in source)
{
if (num3 != null)
{
num += (long)num3.Value;
num2 += 1L;
}
}
if (num2 == 0L)
{
return null;
}
return new double?((double)num / (double)num2);
}
/// Computes the average of a sequence of nullable values.
/// The average of the sequence of values, or null if the source sequence is empty or contains only values that are null.
/// A sequence of nullable values to calculate the average of.
///
/// is null.
/// The sum of the elements in the sequence is larger than .
// Token: 0x06000288 RID: 648 RVA: 0x0000D43C File Offset: 0x0000B63C
public static double? Average(this IEnumerable source)
{
Check.Source(source);
long num = 0L;
long num2 = 0L;
foreach (long? num3 in source)
{
if (num3 != null)
{
checked
{
num += num3.Value;
}
num2 += 1L;
}
}
if (num2 == 0L)
{
return null;
}
return new double?((double)num / (double)num2);
}
/// Computes the average of a sequence of nullable values.
/// The average of the sequence of values, or null if the source sequence is empty or contains only values that are null.
/// A sequence of nullable values to calculate the average of.
///
/// is null.
// Token: 0x06000289 RID: 649 RVA: 0x0000D4DC File Offset: 0x0000B6DC
public static double? Average(this IEnumerable source)
{
Check.Source(source);
double num = 0.0;
long num2 = 0L;
foreach (double? num3 in source)
{
if (num3 != null)
{
num += num3.Value;
num2 += 1L;
}
}
if (num2 == 0L)
{
return null;
}
return new double?(num / (double)num2);
}
/// Computes the average of a sequence of nullable values.
/// The average of the sequence of values, or null if the source sequence is empty or contains only values that are null.
/// A sequence of nullable values to calculate the average of.
///
/// is null.
/// The sum of the elements in the sequence is larger than .
// Token: 0x0600028A RID: 650 RVA: 0x0000D580 File Offset: 0x0000B780
public static decimal? Average(this IEnumerable source)
{
Check.Source(source);
decimal num = 0m;
long num2 = 0L;
foreach (decimal? num3 in source)
{
if (num3 != null)
{
num += num3.Value;
num2 += 1L;
}
}
if (num2 == 0L)
{
return null;
}
return new decimal?(num / num2);
}
/// Computes the average of a sequence of nullable values.
/// The average of the sequence of values, or null if the source sequence is empty or contains only values that are null.
/// A sequence of nullable values to calculate the average of.
///
/// is null.
// Token: 0x0600028B RID: 651 RVA: 0x0000D630 File Offset: 0x0000B830
public static float? Average(this IEnumerable source)
{
Check.Source(source);
float num = 0f;
long num2 = 0L;
foreach (float? num3 in source)
{
if (num3 != null)
{
num += num3.Value;
num2 += 1L;
}
}
if (num2 == 0L)
{
return null;
}
return new float?(num / (float)num2);
}
/// Computes the average of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
/// The average of the sequence of values.
/// A sequence of values to calculate the average of.
/// A transform function to apply to each element.
/// The type of the elements of .
///
/// or is null.
///
/// contains no elements.
/// The sum of the elements in the sequence is larger than .
// Token: 0x0600028C RID: 652 RVA: 0x0000D6D0 File Offset: 0x0000B8D0
public static double Average(this IEnumerable source, Func selector)
{
Check.SourceAndSelector(source, selector);
long num = 0L;
long num2 = 0L;
foreach (TSource tsource in source)
{
num += (long)selector(tsource);
num2 += 1L;
}
if (num2 == 0L)
{
throw new InvalidOperationException();
}
return (double)num / (double)num2;
}
/// Computes the average of a sequence of nullable values that are obtained by invoking a transform function on each element of the input sequence.
/// The average of the sequence of values, or null if the source sequence is empty or contains only values that are null.
/// A sequence of values to calculate the average of.
/// A transform function to apply to each element.
/// The type of the elements of .
///
/// or is null.
/// The sum of the elements in the sequence is larger than .
// Token: 0x0600028D RID: 653 RVA: 0x0000D758 File Offset: 0x0000B958
public static double? Average(this IEnumerable source, Func selector)
{
Check.SourceAndSelector(source, selector);
long num = 0L;
long num2 = 0L;
foreach (TSource tsource in source)
{
int? num3 = selector(tsource);
if (num3 != null)
{
num += (long)num3.Value;
num2 += 1L;
}
}
if (num2 == 0L)
{
return null;
}
return new double?((double)num / (double)num2);
}
/// Computes the average of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
/// The average of the sequence of values.
/// A sequence of values to calculate the average of.
/// A transform function to apply to each element.
/// The type of the elements of source.
///
/// or is null.
///
/// contains no elements.
/// The sum of the elements in the sequence is larger than .
// Token: 0x0600028E RID: 654 RVA: 0x0000D804 File Offset: 0x0000BA04
public static double Average(this IEnumerable source, Func selector)
{
Check.SourceAndSelector(source, selector);
long num = 0L;
long num2 = 0L;
foreach (TSource tsource in source)
{
checked
{
num += selector(tsource);
}
num2 += 1L;
}
if (num2 == 0L)
{
throw new InvalidOperationException();
}
return (double)num / (double)num2;
}
/// Computes the average of a sequence of nullable values that are obtained by invoking a transform function on each element of the input sequence.
/// The average of the sequence of values, or null if the source sequence is empty or contains only values that are null.
/// A sequence of values to calculate the average of.
/// A transform function to apply to each element.
/// The type of the elements of .
// Token: 0x0600028F RID: 655 RVA: 0x0000D888 File Offset: 0x0000BA88
public static double? Average(this IEnumerable source, Func selector)
{
Check.SourceAndSelector(source, selector);
long num = 0L;
long num2 = 0L;
foreach (TSource tsource in source)
{
long? num3 = selector(tsource);
if (num3 != null)
{
checked
{
num += num3.Value;
}
num2 += 1L;
}
}
if (num2 == 0L)
{
return null;
}
return new double?((double)num / (double)num2);
}
/// Computes the average of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
/// The average of the sequence of values.
/// A sequence of values to calculate the average of.
/// A transform function to apply to each element.
/// The type of the elements of .
///
/// or is null.
///
/// contains no elements.
// Token: 0x06000290 RID: 656 RVA: 0x0000D930 File Offset: 0x0000BB30
public static double Average(this IEnumerable source, Func selector)
{
Check.SourceAndSelector(source, selector);
double num = 0.0;
long num2 = 0L;
foreach (TSource tsource in source)
{
num += selector(tsource);
num2 += 1L;
}
if (num2 == 0L)
{
throw new InvalidOperationException();
}
return num / (double)num2;
}
/// Computes the average of a sequence of nullable values that are obtained by invoking a transform function on each element of the input sequence.
/// The average of the sequence of values, or null if the source sequence is empty or contains only values that are null.
/// A sequence of values to calculate the average of.
/// A transform function to apply to each element.
/// The type of the elements of .
///
/// or is null.
// Token: 0x06000291 RID: 657 RVA: 0x0000D9BC File Offset: 0x0000BBBC
public static double? Average(this IEnumerable source, Func selector)
{
Check.SourceAndSelector(source, selector);
double num = 0.0;
long num2 = 0L;
foreach (TSource tsource in source)
{
double? num3 = selector(tsource);
if (num3 != null)
{
num += num3.Value;
num2 += 1L;
}
}
if (num2 == 0L)
{
return null;
}
return new double?(num / (double)num2);
}
/// Computes the average of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
/// The average of the sequence of values.
/// A sequence of values to calculate the average of.
/// A transform function to apply to each element.
/// The type of the elements of .
///
/// or is null.
///
/// contains no elements.
// Token: 0x06000292 RID: 658 RVA: 0x0000DA6C File Offset: 0x0000BC6C
public static float Average(this IEnumerable source, Func selector)
{
Check.SourceAndSelector(source, selector);
float num = 0f;
long num2 = 0L;
foreach (TSource tsource in source)
{
num += selector(tsource);
num2 += 1L;
}
if (num2 == 0L)
{
throw new InvalidOperationException();
}
return num / (float)num2;
}
/// Computes the average of a sequence of nullable values that are obtained by invoking a transform function on each element of the input sequence.
/// The average of the sequence of values, or null if the source sequence is empty or contains only values that are null.
/// A sequence of values to calculate the average of.
/// A transform function to apply to each element.
/// The type of the elements of .
///
/// or is null.
// Token: 0x06000293 RID: 659 RVA: 0x0000DAF4 File Offset: 0x0000BCF4
public static float? Average(this IEnumerable source, Func selector)
{
Check.SourceAndSelector(source, selector);
float num = 0f;
long num2 = 0L;
foreach (TSource tsource in source)
{
float? num3 = selector(tsource);
if (num3 != null)
{
num += num3.Value;
num2 += 1L;
}
}
if (num2 == 0L)
{
return null;
}
return new float?(num / (float)num2);
}
/// Computes the average of a sequence of values that are obtained by invoking a transform function on each element of the input sequence.
/// The average of the sequence of values.
/// A sequence of values that are used to calculate an average.
/// A transform function to apply to each element.
/// The type of the elements of .
///
/// or is null.
///
/// contains no elements.
/// The sum of the elements in the sequence is larger than .
// Token: 0x06000294 RID: 660 RVA: 0x0000DBA0 File Offset: 0x0000BDA0
public static decimal Average(this IEnumerable source, Func selector)
{
Check.SourceAndSelector(source, selector);
decimal num = 0m;
long num2 = 0L;
foreach (TSource tsource in source)
{
num += selector(tsource);
num2 += 1L;
}
if (num2 == 0L)
{
throw new InvalidOperationException();
}
return num / num2;
}
/// Computes the average of a sequence of nullable values that are obtained by invoking a transform function on each element of the input sequence.
/// The average of the sequence of values, or null if the source sequence is empty or contains only values that are null.
/// A sequence of values to calculate the average of.
/// A transform function to apply to each element.
/// The type of the elements of .
///
/// or is null.
/// The sum of the elements in the sequence is larger than .
// Token: 0x06000295 RID: 661 RVA: 0x0000DC34 File Offset: 0x0000BE34
public static decimal? Average(this IEnumerable source, Func selector)
{
Check.SourceAndSelector(source, selector);
decimal num = 0m;
long num2 = 0L;
foreach (TSource tsource in source)
{
decimal? num3 = selector(tsource);
if (num3 != null)
{
num += num3.Value;
num2 += 1L;
}
}
if (num2 == 0L)
{
return null;
}
return new decimal?(num / num2);
}
/// Converts the elements of an to the specified type.
/// An that contains each element of the source sequence converted to the specified type.
/// The that contains the elements to be converted.
/// The type to convert the elements of to.
///
/// is null.
/// An element in the sequence cannot be cast to type .
// Token: 0x06000296 RID: 662 RVA: 0x0000DCEC File Offset: 0x0000BEEC
public static IEnumerable Cast(this IEnumerable source)
{
Check.Source(source);
IEnumerable enumerable = source as IEnumerable;
if (enumerable != null)
{
return enumerable;
}
return Enumerable.CreateCastIterator(source);
}
// Token: 0x06000297 RID: 663 RVA: 0x0000DD14 File Offset: 0x0000BF14
private static IEnumerable CreateCastIterator(IEnumerable source)
{
foreach (object obj in source)
{
TResult element = (TResult)((object)obj);
yield return element;
}
yield break;
}
/// Concatenates two sequences.
/// An that contains the concatenated elements of the two input sequences.
/// The first sequence to concatenate.
/// The sequence to concatenate to the first sequence.
/// The type of the elements of the input sequences.
///
/// or is null.
// Token: 0x06000298 RID: 664 RVA: 0x0000DD40 File Offset: 0x0000BF40
public static IEnumerable Concat(this IEnumerable first, IEnumerable second)
{
Check.FirstAndSecond(first, second);
return Enumerable.CreateConcatIterator(first, second);
}
// Token: 0x06000299 RID: 665 RVA: 0x0000DD50 File Offset: 0x0000BF50
private static IEnumerable CreateConcatIterator(IEnumerable first, IEnumerable second)
{
foreach (TSource element in first)
{
yield return element;
}
foreach (TSource element2 in second)
{
yield return element2;
}
yield break;
}
/// Determines whether a sequence contains a specified element by using the default equality comparer.
/// true if the source sequence contains an element that has the specified value; otherwise, false.
/// A sequence in which to locate a value.
/// The value to locate in the sequence.
/// The type of the elements of .
///
/// is null.
// Token: 0x0600029A RID: 666 RVA: 0x0000DD88 File Offset: 0x0000BF88
public static bool Contains(this IEnumerable source, TSource value)
{
ICollection collection = source as ICollection;
if (collection != null)
{
return collection.Contains(value);
}
return source.Contains(value, null);
}
/// Determines whether a sequence contains a specified element by using a specified .
/// true if the source sequence contains an element that has the specified value; otherwise, false.
/// A sequence in which to locate a value.
/// The value to locate in the sequence.
/// An equality comparer to compare values.
/// The type of the elements of .
///
/// is null.
// Token: 0x0600029B RID: 667 RVA: 0x0000DDB4 File Offset: 0x0000BFB4
public static bool Contains(this IEnumerable source, TSource value, IEqualityComparer comparer)
{
Check.Source(source);
if (comparer == null)
{
comparer = EqualityComparer.Default;
}
foreach (TSource tsource in source)
{
if (comparer.Equals(tsource, value))
{
return true;
}
}
return false;
}
/// Returns the number of elements in a sequence.
/// The number of elements in the input sequence.
/// A sequence that contains elements to be counted.
/// The type of the elements of .
///
/// is null.
/// The number of elements in is larger than .
// Token: 0x0600029C RID: 668 RVA: 0x0000DE38 File Offset: 0x0000C038
public static int Count(this IEnumerable source)
{
Check.Source(source);
ICollection collection = source as ICollection;
if (collection != null)
{
return collection.Count;
}
int num = 0;
using (IEnumerator enumerator = source.GetEnumerator())
{
while (enumerator.MoveNext())
{
num++;
}
}
return num;
}
/// Returns a number that represents how many elements in the specified sequence satisfy a condition.
/// A number that represents how many elements in the sequence satisfy the condition in the predicate function.
/// A sequence that contains elements to be tested and counted.
/// A function to test each element for a condition.
/// The type of the elements of .
///
/// or is null.
/// The number of elements in is larger than .
// Token: 0x0600029D RID: 669 RVA: 0x0000DEAC File Offset: 0x0000C0AC
public static int Count(this IEnumerable source, Func selector)
{
Check.SourceAndSelector(source, selector);
int num = 0;
foreach (TSource tsource in source)
{
if (selector(tsource))
{
num++;
}
}
return num;
}
/// Returns the elements of the specified sequence or the type parameter's default value in a singleton collection if the sequence is empty.
/// An object that contains the default value for the type if is empty; otherwise, .
/// The sequence to return a default value for if it is empty.
/// The type of the elements of .
///
/// is null.
// Token: 0x0600029E RID: 670 RVA: 0x0000DF20 File Offset: 0x0000C120
public static IEnumerable DefaultIfEmpty(this IEnumerable source)
{
return source.DefaultIfEmpty(default(TSource));
}
/// Returns the elements of the specified sequence or the specified value in a singleton collection if the sequence is empty.
/// An that contains if is empty; otherwise, .
/// The sequence to return the specified value for if it is empty.
/// The value to return if the sequence is empty.
/// The type of the elements of .
// Token: 0x0600029F RID: 671 RVA: 0x0000DF3C File Offset: 0x0000C13C
public static IEnumerable DefaultIfEmpty(this IEnumerable source, TSource defaultValue)
{
Check.Source(source);
return Enumerable.CreateDefaultIfEmptyIterator(source, defaultValue);
}
// Token: 0x060002A0 RID: 672 RVA: 0x0000DF4C File Offset: 0x0000C14C
private static IEnumerable CreateDefaultIfEmptyIterator(IEnumerable source, TSource defaultValue)
{
bool empty = true;
foreach (TSource item in source)
{
empty = false;
yield return item;
}
if (empty)
{
yield return defaultValue;
}
yield break;
}
/// Returns distinct elements from a sequence by using the default equality comparer to compare values.
/// An that contains distinct elements from the source sequence.
/// The sequence to remove duplicate elements from.
/// The type of the elements of .
///
/// is null.
// Token: 0x060002A1 RID: 673 RVA: 0x0000DF84 File Offset: 0x0000C184
public static IEnumerable Distinct(this IEnumerable source)
{
return source.Distinct(null);
}
/// Returns distinct elements from a sequence by using a specified to compare values.
/// An that contains distinct elements from the source sequence.
/// The sequence to remove duplicate elements from.
/// An to compare values.
/// The type of the elements of .
///
/// is null.
// Token: 0x060002A2 RID: 674 RVA: 0x0000DF90 File Offset: 0x0000C190
public static IEnumerable Distinct(this IEnumerable source, IEqualityComparer comparer)
{
Check.Source(source);
if (comparer == null)
{
comparer = EqualityComparer.Default;
}
return Enumerable.CreateDistinctIterator(source, comparer);
}
// Token: 0x060002A3 RID: 675 RVA: 0x0000DFAC File Offset: 0x0000C1AC
private static IEnumerable CreateDistinctIterator(IEnumerable source, IEqualityComparer comparer)
{
HashSet items = new HashSet(comparer);
foreach (TSource element in source)
{
if (!items.Contains(element))
{
items.Add(element);
yield return element;
}
}
yield break;
}
// Token: 0x060002A4 RID: 676 RVA: 0x0000DFE4 File Offset: 0x0000C1E4
private static TSource ElementAt(this IEnumerable source, int index, Enumerable.Fallback fallback)
{
long num = 0L;
foreach (TSource tsource in source)
{
long num2 = (long)index;
long num3 = num;
num = num3 + 1L;
if (num2 == num3)
{
return tsource;
}
}
if (fallback == Enumerable.Fallback.Throw)
{
throw new ArgumentOutOfRangeException();
}
return default(TSource);
}
/// Returns the element at a specified index in a sequence.
/// The element at the specified position in the source sequence.
/// An to return an element from.
/// The zero-based index of the element to retrieve.
/// The type of the elements of .
///
/// is null.
///
/// is less than 0 or greater than or equal to the number of elements in .
// Token: 0x060002A5 RID: 677 RVA: 0x0000E06C File Offset: 0x0000C26C
public static TSource ElementAt(this IEnumerable source, int index)
{
Check.Source(source);
if (index < 0)
{
throw new ArgumentOutOfRangeException();
}
IList list = source as IList;
if (list != null)
{
return list[index];
}
return source.ElementAt(index, Enumerable.Fallback.Throw);
}
/// Returns the element at a specified index in a sequence or a default value if the index is out of range.
/// default() if the index is outside the bounds of the source sequence; otherwise, the element at the specified position in the source sequence.
/// An to return an element from.
/// The zero-based index of the element to retrieve.
/// The type of the elements of .
///
/// is null.
// Token: 0x060002A6 RID: 678 RVA: 0x0000E0AC File Offset: 0x0000C2AC
public static TSource ElementAtOrDefault(this IEnumerable source, int index)
{
Check.Source(source);
if (index < 0)
{
return default(TSource);
}
IList list = source as IList;
if (list != null)
{
return (index >= list.Count) ? default(TSource) : list[index];
}
return source.ElementAt(index, Enumerable.Fallback.Default);
}
/// Returns an empty that has the specified type argument.
/// An empty whose type argument is .
/// The type to assign to the type parameter of the returned generic .
// Token: 0x060002A7 RID: 679 RVA: 0x0000E108 File Offset: 0x0000C308
public static IEnumerable Empty()
{
return new TResult[0];
}
/// Produces the set difference of two sequences by using the default equality comparer to compare values.
/// A sequence that contains the set difference of the elements of two sequences.
/// An whose elements that are not also in will be returned.
/// An whose elements that also occur in the first sequence will cause those elements to be removed from the returned sequence.
/// The type of the elements of the input sequences.
///
/// or is null.
// Token: 0x060002A8 RID: 680 RVA: 0x0000E110 File Offset: 0x0000C310
public static IEnumerable Except(this IEnumerable first, IEnumerable second)
{
return first.Except(second, null);
}
/// Produces the set difference of two sequences by using the specified to compare values.
/// A sequence that contains the set difference of the elements of two sequences.
/// An whose elements that are not also in will be returned.
/// An whose elements that also occur in the first sequence will cause those elements to be removed from the returned sequence.
/// An to compare values.
/// The type of the elements of the input sequences.
///
/// or is null.
// Token: 0x060002A9 RID: 681 RVA: 0x0000E11C File Offset: 0x0000C31C
public static IEnumerable Except(this IEnumerable first, IEnumerable second, IEqualityComparer comparer)
{
Check.FirstAndSecond(first, second);
if (comparer == null)
{
comparer = EqualityComparer.Default;
}
return Enumerable.CreateExceptIterator(first, second, comparer);
}
// Token: 0x060002AA RID: 682 RVA: 0x0000E13C File Offset: 0x0000C33C
private static IEnumerable CreateExceptIterator(IEnumerable first, IEnumerable second, IEqualityComparer comparer)
{
HashSet items = new HashSet(second, comparer);
foreach (TSource element in first)
{
if (!items.Contains(element, comparer))
{
yield return element;
}
}
yield break;
}
// Token: 0x060002AB RID: 683 RVA: 0x0000E184 File Offset: 0x0000C384
private static TSource First(this IEnumerable source, Func predicate, Enumerable.Fallback fallback)
{
foreach (TSource tsource in source)
{
if (predicate(tsource))
{
return tsource;
}
}
if (fallback == Enumerable.Fallback.Throw)
{
throw new InvalidOperationException();
}
return default(TSource);
}
/// Returns the first element of a sequence.
/// The first element in the specified sequence.
/// The to return the first element of.
/// The type of the elements of .
///
/// is null.
/// The source sequence is empty.
// Token: 0x060002AC RID: 684 RVA: 0x0000E208 File Offset: 0x0000C408
public static TSource First(this IEnumerable source)
{
Check.Source(source);
IList list = source as IList;
if (list == null)
{
using (IEnumerator enumerator = source.GetEnumerator())
{
if (enumerator.MoveNext())
{
return enumerator.Current;
}
}
throw new InvalidOperationException();
}
if (list.Count != 0)
{
return list[0];
}
throw new InvalidOperationException();
}
/// Returns the first element in a sequence that satisfies a specified condition.
/// The first element in the sequence that passes the test in the specified predicate function.
/// An to return an element from.
/// A function to test each element for a condition.
/// The type of the elements of .
///
/// or is null.
/// No element satisfies the condition in .-or-The source sequence is empty.
// Token: 0x060002AD RID: 685 RVA: 0x0000E294 File Offset: 0x0000C494
public static TSource First(this IEnumerable source, Func predicate)
{
Check.SourceAndPredicate(source, predicate);
return source.First(predicate, Enumerable.Fallback.Throw);
}
/// Returns the first element of a sequence, or a default value if the sequence contains no elements.
/// default() if is empty; otherwise, the first element in .
/// The to return the first element of.
/// The type of the elements of .
///
/// is null.
// Token: 0x060002AE RID: 686 RVA: 0x0000E2A8 File Offset: 0x0000C4A8
public static TSource FirstOrDefault(this IEnumerable source)
{
Check.Source(source);
using (IEnumerator enumerator = source.GetEnumerator())
{
if (enumerator.MoveNext())
{
return enumerator.Current;
}
}
return default(TSource);
}
/// Returns the first element of the sequence that satisfies a condition or a default value if no such element is found.
/// default() if is empty or if no element passes the test specified by ; otherwise, the first element in that passes the test specified by .
/// An to return an element from.
/// A function to test each element for a condition.
/// The type of the elements of .
///
/// or is null.
// Token: 0x060002AF RID: 687 RVA: 0x0000E318 File Offset: 0x0000C518
public static TSource FirstOrDefault(this IEnumerable source, Func predicate)
{
Check.SourceAndPredicate(source, predicate);
return source.First(predicate, Enumerable.Fallback.Default);
}
// Token: 0x060002B0 RID: 688 RVA: 0x0000E32C File Offset: 0x0000C52C
private static List ContainsGroup(Dictionary> items, K key, IEqualityComparer comparer)
{
IEqualityComparer equalityComparer = comparer ?? EqualityComparer.Default;
foreach (KeyValuePair> keyValuePair in items)
{
if (equalityComparer.Equals(keyValuePair.Key, key))
{
return keyValuePair.Value;
}
}
return null;
}
/// Groups the elements of a sequence according to a specified key selector function.
/// An IEnumerable<IGrouping<TKey, TSource>> in C# or IEnumerable(Of IGrouping(Of TKey, TSource)) in Visual Basic where each object contains a sequence of objects and a key.
/// An whose elements to group.
/// A function to extract the key for each element.
/// The type of the elements of .
/// The type of the key returned by .
///
/// or is null.
// Token: 0x060002B1 RID: 689 RVA: 0x0000E3B8 File Offset: 0x0000C5B8
public static IEnumerable> GroupBy(this IEnumerable source, Func keySelector)
{
return source.GroupBy(keySelector, null);
}
/// Groups the elements of a sequence according to a specified key selector function and compares the keys by using a specified comparer.
/// An IEnumerable<IGrouping<TKey, TSource>> in C# or IEnumerable(Of IGrouping(Of TKey, TSource)) in Visual Basic where each object contains a collection of objects and a key.
/// An whose elements to group.
/// A function to extract the key for each element.
/// An to compare keys.
/// The type of the elements of .
/// The type of the key returned by .
///
/// or is null.
// Token: 0x060002B2 RID: 690 RVA: 0x0000E3C4 File Offset: 0x0000C5C4
public static IEnumerable> GroupBy(this IEnumerable source, Func keySelector, IEqualityComparer comparer)
{
Check.SourceAndKeySelector(source, keySelector);
return source.CreateGroupByIterator(keySelector, comparer);
}
// Token: 0x060002B3 RID: 691 RVA: 0x0000E3D8 File Offset: 0x0000C5D8
private static IEnumerable> CreateGroupByIterator(this IEnumerable source, Func keySelector, IEqualityComparer comparer)
{
Dictionary> groups = new Dictionary>();
List nullList = new List();
int counter = 0;
int nullCounter = -1;
foreach (TSource element in source)
{
TKey key = keySelector(element);
if (key == null)
{
nullList.Add(element);
if (nullCounter == -1)
{
nullCounter = counter;
counter++;
}
}
else
{
List group = Enumerable.ContainsGroup(groups, key, comparer);
if (group == null)
{
group = new List();
groups.Add(key, group);
counter++;
}
group.Add(element);
}
}
counter = 0;
foreach (KeyValuePair> group2 in groups)
{
if (counter == nullCounter)
{
yield return new Grouping(default(TKey), nullList);
counter++;
}
yield return new Grouping(group2.Key, group2.Value);
counter++;
}
if (counter == nullCounter)
{
yield return new Grouping(default(TKey), nullList);
counter++;
}
yield break;
}
/// Groups the elements of a sequence according to a specified key selector function and projects the elements for each group by using a specified function.
/// An IEnumerable<IGrouping<TKey, TElement>> in C# or IEnumerable(Of IGrouping(Of TKey, TElement)) in Visual Basic where each object contains a collection of objects of type and a key.
/// An whose elements to group.
/// A function to extract the key for each element.
/// A function to map each source element to an element in the .
/// The type of the elements of .
/// The type of the key returned by .
/// The type of the elements in the .
///
/// or or is null.
// Token: 0x060002B4 RID: 692 RVA: 0x0000E420 File Offset: 0x0000C620
public static IEnumerable> GroupBy(this IEnumerable source, Func keySelector, Func elementSelector)
{
return source.GroupBy(keySelector, elementSelector, null);
}
/// Groups the elements of a sequence according to a key selector function. The keys are compared by using a comparer and each group's elements are projected by using a specified function.
/// An IEnumerable<IGrouping<TKey, TElement>> in C# or IEnumerable(Of IGrouping(Of TKey, TElement)) in Visual Basic where each object contains a collection of objects of type and a key.
/// An whose elements to group.
/// A function to extract the key for each element.
/// A function to map each source element to an element in an .
/// An to compare keys.
/// The type of the elements of .
/// The type of the key returned by .
/// The type of the elements in the .
///
/// or or is null.
// Token: 0x060002B5 RID: 693 RVA: 0x0000E42C File Offset: 0x0000C62C
public static IEnumerable> GroupBy(this IEnumerable source, Func keySelector, Func elementSelector, IEqualityComparer comparer)
{
Check.SourceAndKeyElementSelectors(source, keySelector, elementSelector);
return source.CreateGroupByIterator(keySelector, elementSelector, comparer);
}
// Token: 0x060002B6 RID: 694 RVA: 0x0000E440 File Offset: 0x0000C640
private static IEnumerable> CreateGroupByIterator(this IEnumerable source, Func keySelector, Func elementSelector, IEqualityComparer comparer)
{
Dictionary> groups = new Dictionary>();
List nullList = new List();
int counter = 0;
int nullCounter = -1;
foreach (TSource item in source)
{
TKey key = keySelector(item);
TElement element = elementSelector(item);
if (key == null)
{
nullList.Add(element);
if (nullCounter == -1)
{
nullCounter = counter;
counter++;
}
}
else
{
List group = Enumerable.ContainsGroup(groups, key, comparer);
if (group == null)
{
group = new List();
groups.Add(key, group);
counter++;
}
group.Add(element);
}
}
counter = 0;
foreach (KeyValuePair> group2 in groups)
{
if (counter == nullCounter)
{
yield return new Grouping(default(TKey), nullList);
counter++;
}
yield return new Grouping(group2.Key, group2.Value);
counter++;
}
if (counter == nullCounter)
{
yield return new Grouping(default(TKey), nullList);
counter++;
}
yield break;
}
/// Groups the elements of a sequence according to a specified key selector function and creates a result value from each group and its key. The elements of each group are projected by using a specified function.
/// A collection of elements of type where each element represents a projection over a group and its key.
/// An whose elements to group.
/// A function to extract the key for each element.
/// A function to map each source element to an element in an .
/// A function to create a result value from each group.
/// The type of the elements of .
/// The type of the key returned by .
/// The type of the elements in each .
/// The type of the result value returned by .
// Token: 0x060002B7 RID: 695 RVA: 0x0000E494 File Offset: 0x0000C694
public static IEnumerable GroupBy(this IEnumerable source, Func keySelector, Func elementSelector, Func, TResult> resultSelector)
{
return source.GroupBy(keySelector, elementSelector, resultSelector, null);
}
/// Groups the elements of a sequence according to a specified key selector function and creates a result value from each group and its key. Key values are compared by using a specified comparer, and the elements of each group are projected by using a specified function.
/// A collection of elements of type where each element represents a projection over a group and its key.
/// An whose elements to group.
/// A function to extract the key for each element.
/// A function to map each source element to an element in an .
/// A function to create a result value from each group.
/// An to compare keys with.
/// The type of the elements of .
/// The type of the key returned by .
/// The type of the elements in each .
/// The type of the result value returned by .
// Token: 0x060002B8 RID: 696 RVA: 0x0000E4A0 File Offset: 0x0000C6A0
public static IEnumerable GroupBy(this IEnumerable source, Func keySelector, Func elementSelector, Func, TResult> resultSelector, IEqualityComparer comparer)
{
Check.GroupBySelectors(source, keySelector, elementSelector, resultSelector);
return source.CreateGroupByIterator(keySelector, elementSelector, resultSelector, comparer);
}
// Token: 0x060002B9 RID: 697 RVA: 0x0000E4B8 File Offset: 0x0000C6B8
private static IEnumerable CreateGroupByIterator(this IEnumerable source, Func keySelector, Func elementSelector, Func, TResult> resultSelector, IEqualityComparer comparer)
{
IEnumerable> groups = source.GroupBy(keySelector, elementSelector, comparer);
foreach (IGrouping group in groups)
{
yield return resultSelector(group.Key, group);
}
yield break;
}
/// Groups the elements of a sequence according to a specified key selector function and creates a result value from each group and its key.
/// A collection of elements of type where each element represents a projection over a group and its key.
/// An whose elements to group.
/// A function to extract the key for each element.
/// A function to create a result value from each group.
/// The type of the elements of .
/// The type of the key returned by .
/// The type of the result value returned by .
// Token: 0x060002BA RID: 698 RVA: 0x0000E51C File Offset: 0x0000C71C
public static IEnumerable GroupBy(this IEnumerable source, Func