1
0
mirror of synced 2024-11-13 18:50:50 +01:00
Switch-Toolbox/Switch_Toolbox_Library/Collections/SortExtensions.cs

27 lines
723 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Switch_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);
}
}
}