Reflection and Nullable/Generic types

  • Thread starter Thread starter Kenneth Baltrinic
  • Start date Start date
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
 
Kenneth,

Check out Type.GetGenericTypeArguments and Type.MakeGenericType
respectively.


Mattias
 
Back
Top