Java to CSharp Compiler

Of late I have been thinking of how to convert business objects that are Plain Old Java Objects into C# code.

Here is sed for windows, the stream editor.

The following sed commands:

s/main/Main/
s/String/string/
s/System.out.println/System.Console.WriteLine/

Can transform the cannonical java hello world:

public class Hello
{
         public static void main(String[] args)
         {
                  System.out.println(“Hello, World”);
         }
}

into the cannonical C# hello world

public class Hello
{
         public static void main(String[] args)
         {
                  System.out.println(“Hello, World”);
         }
}

This is a starting point for a java to c# cross complier.

It would be interesting to try to apply this to a more complex java application.
Add a few interop base classes and we have a useful product.

Given that the two languages have very similar syntax it could be an easy task.
The only trick would be replacing extends and implements, but the super sed that I linked to has multi-line pattern matching!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s