Browse Source

Merge branch '5.0.x' of https://github.com/icsharpcode/ILSpy

pull/1728/head
Siegfried Pammer 6 years ago
parent
commit
9431473286
  1. 32
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/NullableTests.cs
  2. 2
      ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs
  3. 28
      ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs
  4. 2
      ICSharpCode.Decompiler/DebugInfo/SequencePoint.cs
  5. 24
      ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs
  6. 5
      ILSpy.AddIn/Commands/NuGetReferenceForILSpy.cs
  7. 9
      ILSpy.AddIn/Commands/OpenCodeItemCommand.cs
  8. 6
      ILSpy.AddIn/Commands/OpenILSpyCommand.cs
  9. 4
      ILSpy.AddIn/Commands/OpenProjectOutputCommand.cs
  10. 4
      ILSpy.AddIn/Commands/OpenReferenceCommand.cs
  11. 5
      ILSpy.AddIn/Commands/ProjectItemForILSpy.cs
  12. 5
      ILSpy.AddIn/Commands/ProjectReferenceForILSpy.cs
  13. 6
      ILSpy.AddIn/ILSpyAddInPackage.cs
  14. 1
      ILSpy.AddIn/ILSpyInstance.cs
  15. 11
      ILSpy.AddIn/Utils.cs
  16. 4
      ILSpy/MainWindow.xaml.cs
  17. 9
      ILSpy/TextView/DecompilerTextView.cs

32
ICSharpCode.Decompiler.Tests/TestCases/Correctness/NullableTests.cs

@ -23,6 +23,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -23,6 +23,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
class NullableTests
{
static void Main()
{
AvoidLifting();
BitNot();
}
static void AvoidLifting()
{
Console.WriteLine("MayThrow:");
Console.WriteLine(MayThrow(10, 2, 3));
@ -33,8 +39,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -33,8 +39,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
Console.WriteLine(NotUsingAllInputs(5, null));
Console.WriteLine("UsingUntestedValue:");
Console.WriteLine(NotUsingAllInputs(5, 3));
Console.WriteLine(NotUsingAllInputs(5, null));
Console.WriteLine(UsingUntestedValue(5, 3));
Console.WriteLine(UsingUntestedValue(5, null));
}
static int? MayThrow(int? a, int? b, int? c)
@ -54,5 +60,27 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -54,5 +60,27 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
// cannot be lifted because the value differs if b == null
return a.HasValue ? a.GetValueOrDefault() + b.GetValueOrDefault() : default(int?);
}
static void BitNot()
{
UInt32? value = 0;
Assert(~value == UInt32.MaxValue);
UInt64? value2 = 0;
Assert(~value2 == UInt64.MaxValue);
UInt16? value3 = 0;
Assert((UInt16)~value3 == (UInt16)UInt16.MaxValue);
UInt32 value4 = 0;
Assert(~value4 == UInt32.MaxValue);
UInt64 value5 = 0;
Assert(~value5 == UInt64.MaxValue);
UInt16 value6 = 0;
Assert((UInt16)~value6 == UInt16.MaxValue);
}
static void Assert(bool b)
{
if (!b)
throw new InvalidOperationException();
}
}
}

2
ICSharpCode.Decompiler/CSharp/SequencePointBuilder.cs

@ -300,7 +300,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -300,7 +300,7 @@ namespace ICSharpCode.Decompiler.CSharp
if (sequencePoint.Offset < pos) {
// overlapping sequence point?
// delete previous sequence points that are after sequencePoint.Offset
while (newList.Count > 0 && newList.Last().EndOffset > pos) {
while (newList.Count > 0 && newList.Last().EndOffset > sequencePoint.Offset) {
var last = newList.Last();
if (last.Offset >= sequencePoint.Offset) {
newList.RemoveAt(newList.Count - 1);

28
ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs

@ -283,10 +283,9 @@ namespace ICSharpCode.Decompiler.CSharp @@ -283,10 +283,9 @@ namespace ICSharpCode.Decompiler.CSharp
UnwrapChild(uoe.Expression).ConvertTo(targetType, expressionBuilder, checkForOverflow, allowImplicitConversion)
).WithRR(new ResolveResult(targetType)).WithoutILInstruction();
}
bool isLifted = type.IsKnownType(KnownTypeCode.NullableOfT) && targetType.IsKnownType(KnownTypeCode.NullableOfT);
IType utype = isLifted ? NullableType.GetUnderlyingType(type) : type;
IType targetUType = isLifted ? NullableType.GetUnderlyingType(targetType) : targetType;
if (type.IsKnownType(KnownTypeCode.Boolean) && targetType.GetStackType().IsIntegerType()) {
IType utype = NullableType.GetUnderlyingType(type);
IType targetUType = NullableType.GetUnderlyingType(targetType);
if (type.IsKnownType(KnownTypeCode.Boolean) && targetUType.GetStackType().IsIntegerType()) {
// convert from boolean to integer (or enum)
return new ConditionalExpression(
this.Expression,
@ -318,7 +317,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -318,7 +317,7 @@ namespace ICSharpCode.Decompiler.CSharp
.ConvertTo(targetType, expressionBuilder, checkForOverflow);
}
}
if (targetType.IsKnownType(KnownTypeCode.IntPtr)) { // Conversion to IntPtr
if (targetUType.IsKnownType(KnownTypeCode.IntPtr)) { // Conversion to IntPtr
if (type.IsKnownType(KnownTypeCode.Int32)) {
// normal casts work for int (both in checked and unchecked context)
} else if (checkForOverflow) {
@ -336,7 +335,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -336,7 +335,7 @@ namespace ICSharpCode.Decompiler.CSharp
.ConvertTo(targetType, expressionBuilder, checkForOverflow);
}
}
} else if (targetType.IsKnownType(KnownTypeCode.UIntPtr)) { // Conversion to UIntPtr
} else if (targetUType.IsKnownType(KnownTypeCode.UIntPtr)) { // Conversion to UIntPtr
if (type.IsKnownType(KnownTypeCode.UInt32) || type.Kind == TypeKind.Pointer) {
// normal casts work for uint and pointers (both in checked and unchecked context)
} else if (checkForOverflow) {
@ -359,14 +358,14 @@ namespace ICSharpCode.Decompiler.CSharp @@ -359,14 +358,14 @@ namespace ICSharpCode.Decompiler.CSharp
// -> convert via underlying type
return this.ConvertTo(type.GetEnumUnderlyingType(), expressionBuilder, checkForOverflow)
.ConvertTo(targetType, expressionBuilder, checkForOverflow);
} else if (targetType.Kind == TypeKind.Enum && type.Kind == TypeKind.Pointer) {
} else if (targetUType.Kind == TypeKind.Enum && type.Kind == TypeKind.Pointer) {
// pointer to enum: C# doesn't allow such casts
// -> convert via underlying type
return this.ConvertTo(targetType.GetEnumUnderlyingType(), expressionBuilder, checkForOverflow)
return this.ConvertTo(targetUType.GetEnumUnderlyingType(), expressionBuilder, checkForOverflow)
.ConvertTo(targetType, expressionBuilder, checkForOverflow);
}
if (targetType.Kind == TypeKind.Pointer && type.IsKnownType(KnownTypeCode.Char)
|| targetType.IsKnownType(KnownTypeCode.Char) && type.Kind == TypeKind.Pointer) {
|| targetUType.IsKnownType(KnownTypeCode.Char) && type.Kind == TypeKind.Pointer) {
// char <-> pointer: C# doesn't allow such casts
// -> convert via ushort
return this.ConvertTo(compilation.FindType(KnownTypeCode.UInt16), expressionBuilder, checkForOverflow)
@ -418,6 +417,17 @@ namespace ICSharpCode.Decompiler.CSharp @@ -418,6 +417,17 @@ namespace ICSharpCode.Decompiler.CSharp
.WithoutILInstruction()
.WithRR(new ByReferenceResolveResult(elementRR, ReferenceKind.Ref));
}
if (this.ResolveResult.IsCompileTimeConstant && this.ResolveResult.ConstantValue != null
&& NullableType.IsNullable(targetType) && !utype.Equals(targetUType))
{
// Casts like `(uint?)-1` are only valid in an explicitly unchecked context, but we
// don't have logic to ensure such a context (usually we emit into an implicitly unchecked context).
// This only applies with constants as input (int->uint? is fine in implicitly unchecked context).
// We use an intermediate cast to the nullable's underlying type, which results
// in a constant conversion, so the final output will be something like `(uint?)uint.MaxValue`
return ConvertTo(targetUType, expressionBuilder, checkForOverflow, allowImplicitConversion: false)
.ConvertTo(targetType, expressionBuilder, checkForOverflow, allowImplicitConversion);
}
var rr = expressionBuilder.resolver.WithCheckForOverflow(checkForOverflow).ResolveCast(targetType, ResolveResult);
if (rr.IsCompileTimeConstant && !rr.IsError) {
return expressionBuilder.ConvertConstantValue(rr, allowImplicitConversion)

2
ICSharpCode.Decompiler/DebugInfo/SequencePoint.cs

@ -17,12 +17,14 @@ @@ -17,12 +17,14 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Diagnostics;
namespace ICSharpCode.Decompiler.DebugInfo
{
/// <summary>
/// A sequence point read from a PDB file or produced by the decompiler.
/// </summary>
[DebuggerDisplay("SequencePoint IL_{Offset,h}-IL_{EndOffset,h}, {StartLine}:{StartColumn}-{EndLine}:{EndColumn}, IsHidden={IsHidden}")]
public struct SequencePoint
{
/// <summary>

24
ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs

@ -53,6 +53,13 @@ namespace ICSharpCode.Decompiler.Metadata @@ -53,6 +53,13 @@ namespace ICSharpCode.Decompiler.Metadata
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nuget", "packages")
};
static readonly string[] RuntimePacks = new[] {
"Microsoft.NETCore.App",
"Microsoft.WindowsDesktop.App",
"Microsoft.AspNetCore.App",
"Microsoft.AspNetCore.All"
};
readonly Dictionary<string, DotNetCorePackageInfo> packages;
ISet<string> packageBasePaths = new HashSet<string>(StringComparer.Ordinal);
readonly string assemblyName;
@ -124,13 +131,16 @@ namespace ICSharpCode.Decompiler.Metadata @@ -124,13 +131,16 @@ namespace ICSharpCode.Decompiler.Metadata
string FallbackToDotNetSharedDirectory(IAssemblyReference name, Version version)
{
if (dotnetBasePath == null) return null;
var basePath = Path.Combine(dotnetBasePath, "shared", "Microsoft.NETCore.App");
var closestVersion = GetClosestVersionFolder(basePath, version);
if (File.Exists(Path.Combine(basePath, closestVersion, name.Name + ".dll"))) {
return Path.Combine(basePath, closestVersion, name.Name + ".dll");
} else if (File.Exists(Path.Combine(basePath, closestVersion, name.Name + ".exe"))) {
return Path.Combine(basePath, closestVersion, name.Name + ".exe");
if (dotnetBasePath == null)
return null;
var basePaths = RuntimePacks.Select(pack => Path.Combine(dotnetBasePath, "shared", pack));
foreach (var basePath in basePaths) {
var closestVersion = GetClosestVersionFolder(basePath, version);
if (File.Exists(Path.Combine(basePath, closestVersion, name.Name + ".dll"))) {
return Path.Combine(basePath, closestVersion, name.Name + ".dll");
} else if (File.Exists(Path.Combine(basePath, closestVersion, name.Name + ".exe"))) {
return Path.Combine(basePath, closestVersion, name.Name + ".exe");
}
}
return null;
}

5
ILSpy.AddIn/Commands/NuGetReferenceForILSpy.cs

@ -4,6 +4,7 @@ using System.Linq; @@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EnvDTE;
using Microsoft.VisualStudio.Shell;
namespace ICSharpCode.ILSpy.AddIn.Commands
{
@ -26,6 +27,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -26,6 +27,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
/// <returns><see cref="NuGetReferenceForILSpy"/> instance or <c>null</c>, if item is not a supported project.</returns>
public static NuGetReferenceForILSpy Detect(object itemData)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (itemData is ProjectItem projectItem) {
var properties = Utils.GetProperties(projectItem.Properties, "Type");
if ((properties[0] as string) == "Package") {
@ -42,6 +45,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -42,6 +45,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
/// <returns>Parameters object or <c>null, if not applicable.</c></returns>
public ILSpyParameters GetILSpyParameters()
{
ThreadHelper.ThrowIfNotOnUIThread();
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" });

9
ILSpy.AddIn/Commands/OpenCodeItemCommand.cs

@ -23,6 +23,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -23,6 +23,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
protected override void OnBeforeQueryStatus(object sender, EventArgs e)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (sender is OleMenuCommand menuItem) {
menuItem.Visible = false;
@ -46,6 +48,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -46,6 +48,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
Document GetRoslynDocument()
{
ThreadHelper.ThrowIfNotOnUIThread();
var document = owner.DTE.ActiveDocument;
var selection = (EnvDTE.TextPoint)((EnvDTE.TextSelection)document.Selection).ActivePoint;
var id = owner.Workspace.CurrentSolution.GetDocumentIdsWithFilePath(document.FullName).FirstOrDefault();
@ -57,12 +61,16 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -57,12 +61,16 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
EnvDTE.TextPoint GetEditorSelection()
{
ThreadHelper.ThrowIfNotOnUIThread();
var document = owner.DTE.ActiveDocument;
return ((EnvDTE.TextSelection)document.Selection).ActivePoint;
}
protected override async void OnExecute(object sender, EventArgs e)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
var textView = Utils.GetCurrentViewHost(owner)?.TextView;
if (textView == null)
return;
@ -89,6 +97,7 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -89,6 +97,7 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
// Add our own project as well (not among references)
var project = FindProject(owner.DTE.Solution.Projects.OfType<EnvDTE.Project>(), roslynProject.FilePath);
if (project == null) {
owner.ShowMessage(OLEMSGICON.OLEMSGICON_WARNING, "Can't show ILSpy for this code element!");
return;

6
ILSpy.AddIn/Commands/OpenILSpyCommand.cs

@ -55,6 +55,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -55,6 +55,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
protected void OpenAssembliesInILSpy(ILSpyParameters parameters)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (parameters == null)
return;
@ -71,6 +73,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -71,6 +73,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
protected Dictionary<string, DetectedReference> GetReferences(Microsoft.CodeAnalysis.Project parentProject)
{
ThreadHelper.ThrowIfNotOnUIThread();
var dict = new Dictionary<string, DetectedReference>();
foreach (var reference in parentProject.MetadataReferences) {
using (var assemblyDef = AssemblyDefinition.ReadAssembly(reference.Display)) {
@ -97,6 +101,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -97,6 +101,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
protected EnvDTE.Project FindProject(IEnumerable<EnvDTE.Project> projects, string projectFile)
{
ThreadHelper.ThrowIfNotOnUIThread();
foreach (var project in projects) {
switch (project.Kind) {
case DTEConstants.vsProjectKindSolutionItems:

4
ILSpy.AddIn/Commands/OpenProjectOutputCommand.cs

@ -17,6 +17,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -17,6 +17,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
protected override void OnBeforeQueryStatus(object sender, EventArgs e)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (sender is OleMenuCommand menuItem) {
menuItem.Visible = false;
@ -27,6 +29,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -27,6 +29,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
protected override void OnExecute(object sender, EventArgs e)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (owner.DTE.SelectedItems.Count != 1)
return;
var projectItemWrapper = ProjectItemForILSpy.Detect(owner, owner.DTE.SelectedItems.Item(1));

4
ILSpy.AddIn/Commands/OpenReferenceCommand.cs

@ -22,6 +22,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -22,6 +22,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
protected override void OnBeforeQueryStatus(object sender, EventArgs e)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (sender is OleMenuCommand menuItem) {
menuItem.Visible = false;
@ -44,6 +46,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -44,6 +46,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
protected override void OnExecute(object sender, EventArgs e)
{
ThreadHelper.ThrowIfNotOnUIThread();
var itemObject = owner.GetSelectedItemsData<object>().FirstOrDefault();
if (itemObject == null)
return;

5
ILSpy.AddIn/Commands/ProjectItemForILSpy.cs

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
using System.IO;
using System.Linq;
using EnvDTE;
using Microsoft.VisualStudio.Shell;
namespace ICSharpCode.ILSpy.AddIn.Commands
{
@ -27,6 +28,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -27,6 +28,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
/// <returns><see cref="ProjectItemForILSpy"/> instance or <c>null</c>, if item is not a supported project.</returns>
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)
@ -42,6 +45,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -42,6 +45,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
/// <returns>Parameters object or <c>null, if not applicable.</c></returns>
public ILSpyParameters GetILSpyParameters(ILSpyAddInPackage package)
{
ThreadHelper.ThrowIfNotOnUIThread();
return new ILSpyParameters(new[] { Utils.GetProjectOutputAssembly(project, roslynProject) });
}
}

5
ILSpy.AddIn/Commands/ProjectReferenceForILSpy.cs

@ -4,6 +4,7 @@ using System.Linq; @@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EnvDTE;
using Microsoft.VisualStudio.Shell;
using Mono.Cecil;
namespace ICSharpCode.ILSpy.AddIn.Commands
@ -31,6 +32,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -31,6 +32,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
/// <returns><see cref="ProjectReferenceForILSpy"/> instance or <c>null</c>, if item is not a supported project.</returns>
public static ProjectReferenceForILSpy Detect(object itemData)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (itemData is ProjectItem projectItem) {
var properties = Utils.GetProperties(projectItem.Properties, "FusionName", "ResolvedPath");
string fusionName = properties[0] as string;
@ -50,6 +53,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -50,6 +53,8 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
/// <returns>Parameters object or <c>null, if not applicable.</c></returns>
public ILSpyParameters GetILSpyParameters(Dictionary<string, DetectedReference> projectReferences)
{
ThreadHelper.ThrowIfNotOnUIThread();
string fileName = projectItem.ContainingProject?.FileName;
if (!string.IsNullOrEmpty(fileName)) {
if (projectReferences.TryGetValue(projectItem.Name, out DetectedReference path)) {

6
ILSpy.AddIn/ILSpyAddInPackage.cs

@ -113,6 +113,10 @@ namespace ICSharpCode.ILSpy.AddIn @@ -113,6 +113,10 @@ namespace ICSharpCode.ILSpy.AddIn
ThreadHelper.ThrowIfNotOnUIThread();
IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
if (uiShell == null) {
return 0;
}
Guid clsid = Guid.Empty;
int result;
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
@ -136,6 +140,8 @@ namespace ICSharpCode.ILSpy.AddIn @@ -136,6 +140,8 @@ namespace ICSharpCode.ILSpy.AddIn
public IEnumerable<T> GetSelectedItemsData<T>()
{
ThreadHelper.ThrowIfNotOnUIThread();
if (DTE.ToolWindows.SolutionExplorer.SelectedItems is IEnumerable<UIHierarchyItem> hierarchyItems) {
foreach (var item in hierarchyItems) {
if (item.Object is T typedItem) {

1
ILSpy.AddIn/ILSpyInstance.cs

@ -54,6 +54,7 @@ namespace ICSharpCode.ILSpy.AddIn @@ -54,6 +54,7 @@ namespace ICSharpCode.ILSpy.AddIn
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD110:Observe result of async calls", Justification = "<Pending>")]
void SendMessage(Process ilspyProcess, string message, bool activate)
{
// We wait asynchronously until target window can be found and try to find it multiple times

11
ILSpy.AddIn/Utils.cs

@ -8,6 +8,7 @@ using System.Text; @@ -8,6 +8,7 @@ using System.Text;
using EnvDTE;
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.LanguageServices;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.TextManager.Interop;
@ -148,6 +149,8 @@ namespace ICSharpCode.ILSpy.AddIn @@ -148,6 +149,8 @@ namespace ICSharpCode.ILSpy.AddIn
public static object[] GetProperties(EnvDTE.Properties properties, params string[] names)
{
ThreadHelper.ThrowIfNotOnUIThread();
var values = new object[names.Length];
foreach (object p in properties) {
try {
@ -168,6 +171,8 @@ namespace ICSharpCode.ILSpy.AddIn @@ -168,6 +171,8 @@ namespace ICSharpCode.ILSpy.AddIn
public static List<(string, object)> GetAllProperties(EnvDTE.Properties properties)
{
ThreadHelper.ThrowIfNotOnUIThread();
var result = new List<(string, object)>();
for (int i = 0; i < properties.Count; i++) {
try {
@ -207,6 +212,10 @@ namespace ICSharpCode.ILSpy.AddIn @@ -207,6 +212,10 @@ namespace ICSharpCode.ILSpy.AddIn
public static IWpfTextViewHost GetCurrentViewHost(IServiceProvider serviceProvider)
{
IVsTextManager txtMgr = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager));
if (txtMgr == null) {
return null;
}
IVsTextView vTextView = null;
int mustHaveFocus = 1;
txtMgr.GetActiveView(mustHaveFocus, null, out vTextView);
@ -235,6 +244,8 @@ namespace ICSharpCode.ILSpy.AddIn @@ -235,6 +244,8 @@ namespace ICSharpCode.ILSpy.AddIn
public static string GetProjectOutputAssembly(Project project, Microsoft.CodeAnalysis.Project roslynProject)
{
ThreadHelper.ThrowIfNotOnUIThread();
string outputFileName = Path.GetFileName(roslynProject.OutputFilePath);
// Get the directory path based on the project file.

4
ILSpy/MainWindow.xaml.cs

@ -343,10 +343,10 @@ namespace ICSharpCode.ILSpy @@ -343,10 +343,10 @@ namespace ICSharpCode.ILSpy
output.Write(string.Format("Cannot find '{0}' in command line specified assemblies.", navigateTo));
decompilerTextView.ShowText(output);
}
} else if (commandLineLoadedAssemblies.Count == 1) {
} else if (relevantAssemblies.Count == 1) {
// NavigateTo == null and an assembly was given on the command-line:
// Select the newly loaded assembly
AssemblyTreeNode asmNode = assemblyListTreeNode.FindAssemblyNode(commandLineLoadedAssemblies[0]);
AssemblyTreeNode asmNode = assemblyListTreeNode.FindAssemblyNode(relevantAssemblies[0]);
if (asmNode != null && treeView.SelectedItem == initialSelection) {
SelectNode(asmNode);
}

9
ILSpy/TextView/DecompilerTextView.cs

@ -649,12 +649,13 @@ namespace ICSharpCode.ILSpy.TextView @@ -649,12 +649,13 @@ namespace ICSharpCode.ILSpy.TextView
if (referenceSegment == null) {
ClearLocalReferenceMarks();
} else if (referenceSegment.IsLocal || !referenceSegment.IsDefinition) {
JumpToReference(referenceSegment);
textEditor.TextArea.ClearSelection();
// cancel mouse selection to avoid AvalonEdit selecting between the new
// cursor position and the mouse position.
textEditor.TextArea.MouseSelectionMode = MouseSelectionMode.None;
JumpToReference(referenceSegment);
}
// cancel mouse selection to avoid AvalonEdit selecting between the new
// cursor position and the mouse position.
textEditor.TextArea.MouseSelectionMode = MouseSelectionMode.None;
}
}

Loading…
Cancel
Save