//The MIT License (MIT)
//http://arolibraries.codeplex.com/license
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
namespace AroLibraries.ExtensionMethods.Enumerable
{
public static class IEnumerableExt
{
public static IOrderedEnumerable<TSource> Ext_OrderBy<TSource, TKey>(this IEnumerable<TSource> enumerable, Func<TSource, TKey> keySelector, bool descending)
{
if (enumerable == null) { return null; }
if (descending)
{
return enumerable.OrderByDescending(keySelector);
}
return enumerable.OrderBy(keySelector);
}
public static IOrderedEnumerable<TSource> Ext_OrderBy<TSource>(this IEnumerable<TSource> enumerable, Func<TSource, IComparable> keySelector1, Func<TSource, IComparable> keySelector2, params Func<TSource, IComparable>[] keySelectors)
{
if (enumerable == null)
{
return null;
}
IEnumerable<TSource> current = enumerable;
if (keySelectors != null)
{
for (int i = keySelectors.Length - 1; i >= 0; i--)
{
current = current.OrderBy(keySelectors[i]);
}
} current = current.OrderBy(keySelector2);
return current.OrderBy(keySelector1);
}
public static IOrderedEnumerable<TSource> Ext_OrderBy<TSource>(this IEnumerable<TSource> enumerable, bool descending, Func<TSource, IComparable> keySelector, params Func<TSource, IComparable>[] keySelectors)
{
if (enumerable == null)
{
return null;
}
IEnumerable<TSource> current = enumerable; if (keySelectors != null)
{
for (int i =
keySelectors.Length - 1; i >= 0; i--)
{
current = current.Ext_OrderBy(keySelectors[i], descending);
}
} return current.Ext_OrderBy(keySelector, descending);
}
}
}
|