twiglet / cs2j

C# to Java Converter
www.cs2j.com
Other
167 stars 73 forks source link

Implement IComparer #19

Open twiglet opened 13 years ago

twiglet commented 13 years ago

Comparator Interface IComparer from C# is not translated correctly. The generated Java class looks as follows: public class PostProfileComparer extends IComparer { public int Compare( PostProfile x, PostProfile y) throws Exception { return y.getScore().Compare(x.getScore()); }

} but interface IComparer is not defined, and also method Compare is not defined on type int (the result type of method getScore()).

We haven't yet implemented the IComparer class. I will look into that. When we do then y.GetScore() should be automatically cast to an Integer before we call the Compare method.

twiglet commented 13 years ago

Or alternatively use the < > == comparison on the ints directly. Simply returning y.getScore() - x.getScore() would be a simple solution, Unfortunately this is not safe regarding int overflows.  I have translated it to   return y.getScore() == x.getScore() ? 0 : (y.getScore() > x.getScore() ? 1 : -1)