Given a type T, is there any way to write something equivalent of
if (typeof(T).ImplementsProperty(MaxValue))
{
return T ?? typeof(T).MaxValue;
}
else
return T;
Note that I don’t need a generic type constraint on the class or method, I just need a conditional in the method body. T in this case can be any IComparable. I’m trying to get null numeric/date types to be ordered with the nulls occurring last.
Edit: Sorry there is an error in the above syntax as pointed out by Ray. It should be returning value ?? typeof(T).MaxValue given a T value or something like that. Hope thats clear.
This seems to work for me for nullable, value and reference types:
Is this what you wanted?