Soenneker.Extensions.Enumerable
A collection of helpful enumerable extension methods
dotnet add package Soenneker.Extensions.Enumerable
IEnumerable
should have IsNullOrEmpty()
too
var populatedList = new List < string > { " foo" , " bar" , " foo" } ;
populatedList. IsNullOrEmpty ( ) // false
populatedList. Populated ( ) // true
populatedList. None ( ) // false
One call checking for null and contains any elements
List < string > ? nullList = null ;
nullList. IsNullOrEmpty ( ) // true
nullList. Populated ( ) // false
var containsDuplicates = populatedList. ContainsDuplicates ( ) ; // true
var deduped = populatedList. RemoveDuplicates ( ) ; // {"foo", "bar"}
public class Node
{
public string Name { get ; set ; }
public List < Node > Children { get ; set ; }
}
void Example ( )
{
var node = new Node( ) { Name = " Node1" } ;
node. Children = new List( )
{
new Node( )
{
Name = " Node2"
}
}
List< Node > ? children = node. Children. ToFlattenedFromRecursive ( c => c. Children ) ;
// Results in flattened List:
// { Node1, Node2 }
}