One of the (few) concerns we hear from people looking to get started with Delphi Prism is that most of the code samples and snippets that are available on the net are written in C#.
Because .NET is fully language agnostic, reusing existing libraries and assemblies written in C# (or any other language) generally is no problem, but for smaller pieces of code – classes or even just small code snippets – it is inconvenient for the Prism developer to start a separate C# project – making manual translation (and sometimes, deeper understanding of the C# language and its intricacies) necessary.
We wanted to make this easier, so for the upcoming February* release of Delphi Prism, we’ve added two new features to the IDE, based on out open source C# to Oxygene tool.
The first is the new Paste C# as Oxygene command in the source editor. If you find snippets of C# code on the web (or elsewhere) that you want to reuse in your project, simply copy them to the clipboard, and then right-click into your code and choose Paste C# as Oxygene from the context menu:
All of this is great when you have code snippets, especially from websites, forums or newsgroups. But what about C# files already on disk? That’s where the second feature comes in: if you right-click your Delphi Prism project and go to the Add menu, you’ll see a new Import C# sub-item. Select this, and you’ll be presented with a regular File Open dialog, where you can browse to and select one or more .cs files on your harddisk. When you click Ok, each .cs file will be translated to Oxygene, and a corresponding new .pas file will be added to your project:
One of our test bases is the entire RemObjects SDK for .NET library, and the tool translates that very satisfactory.
Paste C# and Import C# are probably not features you want to use to blindly translate whole projects with and reuse the resuiting code without further testing or review, but in our experience it is working very well or the intended purpose – reuse onf code snippets found online.