C# から Java 変換

エンタープライズ レベルの C# ライブラリまたはコンソール アプリケーションを、.NET Framework を完全にサポートする同等の Java に変換します。 最小限の手作業で数百万行のコードを一度に翻訳します。
リクエストサービス

CodePorting.Translator Cs2Java はトランスパイラ アプリケーションです

API やコード ドキュメントを変更せずに、両方の言語で同じバージョンのソフトウェアをリリースするために、継続的に改善されている C# コードを Java に自動翻訳するように設定するために使用できます。 また、.NET サポートが存在しないか、問題があるプラットフォームに C# アプリケーションとライブラリを配信する場合にも役立ちます。

強力な機能を使用して 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の保存
C# コードで使用される言語固有の構成要素は、最適な Java の同等の構成要素に変換されます。

CodePorting.Translator Java Class Library

C# プロジェクトを Java に変換するには、ソース コードをある言語から別の言語に翻訳するだけでは十分ではありません。 明らかに、C# コードを実行するには、.NET Framework クラス ライブラリが必要です。 したがって、翻訳された Java コードを実行するには、同様のものも必要になります。

CodePorting.Translator Java Class Libraryは、.NET Framework クラス ライブラリの Java 代替機能を提供し、.NET Framework クラス ライブラリのロジックと構造を維持します。これにより、翻訳されたプロジェクトが Java プラットフォーム実装から隠蔽され、安心感を得ることができます。 .NET コア機能に加えて、ライブラリは System.Net、System.Drawing、System.XML、System.Security、およびその他のサブシステムをサポートしています。
csharp to java conversion scheme

Java に正常に変換された C# 製品の例

関連記事