Let\'s say that I have the methodInfo for something like Nullable.
Is there anyway to convert it to Nullable
You can do it easily with a little more reflection. You can't do it magically without reflection.
static void Main(string[] args)
{
PropertyInfo intHasValue = typeof (int?).GetProperty("HasValue");
PropertyInfo boolHasValue = ChangeGenericType(intHasValue, typeof (bool));
}
public static PropertyInfo ChangeGenericType(PropertyInfo property, Type targetType)
{
Type constructed = property.DeclaringType;
Type generic = constructed.GetGenericTypeDefinition();
Type targetConstructed = generic.MakeGenericType(new[] {targetType});
return targetConstructed.GetProperty(property.Name);
}
Of course this is pretty specific to only work for generic types with a single type parameter but it could be generalized to do more if needed.