Reflection GetValue of bool? is bool

After several hours looking for a bug, I finally found it.

This is the code that housed the “bug”.

PropertyInfo info = obj.GetType().GetProperty("SomeProperty");
object value = info.GetValue(obj, null);
if (value.GetType() == typeof(bool?))
{
//Some code
}
else if (value.GetType() == typeof(int?))
{
//Some other code
}

The property “SomeProperty” is a nullable type (either string, int? or bool?).
The weird thing is that it works for int? but it doesn’t for bool?

For some reason when the nullable bool contains a value (so it’s not null), the type of the value object is no longer bool? but a plain bool.
It’s easily fixed:

...
if (value.GetType() == typeof(bool?) || value.GetType() == typeof(bool))
{
//Some code
}
...