Is there any way to detect this code snippet?
DateTime dt = DateTime.Now;
if (dt == null) {
MessageBox.Show("Imposible with datetime!!!");
}
In our project we have detected that in Release compilation, the whole if gets removed because a comparison between a DateTime and null will be always false. I assume the optimizer translates it as:
if (false) {
...
}
Is there any way to make the analyzer detect this code in any way? An error in compile time would be fine too, even if we have to create an FXCop rule, but we don't know how to track this case.
DateTime dt = null; // This code raises a compile time error, but the comparison with null is fine?