We were playing with Nullable types this week - came across some interesting methods that are available to interrogate Nullable types.
To get at the underlying data type in the Nullable type:
System.Nullable.GetUnderlyingType(type)And to find out more about a Type, whether it's a generic, whether it's a Nullable type, and what are the generic template arguments...
string s = "23";
object o = Convert.ChangeType( s, typeof( int ) );
Nullable ni = 3;
Type t = ni.GetType();
Type t2 = typeof( Nullable );
if ( t2.IsGenericType && t2.GetGenericTypeDefinition() == typeof(Nullable<>))
{
Type baseType = t2.GetGenericArguments()[0];
object o2 = Convert.ChangeType( s, baseType );
//return Activator.CreateInstance(ft, val);
}
Google groups post
here