Given the following code:
public static TUnbox UnboxAndNullCheck<TUnbox, TBox>(TBox obj, string msg = "Unboxing error") where TUnbox : class, TBox
{
var unboxObj = obj as TUnbox;
if (unboxObj == null)
throw new ArgumentNullException( msg );
return unboxObj;
}
It seems calling it requires both type parameters as so:
UnboxAndNullCheck<SubClass, BaseClass>( obj );
Is it possible to call it in a way where you do not have to specify the type of obj?
UnboxAndNullCheck<SubClass>( obj );