My aim is a simple Minimum function for generic nullable structs. The based extension method is simple and compiles well:
public static T Minimum<T>(this T struct1, T struct2) where T : struct, IComparable
{
return struct1.CompareTo(struct2) < 0 ? struct1 : struct2;
}
However the nullable generic version of that has a problem with recognising that extension method:
public static Nullable<T> Mininum<T>(this Nullable<T> struct1, Nullable<T> struct2) where T: struct, IComparable
{
if (!struct1.HasValue)
return struct2;
if (!struct2.HasValue)
return struct1;
// this line won't compile - the Minimum extension method is not visible
return struct1.Value.Minimum(struct2.Value);
}
When using a the non-nullable generic Minimum on e.g. a DateTime instance, it simply works. Anyone has an idea why the compiler doesn’t make the non-nullable generic Minimum visible in the nullable generic Minimum extension method?