Browse Source

Added comparer to AbpListExtensions.SortByDependencies method

pull/5418/head
İsmail ÇAĞDAŞ 6 years ago
parent
commit
9ba33adeab
  1. 8
      framework/src/Volo.Abp.Core/System/Collections/Generic/AbpListExtensions.cs

8
framework/src/Volo.Abp.Core/System/Collections/Generic/AbpListExtensions.cs

@ -188,18 +188,22 @@ namespace System.Collections.Generic
/// <typeparam name="T">The type of the members of values.</typeparam>
/// <param name="source">A list of objects to sort</param>
/// <param name="getDependencies">Function to resolve the dependencies</param>
/// <param name="comparer">Equality comparer for dependencies </param>
/// <returns>
/// Returns a new list ordered by dependencies.
/// If A depends on B, then B will come before than A in the resulting list.
/// </returns>
public static List<T> SortByDependencies<T>(this IEnumerable<T> source, Func<T, IEnumerable<T>> getDependencies)
public static List<T> SortByDependencies<T>(
this IEnumerable<T> source,
Func<T, IEnumerable<T>> getDependencies,
IEqualityComparer<T> comparer = null)
{
/* See: http://www.codeproject.com/Articles/869059/Topological-sorting-in-Csharp
* http://en.wikipedia.org/wiki/Topological_sorting
*/
var sorted = new List<T>();
var visited = new Dictionary<T, bool>();
var visited = new Dictionary<T, bool>(comparer);
foreach (var item in source)
{

Loading…
Cancel
Save