Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rewrite or convert C# code in Java code?

I start to write a client - server application using .net (C#) for both client and server side.

Unfortunately, my company refuse to pay for Windows licence on server box meaning that I need to rewrite my code in Java, or go to the Mono way.

Is there any good way to translate C# code in Java ? The server application used no .net specific feature, only cross language tools like Spring.net, Hibernate.net and log4net.

Thanks.

like image 377
Seb Avatar asked Dec 30 '22 11:12

Seb


2 Answers

I'd suggest building for Mono. You'll run into some gray area, but overall it's great. However, if you want to build for Java, you might check out Grasshopper. It's a commercial product, but it claims to be able to translate CIL (the output of the C# compiler) to Java bytecodes.

like image 81
Nate Kohari Avatar answered Jan 02 '23 01:01

Nate Kohari


Possible solutions aside, direct translations of programs written in one language to a different language is generally considered a Bad Idea™ -- especially if this translation is done in some automated fashion. Even when done by a "real" programmer, translating an application line by line often results in a less than desirable end result because each language has its own idioms, strengths and weaknesses that require things be done in a slightly different way.

As painful as it may be, it's probably in your best interest and those who have to maintain this application to rewrite it in Java if that's what your employer requires.

like image 24
Brian Phillips Avatar answered Jan 01 '23 23:01

Brian Phillips