using System.IO; using System.Linq; using EnvDTE; using Microsoft.VisualStudio.Shell; namespace ICSharpCode.ILSpy.AddIn.Commands { /// /// Represents a project item in Solution Explorer, which can be opened in ILSpy. /// class ProjectItemForILSpy { SelectedItem item; Project project; Microsoft.CodeAnalysis.Project roslynProject; ProjectItemForILSpy(Project project, Microsoft.CodeAnalysis.Project roslynProject, SelectedItem item) { this.project = project; this.roslynProject = roslynProject; this.item = item; } /// /// Detects whether the given represents a supported project. /// /// Selected item to check. /// instance or null, if item is not a supported project. public static ProjectItemForILSpy Detect(ILSpyAddInPackage package, SelectedItem item) { ThreadHelper.ThrowIfNotOnUIThread(); var project = item.Project; var roslynProject = package.Workspace.CurrentSolution.Projects.FirstOrDefault(p => p.FilePath == project.FileName); if (roslynProject == null) return null; return new ProjectItemForILSpy(project, roslynProject, item); } /// /// If possible retrieves parameters to use for launching ILSpy instance. /// /// Package instance. /// Parameters object or null, if not applicable. public ILSpyParameters GetILSpyParameters(ILSpyAddInPackage package) { ThreadHelper.ThrowIfNotOnUIThread(); return new ILSpyParameters(new[] { Utils.GetProjectOutputAssembly(project, roslynProject) }); } } }