I’m using the SafeWhere, but today I got a surprise. It doesn’t seem to do what I’d expect (implement a null check).
Here’s the link:
Couldn’t find it in the documentation. Is it supposed to be used like this:
mylist.SafeWhere(…)
because it fails if mylist == null.
Tried this:
mylist?.SafeWhere(…)
but no luck. Also:
mylist.Safe().Where/Find/etc.
but Safe() converts the List to IEnumerable, which doesn’t have the Find/Where LINQ? extension methods.
Made my own extension method in the end:
public static List<T> SafeX<T>(this List<T> list)
{
if (list != null) return list;
else return new List<T>();
}