有没有一个有效的工具可以将C#代码转换为Java代码?

发布于 2024-07-04 19:40:37 字数 34 浏览 9 评论 0 原文

有没有一个有效的工具可以将C#代码转换为Java代码?

Is there an effective tool to convert C# code to Java code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(14

|煩躁 2024-07-11 19:40:37

我从来没有遇到过C#->Java转换工具。 语法很简单,但框架却截然不同。 即使有工具,我也会强烈建议不要使用。 我曾参与过几个“迁移”项目,并且不能足够强调地说,虽然转换似乎是一个不错的选择,但转换项目总是总是会变成金钱坑。 这不是捷径,您最终得到的是不可读的代码,并且没有利用目标语言。 从个人经验来看,假设重写是更便宜的选择。

I have never encountered a C#->Java conversion tool. The syntax would be easy enough, but the frameworks are dramatically different. Even if there were a tool, I would strongly advise against it. I have worked on several "migration" projects, and can't say emphatically enough that while conversion seems like a good choice, conversion projects always always always turn in to money pits. It's not a shortcut, what you end up with is code that is not readable, and doesn't take advantage of the target language. speaking from personal experience, assume that a rewrite is the cheaper option.

千と千尋 2024-07-11 19:40:37

我们有一个需要用 C# 和 Java 来维护的应用程序。 由于我们积极维护该产品,因此一次性移植不是一种选择。 我们研究了 Net2Java 和 Mainsoft 工具,但都没有满足我们的要求(Net2Java 缺乏稳健性,而 Mainsoft 则成本高且缺乏源代码转换)。 我们创建了自己的工具,名为 CS2J,它作为我们夜间构建脚本的一部分运行,并对我们的 C# 进行了非常有效的移植代码转为Java。 现在它已经足够好来翻译我们的应用程序,但在被视为一个综合工具之前还有很长的路要走。 我们已经将该技术授权给了几个具有类似需求的各方,并且我们正在考虑公开发布它的想法,但这些天我们的核心业务让我们太忙了。

We have an application that we need to maintain in both C# and Java. Since we actively maintain this product, a one-time port wasn't an option. We investigated Net2Java and the Mainsoft tools, but neither met our requirements (Net2Java for lack of robustness and Mainsoft for cost and lack of source code conversion). We created our own tool called CS2J that runs as part of our nightly build script and does a very effective port of our C# code to Java. Right now it is precisely good enough to translate our application, but would have a long way to go before being considered a comprehensive tool. We've licensed the technology to a few parties with similar needs and we're toying with the idea of releasing it publicly, but our core business just keeps us too busy these days.

怀中猫帐中妖 2024-07-11 19:40:37

我不确定您希望将 C# 转换为 java 想要做什么,但如果您需要 .net 互操作性,您可能需要查看 单声道

I'm not sure what you are trying to do by wishing to convert C# to java, but if it is .net interoperability that you need, you might want to check out Mono

紫瑟鸿黎 2024-07-11 19:40:37

这是即兴的,但这不是 Grasshopper 是用来做什么的?

This is off the cuff, but isn't that what Grasshopper was for?

百善笑为先 2024-07-11 19:40:37

语法几乎相同,但它们依赖于不同的框架,因此唯一的转换方法是找懂两种语言的人并转换代码:)你的问题的答案是否定的,没有“有效”的工具来转换 c#到java

Well the syntax is almost the same but they rely on different frameworks so the only way to convert is by getting someone who knows both languages and convert the code :) the answer to your question is no there is no "effective" tool to convert c# to java

江湖正好 2024-07-11 19:40:37

也许您可以使用 jni4net - 开源桥 代替?
或者我知道的其他选项列表。

Possibly you could use jni4net - opensource bridge instead ?
Or list of other options I know.

猫瑾少女 2024-07-11 19:40:37

为什么不用 Haxe (http://haxe.org/) 编写并将其转换为您想要的任何内容是?

Why not write it in Haxe (http://haxe.org/) and convert it to whatever you want it to be?

蓦然回首 2024-07-11 19:40:37

C# 比 Java 拥有更多的功能。 以委托为例:许多非常简单的 C# 应用程序都使用委托,而 Java 人员认为观察者模式就足够了。 因此,为了让工具转换使用委托的 C# 应用程序,它必须将结构从使用委托转换为观察者模式的实现。
另一个问题是,C# 方法默认不是虚拟的,而 Java 方法是虚拟的。 此外,Java 没有办法使方法成为非虚拟方法。 这就产生了另一个问题:C# 中的应用程序可以通过多态性利用非虚拟方法行为,但这种方式不能直接转换为 Java。
如果你环顾四周,你可能会发现有很多工具可以将 Java 转换为 C#,因为它是一种更简单的语言(请不要攻击我,我没有说更糟糕,我说的是更简单); 然而,您会发现很少有像样的工具可以将 C# 转换为 Java。

我建议更改从 Java 转换为 C# 的方法,因为从长远来看,它会减少一些令人头疼的问题。 Db4Objects 最近向公众发布了他们的内部工具,他们使用该工具将 Db4o 转换为 C#。 它被称为锐化。 如果您在他们的网站上注册,您可以查看此链接,其中包含有关如何使用 Sharpen 的说明:
http://developer.db4o.com/Resources/view.aspx/参考/Sharpen/How_To_Setup_Sharpen

(我已经在他们那里注册了一段时间,他们很擅长不发送垃圾邮件)

C# has a few more features than Java. Take delegates for example: Many very simple C# applications use delegates, while the Java folks figures that the observer pattern was sufficient. So, in order for a tool to convert a C# application which uses delegates it would have to translate the structure from using delegates to an implementation of the observer pattern.
Another problem is the fact that C# methods are not virtual by default while Java methods are. Additionally, Java doesn't have a way to make methods non virtual. This creates another problem: an application in C# could leverage non virtual method behavior through polymorphism in a way the does not translate directly to Java.
If you look around you will probably find that there are lots of tools to convert Java to C# since it is a simpler language (please don't flame me I didn't say worse I said simpler); however, you will find very few if any decent tools that convert C# to Java.

I would recommend changing your approach to converting from Java to C# as it will create fewer headaches in the long run. Db4Objects recently released their internal tool which they use to convert Db4o into C# to the public. It is called Sharpen. If you register with their site you can view this link with instructions on how to use Sharpen:
http://developer.db4o.com/Resources/view.aspx/Reference/Sharpen/How_To_Setup_Sharpen

(I've been registered with them for a while and they're good about not spamming)

鹿童谣 2024-07-11 19:40:37

尝试看看 Net2Java 在我看来,自动(或半)的最佳选择至少自动)从 C# 到 Java 的转换

Try to look at Net2Java It seems to me the best option for automatic (or semi-automatic at least) conversion from C# to Java

や三分注定 2024-07-11 19:40:37

它们不直接转换,但它允许 .NET 和 J2EE 之间的互操作性。

http://www.mainsoft.com/products/index.aspx

They don't convert directly, but it allows for interoperability between .NET and J2EE.

http://www.mainsoft.com/products/index.aspx

戈亓 2024-07-11 19:40:37

这些人似乎对此有解决方案,但我还没有尝试过。 他们还有转换器的演示版本。

These guys seem to have a solution for this, but I haven't tried yet. They also have a demo version of the converter.

£冰雨忧蓝° 2024-07-11 19:40:37

Although this is an old-ish question, take a look at xmlVM http://www.xmlvm.org/clr2jvm, I'm not sure if it's mature enough yet, although it has been around for several years now. XMLvm was made, I believe, primarily for translating Android Java apps to the iPhone, however, its XML-code-translation-based framework is flexible enough to do other combinations (see the diagrams on the site).

As for a reason to do this conversion, maybe there is a need to 'hijack' some of the highly abundant oss code out there and use it within his/their own [Java] project.

Cheers

Rich

混吃等死 2024-07-11 19:40:37

微软有一个工具可以将java转换为C#。 对于相反的方向,请查看此处此处。 如果这不起作用,手动转换源代码应该不会花太长时间,因为 C# 和 java 非常相似,

There is a tool from Microsoft to convert java to C#. For the opposite direction take a look here and here. If this doesn't work out, it should not take too long to convert the source manually because C# and java are very similar,

情话难免假 2024-07-11 19:40:37

此博客帖子建议了来自有形。

This blog post suggests useful results from Tangible.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文