The Convert method takes C# code as a string argument and returns Visual Basic code as a string. ReadOnly Property ConverterName() As String The IConvertCode interface is pretty simple: Public Interface IConvertCodeįunction Convert(ByVal csCode As String) As String This describes the conversion operation in general, but will leave the specific implementation to other classes. To abstract the converter implementation from the rest of the code, I crafted the IConvertCode interface. Finally, I wanted it to be easy for the Visual Studio add-in to support additional converters in the future. Also, different code converters use different algorithms, and one may work better or worse for a particular piece of code. Hooking up to more than one conversion service makes it more likely that there will always be a service available to perform the conversion. When you're dealing with Web solutions, there's no guarantee that a particular Web site will remain operational indefinitely, or that it won't change its implementation in a way that breaks your code. There are a number of Web-based code converters available, so I wanted to architect the Paste as Visual Basic add-in so that the user can choose whichever converter he wants to use. All the necessary building blocks are in place to make this work I just need some code to glue it all together. When I find a C# code example on a Web site, I'd really like to eliminate the intermediate conversion steps and just Paste as Visual Basic right into the code editor. Using such code requires copying the sample to the clipboard, going to one of the many great code conversion Web sites, pasting in the code, converting it, copying the new code, and finally pasting the converted code into Visual Studio. It's common to be coding in C# and find a Visual Basic® example that does exactly what you want, or vice versa. However, instead of simply converting the text formatting, it could convert the language of the code example. While perusing the Web one day, looking for a code example, it occurred to me that Paste as would also be beneficial for Visual Studio®. I often copy something from the Web and want to paste it into a document without all of the HTML formatting. The "Paste as." functionality in applications like Microsoft® Word has become indispensable for me. This article uses the following technologies:Ĭode download available at: Paste As.exe(875 KB) A Visual Studio Add-In That Converts C# Code To Visual Basic
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |