Exemple #1
0
        void ProjectItemMenuItem_BeforeQueryStatus(object sender, EventArgs e)
        {
            var menuItem = sender as OleMenuCommand;

            if (menuItem != null)
            {
                menuItem.Visible = false;
                menuItem.Enabled = false;

                string itemPath = VisualStudioInteraction.GetSingleSelectedItemPath();
                var    fileInfo = new FileInfo(itemPath);
                if (!CodeConversion.IsCSFileName(fileInfo.Name))
                {
                    return;
                }

                menuItem.Visible = true;
                menuItem.Enabled = true;
            }
        }
        async void ProjectItemMenuItemCallback(object sender, EventArgs e)
        {
            string itemPath = VisualStudioInteraction.GetSingleSelectedItemPath();
            var    fileInfo = new FileInfo(itemPath);

            if (!CodeConversion.IsCSFileName(fileInfo.Name))
            {
                return;
            }

            try {
                using (StreamReader reader = new StreamReader(itemPath)) {
                    string csCode = await reader.ReadToEndAsync();

                    CodeConversion.PerformCSToVBConversion(ServiceProvider, csCode);
                }
            } catch (Exception ex) {
                VisualStudioInteraction.ShowException(ServiceProvider, CodeConversion.CSToVBConversionTitle, ex);
            }
        }