1
0
mirror of synced 2024-09-24 11:38:22 +02:00
Switch-Toolbox/Switch_Toolbox_Library/Collections/SortExtensions.cs

27 lines
716 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Toolbox.Library
{
public static class SortExtensions
{
/// <summary>
/// Sort one collection based on keys defined in another
/// </summary>
/// <returns>Items sorted</returns>
public static IEnumerable<TResult> SortBy<TResult, TKey>(
this IEnumerable<TResult> itemsToSort,
IEnumerable<TKey> sortKeys,
Func<TResult, TKey> matchFunc)
{
return sortKeys.Join(itemsToSort,
key => key,
matchFunc,
(key, iitem) => iitem);
}
}
}