Reflection and Nullable/Generic types

K

Kenneth Baltrinic

I need to perform two functions that I can't figure out how to do as
follows:

Type GetUnderlyingTypeForNullableType( Type nullableType)
{
//For every value type T where nullableType = typeof(Nullable<T>)
//need to return typeof(T)
return ....
}

And a the revers function:

Type GetNullableVersionOfType( Type type)
{
//For every value type T such that type = typeof(T), return
typeof(Nullable<T>);
return....
}

And unfortunately no, I can't make these methods generic.

Thanks for the help!
--Ken
 
M

Mattias Sjögren

Kenneth,

Check out Type.GetGenericTypeArguments and Type.MakeGenericType
respectively.


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top