Assuming you are only ever comparing doubles, then just declare the objects as doubles. Something like:
If you need to compare other types, you might use a generic methodCode:public bool FnLessThan(FSFunction fn) { double v1, v2; try { v1 = Convert.ToDouble(fn.GetParm(0)); v2 = Convert.ToDouble(fn.GetParm(1)); } catch( Exception ) { return false; } return v1 < v2 ? true : false; }
I've constrained the above method to work only from types derived from Tbase (which you'll have to define). You also need to implement the IComparable in Tbase and override the CompareTo() method in each derived class. I don't expect the code snippet above to work right out of the box, but hopefully it will give you some ideas.Code:public bool FnLessThan<T1, T2>(FSFunction fn) Where T1 : Tbase Where T2 : Tbase { T1 v1; T2 v2; try { v1 = (T1) Convert.ChangeType(fn.GetParm(0), typeof( T1 ) ); v2 = (T2) Convert.ChangeType(fn.GetParm(1), typeof( T2 ) ); } catch( Exception ) { return false; } return 0 > v1.CompareTo( v2 ) ? true : false; }




Reply With Quote
