什么是最好的 C# 到 VB.net 转换器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/88359/
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
What is the best C# to VB.net converter?
提问by Florian
While searching the interweb for a solution for my VB.net problems I often find helpful articles on a specific topic, but the code is C#. That is no big problem but it cost some time to convert it to VB manually. There are some sites that offer code converters from C# to VB and vice versa, but to fix all the flaws after the code-conversion is nearly as time-consuming as doing it by myself in the first place.
在网上搜索我的 VB.net 问题的解决方案时,我经常找到有关特定主题的有用文章,但代码是 C#。这不是什么大问题,但手动将其转换为 VB 需要一些时间。有一些网站提供从 C# 到 VB 的代码转换器,反之亦然,但是在代码转换后修复所有缺陷几乎和我自己做一样耗时。
Till now I am using http://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx
到现在我都在使用http://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx
Do you know something better?
你知道更好的吗?
采纳答案by Hallgrim
If you cannot find a good converter, you could always compile the c# code and use the dissasembler in Reflectorto see Visual Basic code. Some of the variable names will change.
如果找不到好的转换器,您可以随时编译 c# 代码并使用Reflector 中的反汇编器查看 Visual Basic 代码。一些变量名称会改变。
回答by Darren Kopp
Telerik has a good converterthat is based on SharpDevelop that has worked pretty well over the years, though it has not been updated in years (due to it being based on SharpDevelop).
Telerik 有一个很好的转换器,它基于 SharpDevelop,多年来一直运行良好,尽管它已经多年没有更新(因为它基于 SharpDevelop)。
I've recently come across a roslyn based converter as well. I don't know how well it works or how well maintained it is, but as it's open source you can always fork it and update it as needed.
我最近也遇到了一个基于 roslyn 的转换器。我不知道它的工作情况或维护情况如何,但由于它是开源的,您始终可以根据需要对其进行分叉和更新。
回答by GEOCHET
Last I checked, SharpDevelophas one and it is open source too.
最后我查了一下,SharpDevelop有一个,它也是开源的。
回答by Ricardo Amores
SharpDevelophas a built-in translator between C# and VB.NET. Is not perfect thought (e.g. the optional values in VB.NET doesn't have an equivalent in C#, so the signature of the converter method must be edited), but you can save some time, as you are making all operations inside an IDE and not a webpage (copy C# code, paste, hit button, copy VB.NET code, paste on IDE :P )
SharpDevelop具有 C# 和 VB.NET 之间的内置转换器。不是完美的想法(例如,VB.NET 中的可选值在 C# 中没有等效项,因此必须编辑转换器方法的签名),但是您可以节省一些时间,因为您在 IDE 中进行所有操作而不是网页(复制 C# 代码、粘贴、点击按钮、复制 VB.NET 代码、粘贴到 IDE 上:P)
回答by MotoWilliams
Carlos Aguilar Mares has had an online converter for about 40 forevers - Code Translatorbut I would agree that Reflector is the better answer.
Carlos Aguilar Mares 有一个在线转换器大约 40 年了 - Code Translator但我同意 Reflector 是更好的答案。
回答by CJM
While not answering your question, I will say that I have been in a similar position.
虽然不回答你的问题,但我会说我一直处于类似的位置。
I realised that code samples in C# were awkward when I was really starting out in .NET, but a few weeks into my first project (after I grown more familiar with the .NET framework and VB.NET itself), I found that it was interesting and sometimes beneficial to have to reverse-engineer the C# code. Not just in terms of syntax, but also learning about the subtle differences in approach - it's useful to be open-minded in this respect.
当我真正开始使用 .NET 时,我意识到 C# 中的代码示例很笨拙,但是在我的第一个项目几周后(在我更加熟悉 .NET 框架和 VB.NET 本身之后),我发现它是对 C# 代码进行逆向工程很有趣,有时也很有好处。不仅在语法方面,而且还学习方法上的细微差别 - 在这方面保持开放的态度很有用。
I'm sticking with VB.NET as I learn more and more about the framework, but before long I'll dip my to into C# with the intention of becoming 'multi-lingual'.
随着我对框架的了解越来越多,我一直坚持使用 VB.NET,但不久之后我将涉足 C#,以期成为“多语言”。
回答by Davide
Currently I use a plugin for VS2005 that I found on CodeProject (http://www.codeproject.com/KB/cs/Code_convert_add-in.aspx); it use an external service (http://www.carlosag.net/Tools/CodeTranslator/) to perform translation.
目前,我使用了在 CodeProject ( http://www.codeproject.com/KB/cs/Code_convert_add-in.aspx)上找到的 VS2005 插件;它使用外部服务 ( http://www.carlosag.net/Tools/CodeTranslator/) 来执行翻译。
Occasionally, when I'm offline, I use a converter tool (http://www.kamalpatel.net/ConvertCSharp2VB.aspx).
有时,当我离线时,我会使用转换器工具 ( http://www.kamalpatel.net/ConvertCSharp2VB.aspx)。
回答by Davide
I think the best thing to do is learn enough of the other language so that you can rewrite by hand, there's some quite difficult differences in certain aspects that I'm not sure a converter would handle very well. For example, compare my translation from C# to VB of the following:
我认为最好的办法是学习足够的其他语言,以便您可以手动重写,在某些方面存在一些非常困难的差异,我不确定转换器是否会处理得很好。例如,比较我从 C# 到 VB 的以下翻译:
public class FileSystemEventSubscription : EventSubscription
{
private FileSystemWatcher fileSystemWatcher;
public FileSystemEventSubscription(IComparable queueName,
Guid workflowInstanceId, FileSystemWatcher fileSystemWatcher) : base(queueName, workflowInstanceId)
{
this.fileSystemWatcher = fileSystemWatcher;
}
becomes
变成
Public Class FileSystemEventSubscription
Inherits EventSubscription
Private myFileSystemWatcher As FileSystemWatcher
Public Sub New(ByVal QueueName As IComparable, ByVal WorkflowInstanceID As Guid, ByVal Watcher As FileSystemWatcher)
MyBase.New(QueueName, WorkflowInstanceID)
Me.myFileSystemWatcher = Watcher
End Sub
The C# is from the Custom Activity Framework sample, and I'm afraid I've lost the link to it. But it contains some nasty looking inheritance (from a VB point of view).
C# 来自自定义活动框架示例,恐怕我已经失去了它的链接。但它包含一些看起来很讨厌的继承(从 VB 的角度来看)。
回答by Davide
The one at http://www.developerfusion.com/tools/convert/csharp-to-vb/(new url) now supports .NET 3.5 syntax (thanks to the #develop guys once again), and will automatically copy the results to your clipboard :)
在一个http://www.developerfusion.com/tools/convert/csharp-to-vb/(新URL)现在支持.NET 3.5语法(感谢#develop家伙再一次),并将结果自动复制到您的剪贴板:)
回答by Germstorm
You can load your DLL or EXE into Redgate's (formerly Lutz Roeder's) .Net Reflector, select your method and then the desired language from the language combo. The code of the selected method will be displayed in the selected language.
您可以将 DLL 或 EXE 加载到 Redgate(以前称为 Lutz Roeder)的.Net Reflector 中,选择您的方法,然后从语言组合中选择所需的语言。所选方法的代码将以所选语言显示。
I hope this helps.
我希望这有帮助。