Implementing monadic bind for Nullable<> *and* reference types
===

I have this function:

    public static U? IfNotNull<T, U>(this T? self, Func<T, U?> func)
        where T : struct
        where U : struct
    {
        return (self.HasValue) ? func(self.Value) : null;
    }

Example:

    int? maybe = 42;
    maybe.IfNotNull(n=>2*n); // 84
    
    maybe = null;
    maybe.IfNotNull(n=>2*n); // null

I want it to work on implicitly-nullable reference types as well as explicit `Nullable<>` types. This implementation would work:

    public static U IfNotNull<T, U>(this T? self, Func<T, U> func)
        where T : struct
        where U : class
    {
        return (self.HasValue) ? func(self.Value) : null;
    }

But of course overload resolution does not look at type constraints, so you can't have both at once. Is there a solution to this?