I'm trying to write an extension method on numeric types to be used in a fluent testing framework I'm building. Basically, I want to do this:
public static ShouldBeGreaterThan<T>(this T actual, T expected, string message)
where T : int || T: double || etc...
Just where T : struct
doesn't do, since that will also match string
and bool
, and possibly something else I'm forgetting. is there something I can do to match only numeric types? (Specifically types that implement the >
and <
operators, so I can compare them... If this means I'm matching dates as well, it doesn't really matter - the extension will still do what I expect.)