An extension method expects an open generic IEnumerable.
Should I check inside the method wether the list is null.
I have the opinion that a list must never be null but have count == 0.
How do you handle such a case?
UPDATE:
I forgot to mention that the method is a recursive method where the list is recursively called/passed of course.
Yes you should check that. It’s also fairly common pattern to throw in such case, especially in LINQ:
Handling empty list is much easier than handling list instance that is null. Think about it in this way; list with no items is simply empty collection – fairly common case. List that is null… represents what? Exceptional situation, and should be handled as such.
Update:
I looked around on what Microsoft has to say about my speculations that throwing ANE is common pattern (as opposed to letting CLR throw NRE – which at points might be too vague) and it seems to be correct. We can find at ANE documentation page that:
And later, in framework design guidelines’ Exception Throwing section:
In your case, since you mentioned your method must never accept null list argument, it is simple execution failure situation.