Hi,
I'm in the process of upgrading an Object-Relational mapping library to .NET
2.0 and am wanting to implement support for Nullable typess.
I'm using Reflection to analyise the object that is being mapped and
building up a schema for the mapping.
This means I need a way to determine if the PropertyInfo.PropertyType is an
implementation of System.Nullable<>. I've been batting my head against this
for a while and only come up with one solution.
private static bool IsNullable(Type type)
{
if(!type.IsGenericType)
return false;
Type[] parameters = new Type[] { type.GetGenericArguments()[0] };
Type constructedType = typeof(Nullable<>).MakeGenericType(parameters);
return type == constructedType;
}
which I think is less than optimal.
Any suggestions?