A guy came to me there recently with a half done web app that has been created using VB.NET, nothing major, just a normal site. His original programmer couldn't continue so he wants me to finish it. Problem is I don't program using VB.NET nor have I any intention of learning it for a project this small. Usually I would run from something like this but I need the cash. Should I ta开发者_如何学Pythonke the project and continue it using C# or just leave it. Has anyone had a similar experience and how did it turn out.
You can also just bite the bullet and finish it in VB.NET. This way you don't have to worry about the vagaries of conversion or managing a codebase of multiple languages. I know it might not sound palatable but the jump to VB from C# isn't that tough, or even much of a jump.
NOTE: Etymology link added for folks who might not be familiar with the "bite the bullet" idiom.
It can be done, yes. That doesn't mean it will be pretty.
You have two options (as I see it):
Convert the existing code from VB.NET to C# and then complete the application (leaving you with a 100% C# code base).
Migrate the VB.NET logic into a seperate assembly. You can then build that assembly seperate from your C# code and include it as a reference for everything else.
Either way there is probably going to be a good deal of work involved.
If this is a "Web Site", you can use both C# and VB.NET. See Shared Code Folders in ASP.NET Web Sites at http://msdn.microsoft.com/en-us/library/t990ks23(VS.80).aspx. Code-behind can be either language. As you work on the pages, you can migrate any VB.NET code, if needed.
If you can move the VB code into a separate assembly and call the functions in that from C# than fine-I would not suggest you have both languages in the same layer for the same app. You need to also think of the support & maintenance of the app too. If it's done in a mix of both VB and C# in the same layer than maintaining the site either for yourself or for someone else is going to be more complex than normal-and could even cost your client more in the long run through this complexity.
If it isn't precompiled, I think ASP.NET site projects can mix the language they use because they are compiled before use.
http://www.drdobbs.com/web-development/199701178;jsessionid=IFM3WABNVTC0FQE1GHOSKHWATMY32JVN
To be honest, I would use this as an excuse to get a working understanding of VB.NET - its not difficult and is worth doing.
Since you say that it's a small unfinished project I'd just use the free online converters to convert the code from VB.Net to C# automatically. They'll fail sometimes, but most of that will be obvious and either way, you wouldn't trust someone else's half finished code anyway would you? So you'll pretty much have to go through it line by line anyway to see how it works and could then fix any remaining conversion issues.
If you can compile it to it's own dll you could finish the rest in c#. Or run it through some of the converters out there and fix what's needed.
I think this also depends on the .NET framework version you are using as to what approach you can take.
If it is 1.1 I think your stuck with using VB.NET unless you can separate the additional code needed into a new assembly and reference it from existing project.
If it is a later version of .NET I believe you can mix c# and vb.net classes but obviously not mix languages within classes and pages.
To be honest you are probably better off either converting to c# as has been suggested or taking the plunge and using it as an opportunity to get an understanding of the vb.net syntax.
I'd go with the latter.
Well I haven't used any tools of this kind, but there are enough references to code converter tools like the one above. Maybe you could try it out?
You might want to try SharpDevelop's Code Converter. See Offline code converter at http://wiki.sharpdevelop.net/Code%20Converter.ashx.
精彩评论