You can't. When you compile:
DoSomething<string?>();
DoSomething<string>();
the compiler emits:
DoSomething<string>();
DoSomething<string>();
So the nullability of the type parameter is lost.
You could add a
notnull
constraint to the type parameter if it should never accept
null
. But without it, you can't differentiate between nullable and non-nullable reference types.