throw better error when empty list, underlying cause to be fixed

This commit is contained in:
CWX
2025-04-07 14:31:40 +01:00
parent 213e61022e
commit a2575f2a6a
@@ -115,6 +115,11 @@ public class RandomUtil(ISptLogger<RandomUtil> _logger, ICloner _cloner)
// We can call `count` directly if it's a list
if (collection is IList<T> list)
{
if (!list.Any())
{
throw new InvalidOperationException("Sequence contains no elements.");
}
return list[GetInt(0, list.Count - 1)];
}