How to check if two types can be compared, summed etc.?

Posted by Marcus on Stack Overflow See other posts from Stack Overflow or by Marcus
Published on 2010-03-25T19:15:01Z Indexed on 2010/03/25 19:23 UTC
Read the original article Hit count: 363

Filed under:
|

Hi, if given two types (Type a, Type b), is there any "nice" way to find out if those two can be compared, summed etc.?

I was thinking if the types implement IConvertible, one could convert both to lets say decimal and perform a "Convert.ToDecimal(a) > Convert.ToDecimal(b)" ?

I am building an expression evaluator and want to be able to work with any kind of object and thus need to know if a type can be compared to another type (it DOESN'T have to be the same types on both sides. eg. double > int)

© Stack Overflow or respective owner

Related posts about c#

Related posts about iconvertible