I'm trying to find a way to check and see if the value of a given object is equal to its default value. I've looked around and come up with this:
public static bool IsNullOrDefault<T>(T argument)
{
if (argument is ValueType || argument != null)
{
return object.Equals(argument, default(T));
}
return true;
}
The problem I'm having is that I want to call it like this:
object o = 0;
bool b = Utility.Utility.IsNullOrDefault(o);
Yes o is an object, but I want to make it figure out the base type and check the default value of that. The base type, in this case, is an integer and I want to know in this case if the value is equal to default(int), not default(object).
I'm starting to think this might not be possible.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…