将 C++/CLI 翻译为 C#
如何将小型 C++/CLI 项目转换为 C#
How I can translate small C++/CLI project to c#
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何将小型 C++/CLI 项目转换为 C#
How I can translate small C++/CLI project to c#
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
一种迂回的手动方法是编译 C++/CLI 项目并在 Reflector< 中打开输出程序集/a>.反汇编每个类,将反汇编的 IL 转换为 C#,然后保存该代码。
至于自动执行此操作的方法,我想不出任何方法。
话虽如此,您确定您真的想要将您的项目转换为 C# 吗?如果您的 C++/CLI 项目使用任何非托管代码,您将很难想出纯托管的等效代码。如果项目或多或少由纯 CLR 代码组成,并且为了用 C++/CLI 编写而用 C++/CLI 编写,我可以理解想要将其转换为 C#。但如果有理由用 C++/CLI 编写它,您可能希望保持这种方式。
One roundabout, manual way would be to compile your C++/CLI project and open the output assembly in Reflector. Disassemble each class, have it convert the disassembled IL to C#, and save that code off.
As for an automatic way to do it, I can't think of any off the top of my head.
Those things being said, are you sure you really want to convert your project to C#? If your C++/CLI project uses any unmanaged code, you'll have a difficult time coming up with a purely managed equivalent. If the project is more or less composed of pure CLR code, and it was written in C++/CLI for the sake of being written in C++/CLI, I can understand wanting to convert it to C#. But if there was a reason for writing it in C++/CLI, you may want to keep it that way.
恕我直言,逐行是最好的方法。我已经将几个 C++ 风格的项目移植到托管语言中,并且尝试了各种方法;翻译人员、逐行、脚本编写等……随着时间的推移,我发现最有效的方法是逐行执行,尽管一开始这似乎是最慢的方法。
译者丢失了太多东西。没有一个翻译器是完美的,您最终会花费大量时间来修复翻译后的代码。此外,翻译后的代码通常很丑陋,而且往往比手工编写的代码可读性较差。所以结果是一个固定的、不是很漂亮的代码库。
我逐行提供的一些提示
IMHO, line by line is the best way. I've ported several C++ style projects to a managed language and I've tried various approaches; translators, line by line, scripting, etc ... Over time I've found the most effective way is to do it line by line even though it seems like the slowest way at first.
Too much is lost in a translator. No translator is perfect and you end up spending a lot of time fixing up the translated code. Also, translated code as a rule is ugly and tends to be less readable than hand crafted code. So the result is a fixed up, not very pretty code base.
A couple of tips I have on line by line
我还没有尝试过,但我只是用谷歌搜索了一下,发现了这个: http://code2code.net/
根据它,您不应该完全依赖它生成的代码:
另请阅读:将 C++/CLI 转换为 C#
I haven't tried it, but I just googled it and found this: http://code2code.net/
According t it, you shouldn't fully rely on the code it produces:
Also, read this: Translate C++/CLI to C#