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> /// <typeparam name="T">The type of the members of values.</typeparam>
/// <param name="source">A list of objects to sort</param> /// <param name="source">A list of objects to sort</param>
/// <param name="getDependencies">Function to resolve the dependencies</param> /// <param name="getDependencies">Function to resolve the dependencies</param>
/// <param name="comparer">Equality comparer for dependencies </param>
/// <returns> /// <returns>
/// Returns a new list ordered by dependencies. /// Returns a new list ordered by dependencies.
/// If A depends on B, then B will come before than A in the resulting list. /// If A depends on B, then B will come before than A in the resulting list.
/// </returns> /// </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 /* See: http://www.codeproject.com/Articles/869059/Topological-sorting-in-Csharp
* http://en.wikipedia.org/wiki/Topological_sorting * http://en.wikipedia.org/wiki/Topological_sorting
*/ */
var sorted = new List<T>(); var sorted = new List<T>();
var visited = new Dictionary<T, bool>(); var visited = new Dictionary<T, bool>(comparer);
foreach (var item in source) foreach (var item in source)
{ {

Loading…
Cancel
Save