How do I convert a System.Type to its nullable version?
Posted
by AlexDuggleby
on Stack Overflow
See other posts from Stack Overflow
or by AlexDuggleby
Published on 2008-09-20T13:08:11Z
Indexed on
2010/03/18
22:11 UTC
Read the original article
Hit count: 347
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, but how do I get the nullable version of a .NET type?
So I have
typeof(int)
typeof(DateTime)
System.Type t = something;
and I want
int?
DateTime?
or
Nullable<int> (which is the same)
if t is primitive then Nullable<T> else just T
Any suggestions? (Is there something built in.) Thanks in advance.
© Stack Overflow or respective owner