I have too methods:
public TValueType? DoStuffWithValueType<TValueType>(int x, int y)
where TValueType: struct {}
public TRefType DoStuffWithRefType<TRefType>(int x, int y)
where TRefType: class {}
How can i wrap them in a new third method?
The following is not compiling since i cannot persuade the compiler that T is in fact a struct when calling DoStuffWithValueType:
public T DoStuff<T>(int x, int y) {
if(typeof(T).IsValueType)
{
return DoStuffWithValueType<T>(x, y);
}
return DoStuffWithRefType<T>(x, y);
}
I already tried overloading DoStuff, but this attempt failed since generic-constraints are not part of the method signature.
I also tried to get rid of the constraints, but i could not.
Any ideas? Thank you!
structconstraint. Nullable value types cannot be used with eitherclassorstructconstraints.