This is not exactly what you need here, but I use the Extension method to implement this kind of chain method, when the condition can be resolved to Or or And's list.
Sort of
if (true.IfOr(condition1 == a, condition2 == b) { something(); }
The extension method is then quite simple:
public static bool IfOr(this bool result, params bool[] tests) { foreach (bool test in tests) if (!test) return !result; return result; }
Another way that may work, although it may not be very optimal, is to use the Predicate delegate in .net and define a list of methods that execute your individual units of logic. Then you can replace your nested tertiary operators with lambda. I have no sample code for this, though, sorry.
Finally, sometimes there is nothing better than the good old switch statement. I believe that .Net has a tendency to compile them as jump tables, so if you test the most divisible first, then you can really get some pretty efficient and readable code. And it is supported, rather than hiding logic or implementation with tricks.
source share