-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
138 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/Our.Umbraco.Look/Extensions/IEnumerableExtensions/BothNullOrElementCollectionsEqual.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Our.Umbraco.Look.Extensions | ||
{ | ||
internal static partial class IEnumerableExtensions | ||
{ | ||
/// <summary> | ||
/// Returns true if both are null, or both collections of collections have the same elements in each regardless of sequence | ||
/// </summary> | ||
/// <typeparam name="TSource"></typeparam> | ||
/// <param name="first"></param> | ||
/// <param name="second"></param> | ||
/// <returns></returns> | ||
internal static bool BothNullOrElementCollectionsEqual<TSource>(this IEnumerable<IEnumerable<TSource>> first, IEnumerable<IEnumerable<TSource>> second) | ||
{ | ||
if (first == null && second == null) return true; | ||
|
||
if (first == null || second == null) return false; | ||
|
||
if (first.Count() != second.Count()) return false; | ||
|
||
var areEqual = true; | ||
|
||
if (first.Any()) | ||
{ | ||
var firstStack = new Stack<IEnumerable<TSource>>(first); | ||
var secondList = new List<IEnumerable<TSource>>(second); | ||
|
||
do | ||
{ | ||
var firstCollection = firstStack.Pop(); | ||
|
||
var matchingCollectionFound = false; | ||
|
||
var secondStack = new Stack<IEnumerable<TSource>>(secondList); | ||
|
||
do | ||
{ | ||
var secondCollection = secondStack.Pop(); | ||
|
||
matchingCollectionFound = firstCollection.BothNullOrElementsEqual(secondCollection); | ||
|
||
if (matchingCollectionFound) | ||
{ | ||
secondList.Remove(secondCollection); | ||
} | ||
} | ||
while (!matchingCollectionFound && secondStack.Any()); | ||
|
||
areEqual = matchingCollectionFound; | ||
} | ||
while (areEqual && firstStack.Any()); | ||
} | ||
|
||
return areEqual; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters