Convertir C# a Java

Traduzca cualquier biblioteca o aplicación de consola C# de nivel empresarial a su equivalente Java con total compatibilidad con .NET Framework. Traduzca millones de líneas de código a la vez con el mínimo esfuerzo manual.
Solicitar Servicio

CodePorting.Translator Cs2Java es una aplicación transpiladora

Puede utilizarse para configurar la traducción automática de código C# a Java, en continua mejora, con el fin de publicar la misma versión del software para ambos lenguajes sin cambiar las API ni la documentación del código. También puede ayudar a distribuir aplicaciones y bibliotecas de C# a plataformas en las que la compatibilidad con .NET no existe o es problemática.

Convierta código C# sin esfuerzo con nuestras potentes funciones

CodePorting.Translator Cs2Java es una aplicación transpiladora de código fuente a código fuente, que permite reproducir las clases y rutinas internas de la misma forma en que están implementadas en el código C# original.
public class A : B
{
    int B.this[int index]
    {
        get { return mArray[index]; }
        set { mArray[index] = value; }
    }

    private int[] mArray;
}

internal interface B
{
    int this[int index]
    {
        get; set;
    }
}


public class A implements B
{
    public final int get_Item(int index)
    {
        return mArray[index];
    }

    public final void set_Item(int index, int value)
    {
        mArray[index] = value;
    }

    private int[] mArray;
}

interface B
{
    int get_Item(int index);
    void set_Item(int index, int value);
}
using System.Threading;

class LambdaTest
{
    public void TestMPMM_1()
    {
        var a = 0;
        new Thread(() =>
        {
            var b = a;
        });
    }
}
import com.codeporting.ms.System.Threading.Thread;
import com.codeporting.ms.System.Threading.ThreadStart;

class LambdaTest
{
    private LambdaTest[] LambdaTest_this = {this};
    public final void testMPMM_1()
    {
        int[] a_closure = new int[]{0};
        new Thread(new ThreadStart() {
            public String getDelegateId() {
                return System.identityHashCode(LambdaTest_this[0]) + "-1342179863";
            }
            public void invoke() {
                int b = a_closure[0];
            }
        });
    }
}
using System;

class Program
{
    public static void Main(string[] args)
    {
        var printer = new Printer("\n");
        printer.Print("hello, Printer");
        IPrinter iprinter = printer;
        iprinter.Print("hello, IPrinter");
    }
}

interface IPrinter
{
    void Print(string text);
}

class Printer : IPrinter
{
    string endOfLine;

    public Printer(string endOfLine)
    {
        this.endOfLine = endOfLine;
    }

    public void Print(string text)
    {
        Console.Write($"[class method call] : {text}{endOfLine}");
    }

    void IPrinter.Print(string text)
    {
        Console.Write($"[interface method call] : {text}{endOfLine}");
    }
}
import com.codeporting.ms.System.Console;
import com.codeporting.ms.System.StringExtensions;

class Program
{
    public static void main(String[] args)
    {
        Printer printer = new Printer("\n");
        printer.print("hello, Printer");
        IPrinter iprinter = (printer).get_Printer_IPrinter();
        iprinter.print("hello, IPrinter");
    }
}

interface IPrinter
{
    void print(String text);
}

class Printer 
{
    private class Printer_IPrinter implements IPrinter
    {
        private Printer implementation;
        public Printer_IPrinter(Printer implementation)
        {
            this.implementation = implementation;
        }
        public final void print(String text)
        {
            Console.write(StringExtensions.format("[interface method call] : {0}{1}", text, this.implementation.endOfLine));
        }
    }

    final IPrinter get_Printer_IPrinter()
    {
        return new Printer_IPrinter(this);
    }

    private String endOfLine;

    public Printer(String endOfLine)
    {
        this.endOfLine = endOfLine;
    }

    public final void print(String text)
    {
        Console.write(StringExtensions.format("[class method call] : {0}{1}", text, endOfLine));
    }
}
using System;

class Vector2
{
    public float x, y;
    
    public Vector2(float x, float y)
    {
        this.x = x;
        this.y = y;
    }
    public Vector2()
    {
        this.x = 0f;
        this.y = 0f;
    }
    
    public override string ToString() => $"({x}, {y})";

    public static Vector2 operator +(Vector2 a, Vector2 b) => new Vector2(a.x + b.x, a.y + b.y);
    public static Vector2 operator -(Vector2 a, Vector2 b) => new Vector2(a.x - b.x, a.y - b.y);
    public static Vector2 operator *(Vector2 a, Vector2 b) => new Vector2(a.x * b.x, a.y * b.y);
    public static Vector2 operator /(Vector2 a, Vector2 b) => new Vector2(a.x / b.x, a.y / b.y);
    public static Vector2 operator *(Vector2 a, float b) => new Vector2(a.x * b, a.y * b);
    public static Vector2 operator /(Vector2 a, float b) => new Vector2(a.x / b, a.y / b);
}

class Program
{
    public static void Main(string[] args)
    {
        Vector2 a = new Vector2(1f, 2f);
        Vector2 b = new Vector2(3f, 4f);
        Vector2 c = (a + b) * 2f;
        Vector2 d = c / 10f;
        Console.WriteLine($"a = {a}, b = {b}, c = {c}, d = {d}");
    }
}
import com.codeporting.ms.System.Console;
import com.codeporting.ms.System.StringExtensions;

class Vector2
{
    public float x, y;
    
    public Vector2(float x, float y)
    {
        this.x = x;
        this.y = y;
    }
    public Vector2()
    {
        this.x = 0f;
        this.y = 0f;
    }
    @Override
    public /*override*/ String toString()
    {
        return StringExtensions.format("({0}, {1})", x, y);
    }
    public static Vector2 op_Addition(Vector2 a, Vector2 b)
    {
        return new Vector2(a.x + b.x, a.y + b.y);
    }
    public static Vector2 op_Subtraction(Vector2 a, Vector2 b)
    {
        return new Vector2(a.x - b.x, a.y - b.y);
    }
    public static Vector2 op_Multiply(Vector2 a, Vector2 b)
    {
        return new Vector2(a.x * b.x, a.y * b.y);
    }
    public static Vector2 op_Division(Vector2 a, Vector2 b)
    {
        return new Vector2(a.x / b.x, a.y / b.y);
    }
    public static Vector2 op_Multiply(Vector2 a, float b)
    {
        return new Vector2(a.x * b, a.y * b);
    }
    public static Vector2 op_Division(Vector2 a, float b)
    {
        return new Vector2(a.x / b, a.y / b);
    }
}

class Program
{
    public static void main(String[] args)
    {
        Vector2 a = new Vector2(1f, 2f);
        Vector2 b = new Vector2(3f, 4f);
        Vector2 c = Vector2.op_Multiply((Vector2.op_Addition(a, b)), 2f);
        Vector2 d = Vector2.op_Division(c, 10f);
        Console.writeLine(StringExtensions.format("a = {0}, b = {1}, c = {2}, d = {3}", a, b, c, d));
    }
}
using System;
using System.Collections;

public class Test
{
    public void PrintFibonacci()
    {
        Console.WriteLine("Fibonacci numbers:");

        foreach (int number in GetFibonacci(5))
        {
            Console.WriteLine(number);
        }
    }

    IEnumerable GetFibonacci(int maxValue)
    {
        int previous = 0;
        int current = 1;

        while (current <= maxValue)
        {
            yield return current;

            int newCurrent = previous + current;
            previous = current;
            current = newCurrent;
        }
    }
}
import com.codeporting.ms.lang.Operators;
import com.codeporting.ms.System.Collections.Generic.IGenericEnumerable;
import com.codeporting.ms.System.Collections.Generic.IGenericEnumerator;
import com.codeporting.ms.System.Collections.IEnumerable;
import com.codeporting.ms.System.Console;
import com.codeporting.ms.System.Environment;
import com.codeporting.ms.System.IDisposable;
import java.util.Iterator;

public class Test
{
    public final void printFibonacci()
    {
        Console.writeLine("Fibonacci numbers:");
        //Foreach to while statement conversion
        Iterator variable1 = getFibonacci(5).iterator();
        try
        {
            while (variable1.hasNext())
            {
                int number = Operators.unboxing(variable1.next(),int.class);
                Console.writeLine(number);
            }
        }
        finally
        {
            IDisposable variable2 = Operators.as(variable1, IDisposable.class);
            if (variable2 != null)
            {
                variable2.dispose();
            }
        }
    }

    private IEnumerable getFibonacci(int maxValue)
    {
        return new YieldIterator_GetFibonacci(-2, this, maxValue);
    }

    private class YieldIterator_GetFibonacci implements IGenericEnumerable<Object>, IGenericEnumerator<Object>, IDisposable
    {
        private int __state;
        private Object __current;
        private long __initialThreadId;
        private Test __this;
        private int previous;
        private int current;
        private int maxValue;
        public YieldIterator_GetFibonacci(int __state, Test __this, int maxValue)
        {
            this.__state = __state;
            this.__this = __this;
            this.maxValue = maxValue;
            __initialThreadId = Thread.currentThread().getId();
        }

        public final void dispose()
        {
        }

        public final boolean hasNext()
        {
            switch (__state)
            {
                case 0:
                    previous = 0;
                    current = 1;
                    if (current <= maxValue)
                    {
                        __current = current;
                        __state = 1;
                        return true;
                    }
                    else
                    {
                        __state = 2;
                        return hasNext();
                    }

                case 1:
                    int newCurrent = previous + current;
                    previous = current;
                    current = newCurrent;
                    if (current <= maxValue)
                    {
                        __current = current;
                        __state = 1;
                        return true;
                    }
                    else
                    {
                        __state = 2;
                        return hasNext();
                    }

                default:
                    __state = -1;
                    return false;
            }
        }

        public final Object next()
        {
            return __current;
        }

        public final void reset()
        {
            throw new com.codeporting.ms.System.NotSupportedException();
        }

        public final IGenericEnumerator<Object> iterator()
        {
            if (__state == -2 && __initialThreadId == Thread.currentThread().getId())
            {
                __state = 0;
                return this;
            }
            else
            {
                return new YieldIterator_GetFibonacci(0, __this, maxValue);
            }
        }
    }
}

csharp converter feature
Dependencias externas
Sustituir el código escrito manualmente como reemplazo de la dependencia que no está disponible para la traducción
csharp converter feature
Preservación de API
Las construcciones específicas del lenguaje utilizadas en el código C# se traducen a sus equivalentes Java más adecuados

CodePorting.Translator Java Class Library

Para convertir un proyecto C# a Java, no basta con traducir el código fuente de un lenguaje a otro. Obviamente, para ejecutar código C# se necesita la biblioteca de clases .NET Framework. Por lo tanto, para ejecutar el código Java traducido también se necesitaría algo similar.

CodePorting.Translator Java Class Library proporciona un reemplazo Java de la biblioteca de clases .NET Framework, manteniendo la lógica y la estructura de la biblioteca de clases .NET Framework, lo que hace que un proyecto traducido se sienta como en casa, ocultándolo de la implementación de la plataforma Java. Junto con las características principales de .NET, nuestra biblioteca soporta System.Net, System.Drawing, System.XML, System.Security y otros subsistemas.
csharp to java conversion scheme

Ejemplos de productos C# traducidos exitosamente a Java

Artículos relacionados: