- I was not aware of the GetValueOrDefault method on Nullable
. Never used it.
- Boxing/Unboxing of Nullables: 4.2.2 pp 118, 119: I had no idea that this might be an issue. But that boxing an instance of Nullable
results in either a null reference or a boxed value of the underlying type does make perfect sense.
- The class Nullable. Never used it as well. But I should have used the GetUnderlyingType method. I firmly believe that I have implemented exactly that feature two or three times in the last couple of years in various project using reflection.
- No supprise about the null coalescing operator. But I notice that it is one of the lesser known features of C#. My estimation is that 2 out of 3 devs do not know it.
- Using Nullable
for trying an operation: That idea is brilliant. Why didn't I thing of it? I used it right away.
- Combining Comparers by using Nullable
as the return type and than applying the null coalescing operator is a very cool thing especially regarding the readability/maintainability of the code.
My first idea was to have each comparer have a reference to a NextComparer to which it would delegate if it's own result would be 0 (zero). That would allow us to chain together comparer in any sequence we like at runtime. It would be something like a Chain of Responsibility.
What I do not like about it is the fact that now the Comparer have to compare and have to handle the chaining as well. So I think having Decorator for the comparer that will take care of the chainging, the delegating to the next element of the chain and will decide how to handle the end of the chain would be much better.