Hi I want to convert the code at Webcam using DirectShow.NET to C#. It works perfectly in vb.net. I tried converting using an online converter, however I got about 30 errors,
Any suggestions to what I must do next:
This is the converter that I used :
1) Convert VB.NET to C#
The CodeProject article says the author originally converted this sample from C# to VB.NET. This may be the original C# source:
Link
Who says you even have to convert it? You could throw it in a Class Library and use the DLL in your C# project. No need for translating perfectly working .Net code into other .Net code.
Without the errors and relavent source code, we can't really help. The best bet is to use an online converter (as you did) and fix compiler errors, then test for other errors.
I've used sharpdevelop to translate between vb and c# a few times for projects. It's really pretty great, only had to make minor changes.
http://www.sharpdevelop.net
Use RedGate's reflector against the compiled assembly and the Denis Bauer's disassembler to get back code in the language of your choice.
I'd echo the npinti's suggestion; but I've never found a converter that will do everything flawlessly.
My guess is that you'll find several that do a good/great job; but you're still going to have to do a little work to get everything to play nice.
Learn C#, then convert it.
Maybe C-Sharpener For VB will work
Here is your golden ticket!!! ;) When i found this tool (which does a perfect conversion 99% of the time, it really make s a VB developers life easier and opens up all the online snippets and samples exclusively in C now available for a VB'er... Which BTW- is so overlooked on it's strengths at this point, it's just, well, crazy! ;)
Here is that 'gem' i am referring to: http://converter.telerik.com/
Hope that helps!!!
Related
I am currently working on wrapping a big C++ library to C# using SWIG. I am facing a big problem, since my library use a big amount of std::list, and it seems that SWIG (I am using the last release 3.0.12) doesn't supply a default mapping for std::list. I looked all over the web, nothing found.. I am quite surprised because std::list are quite similar to C# LinkedList !
Anyway, I am not in SWIG for a long time, so I don't really know how to do.. All I know is that I absolutely can't change all the std::list in my lib, and I'd really like to wrap them in C# LinkedList, but I don't know if it's possible and if I can do it easily..
I looked over typemaps, but I'm not sure it would worked correctly because mapping std::list to a LinkedList seems more complicated than using simple typemaps..
People, I need you to advise me !
Thanks in advance,
Quentin.
Well, for those who are facing the same issue like I was, I finally decided to make my own implementation of std::list to C# LinkedList.
I made a pull request on the SWIG GitHub today. If someone is interested, go check it. It is not perfect but work for now.
I am currently writing some code and I am wondering if it would be possible to execute some C# code from my application. I'll give you an idea, lets say I want to give the user a textbox and have them type some code and hit go, I want them to ask for a list of fruit and then go through each fruit and output it.. an example:
var fruitList = getFruit();
foreach(var fruit in fruitList)
{
print(fruit.Name);
}
I would like to be able to go through this and assign a list of Fruit objects to fruitList, the parser should be able to tie up getFruit() to a method I've written in the c# code. The same goes for print, it should equate this to a print function I've written that outputs it to a textbox.
Now I know that C# isn't a script, it is compiled, and I've done a lot of Googling but can't really find anything. My only option to me appears to be to write a little language parser myself - which sounds fun - but I've done this before and I know it's hard work. So this is just a preliminary check to see if some solution does exist before I commit to the long haul.
So, my fellow programmers, do you know of anything that may be able to assist me?
If not, no problem, I appreciate all feedback whether it's tips, advice, links to articles such as this http://blogs.msdn.com/b/ericwhite/archive/2010/06/29/writing-a-recursive-descent-parser-using-c-and-linq.aspx or a solution.
Regards,
Adam
EDIT: I have managed to get a working example. Note this code is a bit messy as I've pasted some other code in to the test app, but it works. Basically, I compile the code into a DLL, then I load the DLL, find the type, find the method, and invoke it. It's pretty damn quick too! I don't want to spam you so the full code is below:
http://imdsm.blogspot.com/2012/01/compile-c-into-assembly-then-load-it.html
Thank you to everyone who posted here. You just saved me days of confusion!
You mean like in this screenshot here?
We use this in our software, HeuristicLab, you can add a ProgrammableOperator into an operator graph which will execute the code that you typed in at the place that you typed it in a custom-built algorithm.
In the System.CodeDom namespace you've got all you need to dynamically compile code. You can create an assembly from the compilation, get the assembly's types and execute their code.
I think the new compiler project of microsoft is what you are looking for. With it you can run C# as were a script indeed.
Project "Roslyn"
Have a look if Roslyn can help , it's still in CTP status.
You can use the CSharpCodeProvider
Or you could use a scripting language and run the interpreter in your application
Ex IronRuby
I may be starting a new job which requires VB.NET but I am a C# developer and even though I may be able to understand the code, writing it from scratch seems to be a hassle for me for a while.
There are C#>VB.NET converter out there (online) and where you paste your C# code and it converts it into VB.NET code. My question is whether there is any person who experienced this and whether it is a good temp solution or I am gonna experience so much difficulties with that? Do they convert good?
And probably I am gonna run the codes on Asp.net.
An example converter: http://www.developerfusion.com/tools/convert/csharp-to-vb/
Thanks in advance.
Don't use converters - learn VB.NET and the differences between its syntax and C#.
There is a very good comparison cheat sheet here to get you started.
In practice, you will find that most of the time you are interacting with familiar .NET objects in the same way and you only have some syntax differences (though generics and delegate syntax are such a pain that one tends to shy away from them).
Microsoft has stated that they are trying to bring both language to feature parity, so anything you can do in C#, you should be able to do with VB.NET (with minor differences normally).
Update - don't forget that compiled code (in assemblies) should work identically in both languages (assuming CLS compliance), so you could write a library in C# for use with VB.NET and vice versa.
You can try the Telerik Code Converter
That being said, it would be a valuable exercise to convert the code manually. You'll gain a good amount of experience by doing a manual conversion and you'll learn some of the key differences between the 2 languages that may help you going forward.
I'd say your code will work, but you'll miss some special features for which there is no C# equivalent and which would make your code fit better with the language. Some examples:
In C#, you assign event handlers with +=, which will be translated to AddHandler. In VB, however, it's much more common to use WithEvents instance variables. This is especially relevant for ASP.NET, where C# often uses the AutoEventWireup feature, which done in VB through WithEvents instead.
In C#, you access XML through LINQ to XML method calls, which will be translated to the matching method calls in VB. However, in VB, it's more natural to use the integrated language support for XML.
This is good for converting the bulk of your code, but it's not a total solution. One thing you will have issues with is the converter knowing what to do with C#'s indexer brackets ([]) vs. method parentheses (()). VB uses parenthesis for indexers and methods and there's no way for it to know which to use.
I've gone through conversion hell with these things and finally decided that they were just too much trouble and that it was much easier to just convert it by hand. I come from a VB background, so this wasn't a huge deal for me.
For what you want to do, though, you need to learn VB.NET syntax. Writing everything in C# and converting it to VB.NET is not a good, long-term solution. You will eventually have to learn VB.NET. Your manager(s) will not be keen to the fact that you're not learning the core fundamentals of the language you were hire to program in.
Don't do it... There are converters, but you will find that once you learn the key differences that you will be fine. You will interact with the .NET libraries in the same way so much of the programming will be the same.
I just changed jobs recently and went the opposite direction. I'm glad I took the time to learn C#. Major dividends in the end and you'll be more versatile.
I need to write a translator for vbscript to c#. What would be the basic steps invloved to translate using ANTLR? I am not very clear about whether to use grammar (lexer/parser? file or stringtemplate or AST or all.
Suggestions?
Thanks in advance.
Is this really possible?
I'm "translating" (read: rewriting) a MS Access/VBA application since two years to C# and found out that even the online available converters (like this one which is more VB.NET, but anyway) fails at most basic conversions.
So my assumption until now is that there are way too much kind of constructs that are simply not translatable from VBScript to C#.
See What kinds of patterns could I enforce on the code to make it easier to translate to another programming language?
The easiest way to translate VBScript to C# would be using VB.NET as an intermediate step. VBScript is very similar to VB.NET (there are some differences though), so all you need to do is copy-paste your code in a new solution in Visual Studio. After you make a few changes, the code will be able to compile.
You can leave it at that (you can call the resulting DLL from your C# code), but even if you don't want to do that, converting VB.NET to C# is trivial. You can even decompile your resulting DLL/EXE (although this will lead to some loss of information) or use any online VB.NET to C# converter.
Is there a tool to convert a VB.NET 2005 project to a C# 2008 project. I am trying to convert our project to VS 2008 and mostly port all the vb.NET code in some projects to C# 3.0/3.5.
I had a similar decision to make with a VB.net project.
Solution was a compromise, I decided to run with dual VB and C#.
Upgrading VB.NET 2005 to 2008 is easy bit.
Added CSharp and VB folders to App_Code and
<codeSubDirectories>
<add directoryName="CSharp" />
<add directoryName="VB" />
</codeSubDirectories>
to compilation section of web.config
As Kev says, it's not as straight forward as you might expect, and you will likely run into unexpected issues , that make running with dual language support the best solution
I know this doesn't directly answer the question, but it's an alternative approach
You could check out SharpDevelop. It's an open source .NET development environment.
SharpDevelop has some code conversion built in.
Take a look at this.
http://www.developerfusion.com/tools/convert/vb-to-csharp/
Try to google term "convert vb.net project to c# project", you will find a couple of options there.
There's a tool on CodeProject called GBVB (Goodbye VB) that purports to 'flawlessly' convert VB.NET code to C# code. However the author does add a number of caveats such as the problems with ambiguous code, optional parameters etc.
Another approach could be to use Denis Bauer's Reflector.FileDisassembler .NET Reflector add-in and disassemble the compiled assemblies back to C#.
Handling .aspx/.asmx pages and their code-behind files would probably be a special case because you'd need to manually change the <%# Page Codebehind="Default.aspx.cs" %> directives to point to the correct source files.
Automatic VB.NET to C# conversion isn't really as straight forward as it initially appears to be. I've been here before and gave up on a fairly large project, there's a lot of fiddling about with specific edge cases where the translation either wouldn't compile or produced unexpected behaviour at runtime. I elected to go for a dual language solution where all new code was written in C# and older VB.NET code was ported gradually over time.
hi this code answer not
public student ()
{}
private string code;
private string name;
public string code()
{
set (code=Value);
Get return code;
}
Telerik has a converter you might want to take a look at.
Since others have mentioned online conversion tools I've found www.carlosag.net to work the best for my code. Maybe b/c I work other 3rd party API's but it seems like a lot of the other online converter just error out if they hit a line they can't convert.
SharpDevelop is quite good, but at my company we've found VBConversions to provide a much more complete conversion. It's a commerical app though, but for the time saved over SharpDevelop it was a no-brainer for us.
As a specific example, one thing we found that SharpDevelop didn't convert correctly was VB indexes, which use curvy brackets. It seemed unable to distinguish between indexes and method calls so didn't convert the indexes to square brackets. VBConversions converted them fine. This one thing made it worth its purchase for us.
It looks like Tangible Software have a very similarly product to VBConversions, but I don't have any experience with it. Jon Skeet suggested it though, so it must be pretty good.