I am having to port code from Java to C# (and soon the other way round) by copying and pasting and then editing compiler errors. (Please accept that this is necessary; I can
Converting from Java to C# is difficult not only because of language difference, but because of not compatible base libraries. As for me, the best way to convert from Java to .Net is using IKVM - an implementation of Java for Mono/.NET
Perhaps the Java Language Conversion Assistant Wizard could assist you here?
http://msdn.microsoft.com/en-us/library/7tatw8a2(VS.80).aspx
In addition I would suggest something like Resharper or another refactoring tool to take advantage of the C# language features and make your code more efficient and readable.
edit:
V3 is available with VS2005, read this if you dont seem to have it installed: http://natarajana.com/jlca.aspx
One example - Java runs variable initializers after the superclass constructor. C# runs them before. This affects things if the superclass constructor then calls a virtual method overridden in the class in question. (This is generally a bad idea, but it happens.)
Then of course there's generics, which are very, very different. For example:
public class Foo<T>
{
static int counter;
}
In Java there's one counter
variable. In C# there's one per constructed type, so Foo<string>.counter
and Foo<int>.counter
are independent.
I'm afraid I don't know of any tools to identify this kind of thing.
I've done a certain amount of porting Java to C# myself, and I think it's important to try to make the resulting code as idiomatically "sharpy" as you can. Things like converting getters and setters to properties and sometimes indexers, for example. Implementing IDisposable
where appropriate... things like that.
IKVM is a great option for running java code in C#. You don't need to modify your java code. It simply takes a jar file and generates a .NET dll.
http://www.ikvm.net/
Going the other direction, from C# to java, will be difficult, as C# is basically a superset of java. You would need to limit the use of constructs which are not available in java.