Last active
June 7, 2017 14:34
-
-
Save vdovinanton/b75ef947a78b028a114d3c8bf63d3ce7 to your computer and use it in GitHub Desktop.
Gets all child items
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
private static IEnumerable<CollectionMemberCached> Descendants(CollectionMemberCached root) | |
{ | |
var nodes = new Stack<CollectionMemberCached>(new[] { root }); | |
while (nodes.Any()) | |
{ | |
CollectionMemberCached node = nodes.Pop(); | |
yield return node; | |
foreach (var n in node.Members) | |
nodes.Push(n); | |
} | |
} | |
//usage | |
var collecationMembers = | |
allCollections.SelectMany(q => q.Members) | |
.SelectMany(Descendants) | |
.Where(q => q.Type == CollectionMemberType.User && !q.Excluded) | |
.ToList(); | |
/* | |
public class CollectionMemberCached | |
{ | |
public CollectionMemberCached() | |
{ | |
Members = new List<CollectionMemberCached>(); | |
} | |
public Guid ObjectGuid { get; set; } | |
public string Name { get; set; } | |
public string Email { get; set; } | |
public bool Excluded { get; set; } | |
public CollectionMemberType Type { get; set; } | |
public List<CollectionMemberCached> Members { get; set; } | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment