An unconstrained type parameter can be a nullable reference, non-nullable reference, value type or nullable value type.
Is it possible to roundtrip a parameter through object[?] ?
The following simplified code demonstrates the problem:
public static void Foo<U>(U unconstrainedParameter)
{
object? nullableObject = unconstrainedParameter;
U assignBack = (U)nullableObject; // [CS8600] Converting null literal or possible null value to non-nullable type.
}
If we change nullableObject to type object
then I get the error even at the assignment.
Is there some "trick" to do this roundtrip conversion without the need to suppress the warning (by using a nullable object and then ! when converting back)