Once again one of those: \"Is there an easier built-in way of doing things instead of my helper method?\"
So it\'s easy to get the underlying type from a nullable type,
There isn't anything built in that I know of, as the int?
, etc. is just syntactic sugar for Nullable
; and isn't given special treatment beyond that. It's especially unlikely given you're attempting to obtain this from the type information of a given type. Typically that always necessitates some 'roll your own' code as a given. You would have to use Reflection to create a new Nullable
type with type parameter of the input type.
Edit: As the comments suggest actually Nullable<>
is treated specially, and in the runtime to boot as explained in this article.