Well, you could have List<Tuple<Func<Motorist, bool>, RiskFactor> :
var filters = new List<Tuple<Func<Motorist, bool>, RiskFactor> { Tuple.Create(m => m.PointsOnLicense > 3, RiskFactor.HIGH_RISK), Tuple.Create(m => m.Age < 25, RiskFactor.HIGH_RISK), Tuple.Create(m => m.PointsOnLicense > 0, RiskFactor.MODERATE_RISK), };
Then:
var risk = filters.Where(filter => filter.Item1(motorist)) .Select(filter => filter.Item2) .DefaultIfEmpty(RiskFactor.LOW_RISK) .First();
This at least makes it easy to add extra checks, and it just knocks them down in order. This is a bit strange - I could create my own Filter type, not Tuple , for example, but it should work ...
source share