mirror of https://github.com/icsharpcode/ILSpy.git
12 changed files with 379 additions and 117 deletions
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Threading.Tasks; |
||||
using VSLangProj; |
||||
|
||||
namespace ICSharpCode.ILSpy.AddIn.Commands |
||||
{ |
||||
/// <summary>
|
||||
/// Represents an assembly reference item in Solution Explorer, which can be opened in ILSpy.
|
||||
/// </summary>
|
||||
class AssemblyReferenceForILSpy |
||||
{ |
||||
Reference reference; |
||||
|
||||
AssemblyReferenceForILSpy(Reference reference) |
||||
{ |
||||
this.reference = reference; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Detects whether the given selected item represents a supported project.
|
||||
/// </summary>
|
||||
/// <param name="itemData">Data object of selected item to check.</param>
|
||||
/// <returns><see cref="AssemblyReferenceForILSpy"/> instance or <c>null</c>, if item is not a supported project.</returns>
|
||||
public static AssemblyReferenceForILSpy Detect(object itemData) |
||||
{ |
||||
return (itemData is Reference reference) ? new AssemblyReferenceForILSpy(reference) : null; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// If possible retrieves parameters to use for launching ILSpy instance.
|
||||
/// </summary>
|
||||
/// <param name="projectReferences">List of current project's references.</param>
|
||||
/// <returns>Parameters object or <c>null, if not applicable.</c></returns>
|
||||
public ILSpyParameters GetILSpyParameters(Dictionary<string, string> projectReferences) |
||||
{ |
||||
if (projectReferences.TryGetValue(reference.Name, out var path)) |
||||
return new ILSpyParameters(new[] { path }); |
||||
|
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Threading.Tasks; |
||||
using EnvDTE; |
||||
|
||||
namespace ICSharpCode.ILSpy.AddIn.Commands |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a NuGet package item in Solution Explorer, which can be opened in ILSpy.
|
||||
/// </summary>
|
||||
class NuGetReferenceForILSpy |
||||
{ |
||||
ProjectItem projectItem; |
||||
|
||||
NuGetReferenceForILSpy(ProjectItem projectItem) |
||||
{ |
||||
this.projectItem = projectItem; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Detects whether the given selected item represents a supported project.
|
||||
/// </summary>
|
||||
/// <param name="itemData">Data object of selected item to check.</param>
|
||||
/// <returns><see cref="NuGetReferenceForILSpy"/> instance or <c>null</c>, if item is not a supported project.</returns>
|
||||
public static NuGetReferenceForILSpy Detect(object itemData) |
||||
{ |
||||
if (itemData is ProjectItem projectItem) { |
||||
var properties = Utils.GetProperties(projectItem.Properties, "Type"); |
||||
if ((properties[0] as string) == "Package") { |
||||
return new NuGetReferenceForILSpy(projectItem); |
||||
} |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// If possible retrieves parameters to use for launching ILSpy instance.
|
||||
/// </summary>
|
||||
/// <returns>Parameters object or <c>null, if not applicable.</c></returns>
|
||||
public ILSpyParameters GetILSpyParameters() |
||||
{ |
||||
var properties = Utils.GetProperties(projectItem.Properties, "Name", "Version", "Path"); |
||||
if (properties[0] != null && properties[1] != null && properties[2] != null) { |
||||
return new ILSpyParameters(new[] { $"{properties[2]}\\{properties[0]}.{properties[1]}.nupkg" }); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,54 @@
@@ -0,0 +1,54 @@
|
||||
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 |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a project item in Solution Explorer, which can be opened in ILSpy.
|
||||
/// </summary>
|
||||
class ProjectItemForILSpy |
||||
{ |
||||
SelectedItem item; |
||||
|
||||
ProjectItemForILSpy(SelectedItem item) |
||||
{ |
||||
this.item = item; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Detects whether the given <see cref="SelectedItem"/> represents a supported project.
|
||||
/// </summary>
|
||||
/// <param name="item">Selected item to check.</param>
|
||||
/// <returns><see cref="ProjectItemForILSpy"/> instance or <c>null</c>, if item is not a supported project.</returns>
|
||||
public static ProjectItemForILSpy Detect(SelectedItem item) |
||||
{ |
||||
return new ProjectItemForILSpy(item); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// If possible retrieves parameters to use for launching ILSpy instance.
|
||||
/// </summary>
|
||||
/// <param name="owner">Package instance.</param>
|
||||
/// <returns>Parameters object or <c>null, if not applicable.</c></returns>
|
||||
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) }); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,78 @@
@@ -0,0 +1,78 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Threading.Tasks; |
||||
using EnvDTE; |
||||
using Mono.Cecil; |
||||
|
||||
namespace ICSharpCode.ILSpy.AddIn.Commands |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a project reference item in Solution Explorer, which can be opened in ILSpy.
|
||||
/// </summary>
|
||||
class ProjectReferenceForILSpy |
||||
{ |
||||
ProjectItem projectItem; |
||||
string fusionName; |
||||
string resolvedPath; |
||||
|
||||
ProjectReferenceForILSpy(ProjectItem projectItem, string fusionName, string resolvedPath) |
||||
{ |
||||
this.projectItem = projectItem; |
||||
this.fusionName = fusionName; |
||||
this.resolvedPath = resolvedPath; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Detects whether the given selected item represents a supported project.
|
||||
/// </summary>
|
||||
/// <param name="itemData">Data object of selected item to check.</param>
|
||||
/// <returns><see cref="ProjectReferenceForILSpy"/> instance or <c>null</c>, if item is not a supported project.</returns>
|
||||
public static ProjectReferenceForILSpy Detect(object itemData) |
||||
{ |
||||
if (itemData is ProjectItem projectItem) { |
||||
var properties = Utils.GetProperties(projectItem.Properties, "FusionName", "ResolvedPath"); |
||||
string fusionName = properties[0] as string; |
||||
string resolvedPath = properties[1] as string; |
||||
if ((fusionName != null) || (resolvedPath != null)) { |
||||
return new ProjectReferenceForILSpy(projectItem, fusionName, resolvedPath); |
||||
} |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// If possible retrieves parameters to use for launching ILSpy instance.
|
||||
/// </summary>
|
||||
/// <param name="projectReferences">List of current project's references.</param>
|
||||
/// <returns>Parameters object or <c>null, if not applicable.</c></returns>
|
||||
public ILSpyParameters GetILSpyParameters(Dictionary<string, string> projectReferences) |
||||
{ |
||||
string fileName = projectItem.ContainingProject?.FileName; |
||||
if (!string.IsNullOrEmpty(fileName)) { |
||||
if (projectReferences.TryGetValue(projectItem.Name, out string path)) { |
||||
return new ILSpyParameters(new[] { path }); |
||||
} |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// If possible retrieves parameters to use for launching ILSpy instance.
|
||||
/// </summary>
|
||||
/// <returns>Parameters object or <c>null, if not applicable.</c></returns>
|
||||
public ILSpyParameters GetILSpyParameters() |
||||
{ |
||||
if (resolvedPath != null) { |
||||
return new ILSpyParameters(new[] { $"{resolvedPath}" }); |
||||
} else if (!string.IsNullOrWhiteSpace(fusionName)) { |
||||
return new ILSpyParameters(new string[] { GacInterop.FindAssemblyInNetGac(AssemblyNameReference.Parse(fusionName)) }); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue