Are there any 'good' resources for porting a VB.NET winforms application to C#? I'm sure there are is software that just translates the code, but I'm looking to refactor the code at the same time. Keeping it in its current form is problematic, since it uses some of the 'bad design' practices that VB.NET allows, and would further complicate future maintanence. Has anyone here gone through that process, and how did you go about doing it? Did you use a translate/refactor approach? Did you just use the end product to recreate functionality without looking at the current codebase for most of it? What would you (collectively) recommend?
将VB.NET winforms应用程序移植到C#有什么“好”的资源吗?我确信有软件只是翻译代码,但我希望同时重构代码。保持它当前的形式是有问题的,因为它使用了VB.NET允许的一些“糟糕的设计”实践,并且会进一步使未来的维护变得复杂。这里有没有人经历过这个过程,你是怎么做的?你使用翻译/重构方法了吗?您是否只是使用最终产品来重新创建功能而不查看大部分当前的代码库?你(集体)推荐什么?
Update:
As I was telling Grauenwolf, keeping it in its current language presents the following issues:
正如我告诉Grauenwolf一样,用当前语言保留它会出现以下问题:
- Not being able to readily add features. VB.NET isn't a language I'm rock solid in. I do appreciate the irony of learning the language to port it over -- but future maintenance will need to account for someone who doesn't know VB.NET.
- The rest of the application has been ported to C# (a long time ago, in fact); all features that we'd like to add depend on de-coupling the app (right now it's very tightly coupled). My choices are to either refactor it in a language I'm not too familiar with, or to refactor it in a language I understand.
无法轻松添加功能。 VB.NET不是一种我坚如磐石的语言。我很欣赏学习语言的讽刺意味 - 但是未来的维护将需要考虑那些不了解VB.NET的人。
应用程序的其余部分已移植到C#(事实上很久以前);我们想要添加的所有功能都取决于解耦应用程序(现在它非常紧密耦合)。我的选择是用一种我不太熟悉的语言重构它,或用我理解的语言重构它。
To anyone who voted the question down, I'm not really sure why you did; the concern isn't whether I should leave it in VB.NET; the concern is what is the future cost of not porting it over now. If I'm going to spare great expense in fixing it, why not go the extra step and make it maintainable for a future programmer?
对于投票问题的任何人,我都不确定你为什么这样做;关注的不是我是否应该将其留在VB.NET中;关注的是现在没有移植它的未来成本是多少。如果我要花费大量精力修复它,为什么不采取额外的步骤并使其可以为未来的程序员维护?
Author's Note: I hadn't looked at this question in ages, there was a recent response, so I moved my 'answer' into the question and deleted the 'answer' (since it wasn't really an answer).
作者注:我多年没有看过这个问题,最近有一个回复,所以我把'回答'移到了问题中并删除了'回答'(因为它不是真的答案)。
7 个解决方案
#1
16
Based on my experience working with some large applications that mix VB and C# projects, I would recommend leaving it in VB.NET. If there are problems with the design, then fix them, but converting the whole thing to C# sounds like a messy, unnecessary distraction to me.
根据我使用混合VB和C#项目的大型应用程序的经验,我建议将其保留在VB.NET中。如果设计有问题,那么修复它们,但将整个事物转换为C#听起来像是一个混乱,不必要的分心。
The non-stylistic differences between the two languages are very minimal, so it is hard to see a functional need that would force a conversion. (There was an old bug in Visual Studio 2003 that ruled out certain chains of project references that mixed C# and VB projects in specific ways, but that is the only one I have ever run into as a practical obstacle.)
两种语言之间的非风格差异非常小,因此很难看到强制转换的功能需求。 (Visual Studio 2003中有一个旧的错误,它排除了某些项目引用链,它们以特定的方式混合了C#和VB项目,但这是我遇到的唯一一个实际障碍。)
Individual developers certainly tend to have a stylistic preference favoring one or the other, but a full conversion is a lot of work to do for something that amounts to a taste for a different flavor of syntactic sugar.
个别开发者肯定倾向于偏爱一种或另一种风格偏好,但完全转换是为了尝试不同风格的语法糖而做很多工作。
#2
6
If you use something like Reflector or Anakrino, its output is based on the IL rather than the original source. Whether or not it produces code that's any better is open for debate... But you could try it out, anyway. :)
如果你使用像Reflector或Anakrino这样的东西,它的输出是基于IL而不是原始来源。无论它是否产生更好的代码都可以争论......但无论如何你可以尝试一下。 :)
#3
3
Keeping it in its current form is problematic, since it uses some of the 'bad design' practices that VB.NET allows, and would further complicate future maintanence.
保持它当前的形式是有问题的,因为它使用了VB.NET允许的一些“糟糕的设计”实践,并且会进一步使未来的维护变得复杂。
And you think C# won't allow for bad designs?
你认为C#不会允许糟糕的设计?
The problem isn't VB, the problem is the guy who wrote it and the guy refusing to fix it. So take a step back, breath deeply, then start fixing the code. And who knows, you may learn that some of those 'bad design practices' actually make a lot of sense.
问题不是VB,问题是编写它的人和那个拒绝修复它的人。所以退后一步,深呼吸,然后开始修复代码。谁知道,你可能会发现其中一些“糟糕的设计实践”确实很有意义。
#4
2
In my job we've used the translator of developerfusion, but nothing automated (just translate the piece of code or the class, and manually paste the result in the c# project).
在我的工作中,我们使用了developerfusion的翻译器,但没有自动化(只需翻译一段代码或类,然后手动将结果粘贴到c#项目中)。
Reflector is a great tool, but you can find some problems when reading lambda functions.
Reflector是一个很棒的工具,但是在阅读lambda函数时你会发现一些问题。
For refactoring, the best tool we've tried is Refactor Pro.
对于重构,我们尝试过的最好的工具是Refactor Pro。
#5
1
I've used C-Sharpener to do the conversion on some of our apps, but it is far from perfect. It converted roughly 95% of the code, and I ended up refactoring while I was manually fixing the remaining 5%.
我已经使用C-Sharpener对我们的一些应用程序进行转换,但它远非完美。它转换了大约95%的代码,当我手动修复剩余的5%时,我最终重构了。
#6
1
I have some experiences on VB.NET about 2 years, but now I only use C# in my daily development. Before I tried to use VB.Net to C# to convert my VB.NET code to C#, then I learned from it and also from the book.
我有两年的VB.NET经验,但现在我只在日常开发中使用C#。在我尝试使用VB.Net到C#将我的VB.NET代码转换为C#之前,我从它和本书中学到了东西。
#7
0
Oo Wow ! I am the last person to catch the stuff. I have a very big VB.NET code in WinForms and have been assigned to port it to C# and WinForms. I have 0 knowledge of VB but had to get the task done. I used Telerik Online Code Converter to convert all the VB business logic into C#. The Converter is a foolish one and I was presented with around 5000 erros mostly confusing the [] with () , issues with ref parameters and Threading as well as what not. The compiler (VS 2013) was not even able to figure out all errors in a single build . I had to spent 2 months in fixing those errors and building the project again and again. I copied the WinForms UI to the C# Winforms UI - That was not much of a problem and now I have been debugging both the code simultaneously to see the output.
哇哇!我是最后一个抓住这些东西的人。我在WinForms中有一个非常大的VB.NET代码,并已被分配将其移植到C#和WinForms。我对VB有0知识,但必须完成任务。我使用Telerik在线代码转换器将所有VB业务逻辑转换为C#。转换器是一个愚蠢的转换器,我遇到了大约5000个错误,主要是混淆了[]和(),引用参数和线程的问题,以及什么不是。编译器(VS 2013)甚至无法找出单个构建中的所有错误。我不得不花了两个月的时间来修复这些错误并一次又一次地构建项目。我将WinForms UI复制到C#Winforms UI - 这不是什么大问题,现在我一直在调试这两个代码以查看输出。
I would like to tell that its 4 months now and still I am completing the project. My experience with the coversion has been very bitter and wouldn't like to recommend anyone.
我想告诉它现在已经4个月了,我仍在完成这个项目。我对这次转变的经历非常痛苦,不愿意推荐任何人。
#1
16
Based on my experience working with some large applications that mix VB and C# projects, I would recommend leaving it in VB.NET. If there are problems with the design, then fix them, but converting the whole thing to C# sounds like a messy, unnecessary distraction to me.
根据我使用混合VB和C#项目的大型应用程序的经验,我建议将其保留在VB.NET中。如果设计有问题,那么修复它们,但将整个事物转换为C#听起来像是一个混乱,不必要的分心。
The non-stylistic differences between the two languages are very minimal, so it is hard to see a functional need that would force a conversion. (There was an old bug in Visual Studio 2003 that ruled out certain chains of project references that mixed C# and VB projects in specific ways, but that is the only one I have ever run into as a practical obstacle.)
两种语言之间的非风格差异非常小,因此很难看到强制转换的功能需求。 (Visual Studio 2003中有一个旧的错误,它排除了某些项目引用链,它们以特定的方式混合了C#和VB项目,但这是我遇到的唯一一个实际障碍。)
Individual developers certainly tend to have a stylistic preference favoring one or the other, but a full conversion is a lot of work to do for something that amounts to a taste for a different flavor of syntactic sugar.
个别开发者肯定倾向于偏爱一种或另一种风格偏好,但完全转换是为了尝试不同风格的语法糖而做很多工作。
#2
6
If you use something like Reflector or Anakrino, its output is based on the IL rather than the original source. Whether or not it produces code that's any better is open for debate... But you could try it out, anyway. :)
如果你使用像Reflector或Anakrino这样的东西,它的输出是基于IL而不是原始来源。无论它是否产生更好的代码都可以争论......但无论如何你可以尝试一下。 :)
#3
3
Keeping it in its current form is problematic, since it uses some of the 'bad design' practices that VB.NET allows, and would further complicate future maintanence.
保持它当前的形式是有问题的,因为它使用了VB.NET允许的一些“糟糕的设计”实践,并且会进一步使未来的维护变得复杂。
And you think C# won't allow for bad designs?
你认为C#不会允许糟糕的设计?
The problem isn't VB, the problem is the guy who wrote it and the guy refusing to fix it. So take a step back, breath deeply, then start fixing the code. And who knows, you may learn that some of those 'bad design practices' actually make a lot of sense.
问题不是VB,问题是编写它的人和那个拒绝修复它的人。所以退后一步,深呼吸,然后开始修复代码。谁知道,你可能会发现其中一些“糟糕的设计实践”确实很有意义。
#4
2
In my job we've used the translator of developerfusion, but nothing automated (just translate the piece of code or the class, and manually paste the result in the c# project).
在我的工作中,我们使用了developerfusion的翻译器,但没有自动化(只需翻译一段代码或类,然后手动将结果粘贴到c#项目中)。
Reflector is a great tool, but you can find some problems when reading lambda functions.
Reflector是一个很棒的工具,但是在阅读lambda函数时你会发现一些问题。
For refactoring, the best tool we've tried is Refactor Pro.
对于重构,我们尝试过的最好的工具是Refactor Pro。
#5
1
I've used C-Sharpener to do the conversion on some of our apps, but it is far from perfect. It converted roughly 95% of the code, and I ended up refactoring while I was manually fixing the remaining 5%.
我已经使用C-Sharpener对我们的一些应用程序进行转换,但它远非完美。它转换了大约95%的代码,当我手动修复剩余的5%时,我最终重构了。
#6
1
I have some experiences on VB.NET about 2 years, but now I only use C# in my daily development. Before I tried to use VB.Net to C# to convert my VB.NET code to C#, then I learned from it and also from the book.
我有两年的VB.NET经验,但现在我只在日常开发中使用C#。在我尝试使用VB.Net到C#将我的VB.NET代码转换为C#之前,我从它和本书中学到了东西。
#7
0
Oo Wow ! I am the last person to catch the stuff. I have a very big VB.NET code in WinForms and have been assigned to port it to C# and WinForms. I have 0 knowledge of VB but had to get the task done. I used Telerik Online Code Converter to convert all the VB business logic into C#. The Converter is a foolish one and I was presented with around 5000 erros mostly confusing the [] with () , issues with ref parameters and Threading as well as what not. The compiler (VS 2013) was not even able to figure out all errors in a single build . I had to spent 2 months in fixing those errors and building the project again and again. I copied the WinForms UI to the C# Winforms UI - That was not much of a problem and now I have been debugging both the code simultaneously to see the output.
哇哇!我是最后一个抓住这些东西的人。我在WinForms中有一个非常大的VB.NET代码,并已被分配将其移植到C#和WinForms。我对VB有0知识,但必须完成任务。我使用Telerik在线代码转换器将所有VB业务逻辑转换为C#。转换器是一个愚蠢的转换器,我遇到了大约5000个错误,主要是混淆了[]和(),引用参数和线程的问题,以及什么不是。编译器(VS 2013)甚至无法找出单个构建中的所有错误。我不得不花了两个月的时间来修复这些错误并一次又一次地构建项目。我将WinForms UI复制到C#Winforms UI - 这不是什么大问题,现在我一直在调试这两个代码以查看输出。
I would like to tell that its 4 months now and still I am completing the project. My experience with the coversion has been very bitter and wouldn't like to recommend anyone.
我想告诉它现在已经4个月了,我仍在完成这个项目。我对这次转变的经历非常痛苦,不愿意推荐任何人。