I've got an object that has a type property. When the type is set to Int64, and I try and pull the type info later, I get System.Nullable.
Here's the type Info
{Name = "Nullable`1" FullName = "System.Nullable`1[[System.Int64, mscorlib, Version=2.0.0.0]]"}
How do I get to the System.Int64 type of this?
It sounds like you have a given type for which you want either that type or its underlying type if it is Nullable<T>
. The best way to do this would be something like this:
Nullable.GetUnderlyingType(yourObject.Type) ?? yourObject.Type;
Since Nullabe.GetUnderlyingType
returns null
if the given Type
is not Nullable<T>
you can use the null coalescing operator (??) to default the value to the original type.
Type t = Nullable.GetUnderlyingType(nullableType);
See MSDN.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With