-
Notifications
You must be signed in to change notification settings - Fork 235
Expand file tree
/
Copy pathConvertVBToCSExtensibilityCommand.cs
More file actions
45 lines (37 loc) · 1.86 KB
/
ConvertVBToCSExtensibilityCommand.cs
File metadata and controls
45 lines (37 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.Extensibility;
using Microsoft.VisualStudio.Extensibility.Commands;
namespace ICSharpCode.CodeConverter.VsExtension;
[VisualStudioContribution]
public class ConvertVBToCSExtensibilityCommand : Command
{
private readonly CodeConverterPackage _package;
public ConvertVBToCSExtensibilityCommand(CodeConverterPackage package)
{
_package = package;
}
public override CommandConfiguration CommandConfiguration => new("%a3378a21-e939-40c9-9e4b-eb0cec7b7854%");
public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken)
{
var codeConversion = CodeConverterPackage.CodeConversionInstance;
var serviceProvider = CodeConverterPackage.Instance;
if (codeConversion == null || serviceProvider == null) return;
var itemsPath = await VisualStudioInteraction.GetSelectedItemsPathAsync(CodeConversion.IsVBFileName);
if (itemsPath.Count > 0)
{
await codeConversion.ConvertDocumentsAsync<ICSharpCode.CodeConverter.CSharp.VBToCSConversion>(itemsPath, cancellationToken);
return;
}
var projects = await VisualStudioInteraction.GetSelectedProjectsAsync(".vbproj");
if (projects.Count > 0)
{
await codeConversion.ConvertProjectsAsync<ICSharpCode.CodeConverter.CSharp.VBToCSConversion>(projects, cancellationToken);
return;
}
(string filePath, var selection) = await VisualStudioInteraction.GetCurrentFilenameAndSelectionAsync(serviceProvider, CodeConversion.IsVBFileName, false);
if (filePath != null && selection != null) {
await codeConversion.ConvertDocumentAsync<ICSharpCode.CodeConverter.CSharp.VBToCSConversion>(filePath, selection.Value, cancellationToken);
}
}
}