如何将代码从 C# 转换为 PHP

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/441161/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 03:29:22  来源:igfitidea点击:

How to convert code from C# to PHP

c#phpparsingconverter

提问by Tomasz Smykowski

I have a business logic classes that are written in pure C# (without any specific things from this language) and I would convert this code into PHP. I can write my own parser, but think if I could someone did it before me.

我有一个用纯 C# 编写的业务逻辑类(没有来自这种语言的任何特定内容),我会将这段代码转换为 PHP。我可以编写自己的解析器,但想想是否有人在我之前做过。

Could you please tell me where can I find this kind of converter?

你能告诉我在哪里可以找到这种转换器吗?

Ps. As I've written I use only plain C# programming in this language. Only arguments, declarations of variables, equations and control statements.

附言。正如我所写的,我只使用这种语言的普通 C# 编程。只有参数、变量声明、方程和控制语句。

采纳答案by Spencer Ruport

I know you're hoping for someone who had experience but in case no one comes forward...

我知道你希望有人有经验,但万一没有人挺身而出......

You might consider just copy and pasting the code into a PHP script and checking what breaks. Write a parser to fix that, run it across the entire script, and see what's the next thing that breaks. Continue until the script functions as expected.

您可能会考虑将代码复制并粘贴到 PHP 脚本中,然后检查哪些中断了。编写一个解析器来解决这个问题,在整个脚本中运行它,然后看看接下来会发生什么。继续,直到脚本按预期运行。

If you're not using any of the more involved .Net classes I can't imagine you'll have too much trouble.

如果您不使用任何更复杂的 .Net 类,我无法想象您会遇到太多麻烦。

回答by Ross

Are you asking for a tool to directly convert your C# code to PHP? I doubt there is one available and I'd be a little worried about using one (from what I've learnt of C# it's not easily transferrable to PHP).

您是否需要一种将 C# 代码直接转换为 PHP 的工具?我怀疑是否有一个可用的,我会有点担心使用一个(根据我对 C# 的了解,它不容易转移到 PHP)。

Depending on the size of the project I'd be much more inclined to rewrite it. I did have a look but couldn't find anything (lots and lots of job requests though - looks like a business there =P).

根据项目的大小,我更倾向于重写它。我确实看过但找不到任何东西(尽管有很多工作请求 - 看起来像那里的企业=P)。

回答by mcintyre321

You can now run your PHP code on .NET calling into your business clases using phalanger.codeplex.com

您现在可以使用 phalanger.codeplex.com 在调用业务类的 .NET 上运行 PHP 代码

回答by Piotr St?clik

There is just started project cs2php. Sources are available on https://github.com/isukces/cs2phpand homepage is http://www.cs2php.com/.

有刚刚启动的项目cs2php。来源可在https://github.com/isukces/cs2php和主页是http://www.cs2php.com/