<p>Once again one of those: "Is there an easier built-in way of doing things instead of my helper method?"</p>

<p>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?</p>

<p>So I have</p>

<pre><code>typeof(int)
typeof(DateTime)
System.Type t = something;
</code></pre>

<p>and I want</p>

<pre><code>int? 
DateTime?
</code></pre>

<p>or</p>

<pre><code>Nullable&lt;int&gt; (which is the same)
if (t is primitive) then Nullable&lt;T&gt; else just T
</code></pre>

<p>Is there a built-in method?</p>

Here is the code I use:
```
```
Type GetNullableType(Type type) {
    // Use Nullable.GetUnderlyingType() to remove the Nullable<T> wrapper if type is already nullable.
    type = Nullable.GetUnderlyingType(type) ?? type; // avoid type becoming null
    if (type.IsValueType)
        return typeof(Nullable<>).MakeGenericType(type);
    else
        return type;
}
```
```