-
Notifications
You must be signed in to change notification settings - Fork 0
Enumerable Extensions
StrutTower edited this page Nov 18, 2023
·
1 revision
IEnumerable extension methods
Functions basically the same as Linq .Any() but returns null instead of throwing an error if the enumerable object is null
List<Person> people = GetAllPeople();
bool hasAny = people.SafeAny();
bool hasAnyMatching = people.SafeAny(x => x.LastName == "Smith");
List<Person> nullList = null;
bool nullAny = nullList.SafeAny();
// returns false instead of throwing an errorChecks if the generic type of the enumerable object matches the supplied type
List<Person> people = new List<Person>();
bool isPerson = people.IsOfType(typeof(Person));
// returns true
bool isOrder = people.IsOfType(typeof(Order));
// returns falseSplits a enumerable into smaller list based on the batch size supplied.
List<Person> people = GetAllPeople();
IEnumerable<IEnumerable<Person>> batches = people.Batch(50);