public static void PerformVBToCSConversion(IServiceProvider serviceProvider, string inputCode) { string convertedText = null; try { var result = TryConvertingVBToCSCode(inputCode); if (!result.Success) { var newLines = Environment.NewLine + Environment.NewLine; VsShellUtilities.ShowMessageBox( serviceProvider, $"Selected VB code seems to have errors or to be incomplete:{newLines}{result.GetExceptionsAsString()}", VBToCSConversionTitle, OLEMSGICON.OLEMSGICON_WARNING, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); return; } convertedText = result.ConvertedCode; } catch (Exception ex) { VisualStudioInteraction.ShowException(serviceProvider, VBToCSConversionTitle, ex); return; } // Direct output for debugging //string message = convertedText; //VsShellUtilities.ShowMessageBox( // serviceProvider, // message, // VBToCSConversionTitle, // OLEMSGICON.OLEMSGICON_INFO, // OLEMSGBUTTON.OLEMSGBUTTON_OK, // OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); WriteStatusBarText(serviceProvider, "Copied converted C# code to clipboard."); Clipboard.SetText(convertedText); }
async void ProjectItemMenuItemCallback(object sender, EventArgs e) { string itemPath = VisualStudioInteraction.GetSingleSelectedItemPath(); var fileInfo = new FileInfo(itemPath); if (!CodeConversion.IsVBFileName(fileInfo.Name)) { return; } try { using (StreamReader reader = new StreamReader(itemPath)) { string csCode = await reader.ReadToEndAsync(); CodeConversion.PerformVBToCSConversion(ServiceProvider, csCode); } } catch (Exception ex) { VisualStudioInteraction.ShowException(ServiceProvider, CodeConversion.VBToCSConversionTitle, ex); } }
public static void PerformCSToVBConversion(IServiceProvider serviceProvider, string inputCode) { string convertedText = null; try { if (!TryConvertingCSToVBCode(inputCode, out convertedText)) { VsShellUtilities.ShowMessageBox( serviceProvider, "Selected C# code seems to have errors or to be incomplete.", CSToVBConversionTitle, OLEMSGICON.OLEMSGICON_WARNING, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); return; } } catch (Exception ex) { VisualStudioInteraction.ShowException(serviceProvider, CSToVBConversionTitle, ex); return; } // Direct output for debugging //string message = convertedText; //VsShellUtilities.ShowMessageBox( // serviceProvider, // message, // CSToVBConversionTitle, // OLEMSGICON.OLEMSGICON_INFO, // OLEMSGBUTTON.OLEMSGBUTTON_OK, // OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); WriteStatusBarText(serviceProvider, "Copied converted VB code to clipboard."); Clipboard.SetText(convertedText); }