แปลง C# เป็น Java

แปลไลบรารี C# หรือแอปพลิเคชันคอนโซลระดับองค์กรให้เทียบเท่ากับ Java พร้อมการสนับสนุน .NET Framework อย่างเต็มรูปแบบ แปลโค้ดหลายล้านบรรทัดในคราวเดียวโดยใช้ความพยายามเพียงเล็กน้อย
ขอรับบริการ

CodePorting.Translator Cs2Java เป็นแอปพลิเคชั่นทรานสไพเลอร์

สามารถใช้เพื่อตั้งค่าการแปลอัตโนมัติของการปรับปรุงโค้ด C# เป็น Java อย่างต่อเนื่องเพื่อเผยแพร่ซอฟต์แวร์เวอร์ชันเดียวกันสำหรับทั้งสองภาษาโดยไม่ต้องเปลี่ยน API หรือเอกสารโค้ด นอกจากนี้ยังสามารถช่วยในการส่งมอบแอปพลิเคชันและไลบรารี C# ไปยังแพลตฟอร์มที่ไม่มีการสนับสนุน .NET หรือมีปัญหา

แปลงโค้ด C# ได้อย่างง่ายดายด้วยฟีเจอร์อันทรงพลังของเรา

CodePorting.Translator Cs2Java เป็นแอปตัวแปลซอร์สโค้ดถึงซอร์สโค้ด ซึ่งช่วยให้สามารถทำซ้ำคลาสภายในและรูทีนในลักษณะเดียวกับที่ใช้ในโค้ด C# ดั้งเดิม
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
การพึ่งพาภายนอก
แทนที่โค้ดที่เขียนด้วยตนเองเพื่อทดแทนการขึ้นต่อกันซึ่งไม่สามารถแปลได้
csharp converter feature
การอนุรักษ์ API
The language-specific constructs used in the C# code are translated into the best-matched Java equivalents

CodePorting.Translator Java Class Library

ในการแปลงโปรเจ็กต์ C# เป็น Java การแปลซอร์สโค้ดจากภาษาหนึ่งเป็นอีกภาษาหนึ่งนั้นไม่เพียงพอ แน่นอนว่าในการรันโค้ด C# เราจำเป็นต้องมีไลบรารีคลาส .NET Framework ดังนั้นในการรันโค้ด Java ที่แปลแล้วเราจำเป็นต้องมีสิ่งที่คล้ายกันด้วย

CodePorting.Translator Java Class Library นำเสนอการแทนที่ Java ของไลบรารีคลาส .NET Framework โดยคงตรรกะและโครงสร้างของไลบรารีคลาส .NET Framework ซึ่งทำให้โปรเจ็กต์ที่แปลแล้วรู้สึกเหมือนอยู่บ้าน โดยซ่อนตัวจากการนำแพลตฟอร์ม Java ไปใช้ นอกเหนือจากคุณสมบัติหลักของ .NET แล้ว ไลบรารีของเรายังรองรับ System.Net, System. Drawing, System.XML, System.Security และระบบย่อยอื่นๆ
csharp to java conversion scheme

ตัวอย่างของผลิตภัณฑ์ C# ที่แปลเป็น Java ได้สำเร็จ

บทความที่เกี่ยวข้อง