I have to loop through a list of string
s and validate that all are parsable to int
and not less than 1. Also, if a string is not parsable but is null or whitespace, then it is OK and my validator should not fail.
Here's the code I have come up with which works fine but leads to method complexity:
public static bool ArePerPersonBILimitsInvalid(IEnumerable<string> bilimits)
{
return bilimits.Any(c =>
{
int d;
if (!int.TryParse(c, out d))
{
if (string.IsNullOrWhiteSpace(c))
{
return false;
}
return true;
}
if (d < 1)
{
return true;
}
return false;
});
}