ripper234
ripper234

Reputation: 230008

C# --> Java code generator

I have a small (~2000 lines of code) class that I would like to use from both java & .NET. There are several approaches to do this - among them wrapping the class as a service, using some interop voodoo, or duplicating the code to both C# & java.

Do you know an out-of-the-box tool that accomplishes the latter - takes a simple C# class with no dependencies and converts it to an equivalent java class?

Upvotes: 0

Views: 2498

Answers (5)

Pavel Savara
Pavel Savara

Reputation: 3457

This is list of tools I know. Sharpen or j2cstranslator looks like good options.

Upvotes: 0

Steve Schnepp
Steve Schnepp

Reputation: 4680

It's not really what you asked for, but I would just create a simple C# to Java translator.

The differences are not that huge and you seem to be the author of the source so you can avoid nasty constructs that are quite difficult to translate. That way your translator would be quite simple. I would go from C# to Java because C# is more expressive, and you can emulate almost all the C# functions in Java.

Actually cs2java seems to do just that.

Upvotes: 0

Brian Hedler
Brian Hedler

Reputation: 559

There used to be a COM bridge and you can register C# assemblies for use in COM with regasm.exe or visual studio.

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1038720

IKVM.NET does pretty good job in taking a jar file and compiling it to a managed .NET assembly.

Upvotes: 3

Marc Gravell
Marc Gravell

Reputation: 1062580

If it is small (or in fact, even if it is large), I'm not sure of the wisdom of mechanical translation tools; I've simply never had much joy with them. However, one option would be to write the .NET code in J#.

But I stress - if it was me, I'd manually port it between the two manually and maintain them separately. Most of the time the differences aren't huge - signed bytes, the boxing differences, etc. Of course, anything with delegates will need changing - and captured variables work differently, etc etc.

Upvotes: 2

Related Questions