I want to be able to check whether a value is the default for its value type. Ideally, I'd like to say:
DoSomething<TValue>(TValue value) {
if (value == default(TValue)) {
...
}
}
However, the compiler complains that it can't do a ==
comparison on TValue and TValue. This is the best workaround that I've come up with so far:
DoSomething<TValue>(TValue value) {
if (value == null || value.Equals(default(TValue))) {
...
}
}
Is there a more elegant/correct way to go about this?