using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EnvDTE;
namespace ICSharpCode.ILSpy.AddIn.Commands
{
///
/// Represents a project item in Solution Explorer, which can be opened in ILSpy.
///
class ProjectItemForILSpy
{
SelectedItem item;
ProjectItemForILSpy(SelectedItem item)
{
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(SelectedItem item)
{
return new ProjectItemForILSpy(item);
}
///
/// If possible retrieves parameters to use for launching ILSpy instance.
///
/// Package instance.
/// Parameters object or null, if not applicable.
public ILSpyParameters GetILSpyParameters(ILSpyAddInPackage owner)
{
var project = item.Project;
var roslynProject = owner.Workspace.CurrentSolution.Projects.FirstOrDefault(p => p.FilePath == project.FileName);
string outputFileName = Path.GetFileName(roslynProject.OutputFilePath);
// Get the directory path based on the project file.
string projectPath = Path.GetDirectoryName(project.FullName);
// Get the output path based on the active configuration
string projectOutputPath = project.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath").Value.ToString();
// Combine the project path and output path to get the bin path
return new ILSpyParameters(new[] { Path.Combine(projectPath, projectOutputPath, outputFileName) });
}
}
}