From 142c406596c127e83366a7678dfb3aefcd4230c5 Mon Sep 17 00:00:00 2001 From: Pent Ploompuu Date: Wed, 13 Dec 2017 00:59:43 +0200 Subject: [PATCH 01/36] Add "private protected" support --- ICSharpCode.Decompiler/CSharp/Syntax/CSharpModifierToken.cs | 2 +- ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs | 3 ++- ICSharpCode.Decompiler/TypeSystem/Accessibility.cs | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/CSharpModifierToken.cs b/ICSharpCode.Decompiler/CSharp/Syntax/CSharpModifierToken.cs index d0f6c15fa..01292b740 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/CSharpModifierToken.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/CSharpModifierToken.cs @@ -62,7 +62,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax // Not worth using a dictionary for such few elements. // This table is sorted in the order that modifiers should be output when generating code. static readonly Modifiers[] allModifiers = { - Modifiers.Public, Modifiers.Protected, Modifiers.Private, Modifiers.Internal, + Modifiers.Public, Modifiers.Private, Modifiers.Protected, Modifiers.Internal, Modifiers.New, Modifiers.Unsafe, Modifiers.Abstract, Modifiers.Virtual, Modifiers.Sealed, Modifiers.Static, Modifiers.Override, diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs index abf709ad7..b75feb53f 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs @@ -1057,8 +1057,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax case Accessibility.Internal: return Modifiers.Internal; case Accessibility.ProtectedOrInternal: - case Accessibility.ProtectedAndInternal: return Modifiers.Protected | Modifiers.Internal; + case Accessibility.ProtectedAndInternal: + return Modifiers.Private | Modifiers.Protected; default: return Modifiers.None; } diff --git a/ICSharpCode.Decompiler/TypeSystem/Accessibility.cs b/ICSharpCode.Decompiler/TypeSystem/Accessibility.cs index fae4c9673..0122c8883 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Accessibility.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Accessibility.cs @@ -53,7 +53,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// /// The entity is accessible in derived classes within the same project content. /// - /// C# does not support this accessibility. + /// This corresponds to C# 'private protected'. ProtectedAndInternal, } From 9adbff24a9aaf713f4fbde38138ac3efea03f941 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 16 Dec 2017 13:49:06 +0100 Subject: [PATCH 02/36] Set versionName = null (RTM) --- ILSpy/Properties/AssemblyInfo.template.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ILSpy/Properties/AssemblyInfo.template.cs b/ILSpy/Properties/AssemblyInfo.template.cs index 21cd66c33..b40fac15c 100644 --- a/ILSpy/Properties/AssemblyInfo.template.cs +++ b/ILSpy/Properties/AssemblyInfo.template.cs @@ -42,7 +42,7 @@ internal static class RevisionClass public const string Minor = "0"; public const string Build = "0"; public const string Revision = "$INSERTREVISION$"; - public const string VersionName = "beta4"; + public const string VersionName = null; public const string FullVersion = Major + "." + Minor + "." + Build + ".$INSERTREVISION$$INSERTBRANCHPOSTFIX$$INSERTVERSIONNAMEPOSTFIX$"; } From 5184a9be1e4ed083cf9b7f7a1cbd203024421ea5 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 16 Dec 2017 15:12:40 +0100 Subject: [PATCH 03/36] Fix NRE in LoadedAssembly.LookupReferencedAssemblyInternal --- ILSpy/LoadedAssembly.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ILSpy/LoadedAssembly.cs b/ILSpy/LoadedAssembly.cs index 3eba4c955..483136b3b 100644 --- a/ILSpy/LoadedAssembly.cs +++ b/ILSpy/LoadedAssembly.cs @@ -288,7 +288,7 @@ namespace ICSharpCode.ILSpy } } - if (loadingAssemblies.TryGetValue(file, out asm)) + if (file != null && loadingAssemblies.TryGetValue(file, out asm)) return asm; if (file != null) { From 889b14747f01fd154bfbb408a25352bfac34c5fa Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 17 Dec 2017 00:10:12 +0100 Subject: [PATCH 04/36] Fix NRE in DoDecompile(FieldDefinition) on internal value__ enum fields --- ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs index c7dfd5ace..731c7c964 100644 --- a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs @@ -826,15 +826,15 @@ namespace ICSharpCode.Decompiler.CSharp { Debug.Assert(decompilationContext.CurrentMember == field); var typeSystemAstBuilder = CreateAstBuilder(decompilationContext); - if (decompilationContext.CurrentTypeDefinition.Kind == TypeKind.Enum) { + if (decompilationContext.CurrentTypeDefinition.Kind == TypeKind.Enum && field.ConstantValue != null) { var index = decompilationContext.CurrentTypeDefinition.Members.IndexOf(field); long previousValue = -1; if (index > 0) { var previousMember = (IField)decompilationContext.CurrentTypeDefinition.Members[index - 1]; previousValue = (long)CSharpPrimitiveCast.Cast(TypeCode.Int64, previousMember.ConstantValue, false); } - long initValue = (long)CSharpPrimitiveCast.Cast(TypeCode.Int64, field.ConstantValue, false); var enumDec = new EnumMemberDeclaration { Name = field.Name }; + long initValue = (long)CSharpPrimitiveCast.Cast(TypeCode.Int64, field.ConstantValue, false); if (decompilationContext.CurrentTypeDefinition.Attributes.Any(a => a.AttributeType.FullName == "System.FlagsAttribute")) { enumDec.Initializer = typeSystemAstBuilder.ConvertConstantValue(decompilationContext.CurrentTypeDefinition.EnumUnderlyingType, field.ConstantValue); if (enumDec.Initializer is PrimitiveExpression primitive && initValue > 9) From 454f512929bb1676d6d21052aac56480b0fba4ff Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 17 Dec 2017 19:52:59 +0100 Subject: [PATCH 05/36] Tests: Set Roslyn language version to latest --- ICSharpCode.Decompiler.Tests/Helpers/Tester.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs b/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs index 4abc3c0f7..27f5b4af7 100644 --- a/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs +++ b/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs @@ -187,7 +187,7 @@ namespace ICSharpCode.Decompiler.Tests.Helpers var preprocessorSymbols = GetPreprocessorSymbols(flags); if (flags.HasFlag(CompilerOptions.UseRoslyn)) { - var parseOptions = new CSharpParseOptions(preprocessorSymbols: preprocessorSymbols.ToArray()); + var parseOptions = new CSharpParseOptions(preprocessorSymbols: preprocessorSymbols.ToArray(), languageVersion: LanguageVersion.Latest); var syntaxTrees = sourceFileNames.Select(f => SyntaxFactory.ParseSyntaxTree(File.ReadAllText(f), parseOptions, path: f)); var compilation = CSharpCompilation.Create(Path.GetFileNameWithoutExtension(sourceFileName), syntaxTrees, defaultReferences.Value, From 70b01e734ad5370c6ca7823ba801ccc02f2dae3e Mon Sep 17 00:00:00 2001 From: Christoph Wille Date: Mon, 18 Dec 2017 08:00:54 +0100 Subject: [PATCH 06/36] Update NuGet packages in Frontends and Xamarin Workbook --- DecompilerNuGetDemos.workbook | 2 +- .../ICSharpCode.Decompiler.Console.csproj | 2 +- .../ICSharpCode.Decompiler.PowerShell.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DecompilerNuGetDemos.workbook b/DecompilerNuGetDemos.workbook index 498a46f2e..ac1c0d94d 100644 --- a/DecompilerNuGetDemos.workbook +++ b/DecompilerNuGetDemos.workbook @@ -6,7 +6,7 @@ platforms: - DotNetCore packages: - id: ICSharpCode.Decompiler - version: 3.0.0.3403-beta4 + version: 3.0.0.3443 --- Setup: load the references required to work with the decompiler diff --git a/ICSharpCode.Decompiler.Console/ICSharpCode.Decompiler.Console.csproj b/ICSharpCode.Decompiler.Console/ICSharpCode.Decompiler.Console.csproj index 2f5654cb8..6151cef8d 100644 --- a/ICSharpCode.Decompiler.Console/ICSharpCode.Decompiler.Console.csproj +++ b/ICSharpCode.Decompiler.Console/ICSharpCode.Decompiler.Console.csproj @@ -14,7 +14,7 @@ - + diff --git a/ICSharpCode.Decompiler.PowerShell/ICSharpCode.Decompiler.PowerShell.csproj b/ICSharpCode.Decompiler.PowerShell/ICSharpCode.Decompiler.PowerShell.csproj index e3ac232a8..3e2f7d7ce 100644 --- a/ICSharpCode.Decompiler.PowerShell/ICSharpCode.Decompiler.PowerShell.csproj +++ b/ICSharpCode.Decompiler.PowerShell/ICSharpCode.Decompiler.PowerShell.csproj @@ -8,7 +8,7 @@ - + From 96c6d5d0c57d0c0bb4dba9c9d45b21debaf45950 Mon Sep 17 00:00:00 2001 From: Christoph Wille Date: Mon, 18 Dec 2017 08:01:39 +0100 Subject: [PATCH 07/36] Fix Identity of package Version -> 1.7 Re-enable Enterprise sku (locally found, marketplace didn't) --- ILSpy.AddIn/ILSpy.AddIn.csproj | 4 ++-- ILSpy.AddIn/source.extension.vsixmanifest | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ILSpy.AddIn/ILSpy.AddIn.csproj b/ILSpy.AddIn/ILSpy.AddIn.csproj index a3156ee74..f14de43d3 100644 --- a/ILSpy.AddIn/ILSpy.AddIn.csproj +++ b/ILSpy.AddIn/ILSpy.AddIn.csproj @@ -13,8 +13,8 @@ IC#Code ILSpy en-US - 1.5.0.0 - 1.5.0.0 + 1.7.0.0 + 1.7.0.0 False true diff --git a/ILSpy.AddIn/source.extension.vsixmanifest b/ILSpy.AddIn/source.extension.vsixmanifest index 5a55128dc..56753f5e3 100644 --- a/ILSpy.AddIn/source.extension.vsixmanifest +++ b/ILSpy.AddIn/source.extension.vsixmanifest @@ -1,7 +1,7 @@  - + ILSpy Integrates the ILSpy decompiler into Visual Studio. http://www.ilspy.net @@ -11,6 +11,7 @@ + From 151fa73e296f0421aae9c38fddadecdf07f1ced3 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 18 Dec 2017 15:13:08 +0100 Subject: [PATCH 08/36] Fix exception in LoadPackageInfos --- ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinder.cs b/ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinder.cs index 2ea558215..7da9f19ff 100644 --- a/ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinder.cs +++ b/ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinder.cs @@ -86,7 +86,7 @@ namespace ICSharpCode.Decompiler static IEnumerable LoadPackageInfos(string depsJsonFileName, string targetFramework) { var dependencies = JsonReader.Parse(File.ReadAllText(depsJsonFileName)); - var runtimeInfos = dependencies["targets"][targetFramework].AsJsonObject; + var runtimeInfos = dependencies["targets"][targetFramework + "/"].AsJsonObject; var libraries = dependencies["libraries"].AsJsonObject; if (runtimeInfos == null || libraries == null) yield break; From f493f5e6069e83e9bc0f22b4f6b1163de7171232 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 18 Dec 2017 15:19:41 +0100 Subject: [PATCH 09/36] Fail with null value instead of other exception in case of invalid json file. --- ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinder.cs b/ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinder.cs index 7da9f19ff..8ff093c1d 100644 --- a/ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinder.cs +++ b/ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinder.cs @@ -93,7 +93,7 @@ namespace ICSharpCode.Decompiler foreach (var library in libraries) { var type = library.Value["type"].AsString; var path = library.Value["path"].AsString; - var runtimeInfo = runtimeInfos[library.Key]["runtime"].AsJsonObject; + var runtimeInfo = runtimeInfos[library.Key].AsJsonObject?["runtime"].AsJsonObject; string[] components = new string[runtimeInfo?.Count ?? 0]; if (runtimeInfo != null) { int i = 0; From 8bb5551396276ea5498c1e30354c225bb105ebd9 Mon Sep 17 00:00:00 2001 From: Christoph Wille Date: Mon, 18 Dec 2017 16:08:02 +0100 Subject: [PATCH 10/36] Go to .3447 Nuget (found .deps.json parsing error on release tests). That also hid a throw on assembly resolution. --- DecompilerNuGetDemos.workbook | 2 +- .../ICSharpCode.Decompiler.Console.csproj | 2 +- ICSharpCode.Decompiler.Console/Program.cs | 9 +++++++-- ICSharpCode.Decompiler.PowerShell/Demo.ps1 | 6 +++++- ICSharpCode.Decompiler.PowerShell/GetDecompilerCmdlet.cs | 4 +++- .../ICSharpCode.Decompiler.PowerShell.csproj | 2 +- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/DecompilerNuGetDemos.workbook b/DecompilerNuGetDemos.workbook index ac1c0d94d..f7c907159 100644 --- a/DecompilerNuGetDemos.workbook +++ b/DecompilerNuGetDemos.workbook @@ -6,7 +6,7 @@ platforms: - DotNetCore packages: - id: ICSharpCode.Decompiler - version: 3.0.0.3443 + version: 3.0.0.3447 --- Setup: load the references required to work with the decompiler diff --git a/ICSharpCode.Decompiler.Console/ICSharpCode.Decompiler.Console.csproj b/ICSharpCode.Decompiler.Console/ICSharpCode.Decompiler.Console.csproj index 6151cef8d..c80c5b02e 100644 --- a/ICSharpCode.Decompiler.Console/ICSharpCode.Decompiler.Console.csproj +++ b/ICSharpCode.Decompiler.Console/ICSharpCode.Decompiler.Console.csproj @@ -14,7 +14,7 @@ - + diff --git a/ICSharpCode.Decompiler.Console/Program.cs b/ICSharpCode.Decompiler.Console/Program.cs index 1b375003f..3c3a724fa 100644 --- a/ICSharpCode.Decompiler.Console/Program.cs +++ b/ICSharpCode.Decompiler.Console/Program.cs @@ -75,9 +75,14 @@ namespace ICSharpCode.Decompiler.Console return app.Execute(args); } + static CSharpDecompiler GetDecompiler(string assemblyFileName) + { + return new CSharpDecompiler(assemblyFileName, new DecompilerSettings() { ThrowOnAssemblyResolveErrors = false }); + } + static void ListContent(string assemblyFileName, TextWriter output, ISet kinds) { - CSharpDecompiler decompiler = new CSharpDecompiler(assemblyFileName, new DecompilerSettings()); + CSharpDecompiler decompiler = GetDecompiler(assemblyFileName); foreach (var type in decompiler.TypeSystem.Compilation.MainAssembly.GetAllTypeDefinitions()) { if (!kinds.Contains(type.Kind)) @@ -95,7 +100,7 @@ namespace ICSharpCode.Decompiler.Console static void Decompile(string assemblyFileName, TextWriter output, string typeName = null) { - CSharpDecompiler decompiler = new CSharpDecompiler(assemblyFileName, new DecompilerSettings()); + CSharpDecompiler decompiler = GetDecompiler(assemblyFileName); if (typeName == null) { output.Write(decompiler.DecompileWholeModuleAsString()); diff --git a/ICSharpCode.Decompiler.PowerShell/Demo.ps1 b/ICSharpCode.Decompiler.PowerShell/Demo.ps1 index 04e2ae618..3b8092a72 100644 --- a/ICSharpCode.Decompiler.PowerShell/Demo.ps1 +++ b/ICSharpCode.Decompiler.PowerShell/Demo.ps1 @@ -10,7 +10,11 @@ Import-Module $modulePath $version = Get-DecompilerVersion Write-Output $version -$decompiler = Get-Decompiler $modulePath +# different test assemblies - it makes a difference wrt .deps.json so there are two netstandard tests here +$asm_netstdWithDepsJson = $basePath + '\bin\Debug\netstandard2.0\ICSharpCode.Decompiler.Powershell.dll' +$asm_netstd = $basePath + '\bin\Debug\netstandard2.0\ICSharpCode.Decompiler.dll' + +$decompiler = Get-Decompiler $asm_netstdWithDepsJson $classes = Get-DecompiledTypes $decompiler -Types class $classes.Count diff --git a/ICSharpCode.Decompiler.PowerShell/GetDecompilerCmdlet.cs b/ICSharpCode.Decompiler.PowerShell/GetDecompilerCmdlet.cs index 0faab54f4..7afddec54 100644 --- a/ICSharpCode.Decompiler.PowerShell/GetDecompilerCmdlet.cs +++ b/ICSharpCode.Decompiler.PowerShell/GetDecompilerCmdlet.cs @@ -20,7 +20,9 @@ namespace ICSharpCode.Decompiler.PowerShell string path = GetUnresolvedProviderPathFromPSPath(LiteralPath); try { - var decompiler = new CSharpDecompiler(path, new DecompilerSettings()); + var decompiler = new CSharpDecompiler(path, new DecompilerSettings() { + ThrowOnAssemblyResolveErrors = false + }); WriteObject(decompiler); } catch (Exception e) { diff --git a/ICSharpCode.Decompiler.PowerShell/ICSharpCode.Decompiler.PowerShell.csproj b/ICSharpCode.Decompiler.PowerShell/ICSharpCode.Decompiler.PowerShell.csproj index 3e2f7d7ce..31a57d1f6 100644 --- a/ICSharpCode.Decompiler.PowerShell/ICSharpCode.Decompiler.PowerShell.csproj +++ b/ICSharpCode.Decompiler.PowerShell/ICSharpCode.Decompiler.PowerShell.csproj @@ -8,7 +8,7 @@ - + From 8dac53e2563c573d5948ad01603d48905f55414a Mon Sep 17 00:00:00 2001 From: Christoph Wille Date: Mon, 18 Dec 2017 16:16:17 +0100 Subject: [PATCH 11/36] Update vsix to 1.7.1 to include update --- ILSpy.AddIn/ILSpy.AddIn.csproj | 4 ++-- ILSpy.AddIn/source.extension.vsixmanifest | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ILSpy.AddIn/ILSpy.AddIn.csproj b/ILSpy.AddIn/ILSpy.AddIn.csproj index f14de43d3..208d762d3 100644 --- a/ILSpy.AddIn/ILSpy.AddIn.csproj +++ b/ILSpy.AddIn/ILSpy.AddIn.csproj @@ -13,8 +13,8 @@ IC#Code ILSpy en-US - 1.7.0.0 - 1.7.0.0 + 1.7.1.0 + 1.7.1.0 False true diff --git a/ILSpy.AddIn/source.extension.vsixmanifest b/ILSpy.AddIn/source.extension.vsixmanifest index 56753f5e3..ef25f9c59 100644 --- a/ILSpy.AddIn/source.extension.vsixmanifest +++ b/ILSpy.AddIn/source.extension.vsixmanifest @@ -1,7 +1,7 @@  - + ILSpy Integrates the ILSpy decompiler into Visual Studio. http://www.ilspy.net From 1dac21d0c776a9a8b0d6a65ab0e68e320c31439a Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 19 Dec 2017 00:10:59 +0100 Subject: [PATCH 12/36] Set version to 3.1 alpha1 --- ILSpy/Properties/AssemblyInfo.template.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ILSpy/Properties/AssemblyInfo.template.cs b/ILSpy/Properties/AssemblyInfo.template.cs index b40fac15c..d8be3d2fb 100644 --- a/ILSpy/Properties/AssemblyInfo.template.cs +++ b/ILSpy/Properties/AssemblyInfo.template.cs @@ -39,10 +39,10 @@ using System.Diagnostics.CodeAnalysis; internal static class RevisionClass { public const string Major = "3"; - public const string Minor = "0"; + public const string Minor = "1"; public const string Build = "0"; public const string Revision = "$INSERTREVISION$"; - public const string VersionName = null; + public const string VersionName = "alpha1"; public const string FullVersion = Major + "." + Minor + "." + Build + ".$INSERTREVISION$$INSERTBRANCHPOSTFIX$$INSERTVERSIONNAMEPOSTFIX$"; } From c848ec41e8e2677e30f012e892851a0bfbc64170 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 19 Dec 2017 16:48:53 +0100 Subject: [PATCH 13/36] Add C# 7.2 private protected unit tests --- .../ICSharpCode.Decompiler.Tests.csproj | 2 + .../PrettyTestRunner.cs | 6 ++ .../TestCases/Pretty/CS72_PrivateProtected.cs | 31 +++++++ .../CS72_PrivateProtected.opt.roslyn.il | 83 ++++++++++++++++++ .../Pretty/CS72_PrivateProtected.roslyn.il | 86 +++++++++++++++++++ 5 files changed, 208 insertions(+) create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/CS72_PrivateProtected.cs create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/CS72_PrivateProtected.opt.roslyn.il create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/CS72_PrivateProtected.roslyn.il diff --git a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj index 4fa6cd40c..4653b56ad 100644 --- a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj @@ -3,6 +3,7 @@ net46 + latest True @@ -62,6 +63,7 @@ + diff --git a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs index 30d62d94d..d246eed85 100644 --- a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs @@ -224,6 +224,12 @@ namespace ICSharpCode.Decompiler.Tests Run(cscOptions: cscOptions, decompilerSettings: new DecompilerSettings { UseDebugSymbols = false }); } + [Test] + public void CS72_PrivateProtected([ValueSource("roslynOnlyOptions")] CompilerOptions cscOptions) + { + Run(cscOptions: cscOptions); + } + void Run([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CompilerOptions cscOptions = CompilerOptions.None, DecompilerSettings decompilerSettings = null) { var ilFile = Path.Combine(TestCasePath, testName) + Tester.GetSuffix(cscOptions) + ".il"; diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CS72_PrivateProtected.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CS72_PrivateProtected.cs new file mode 100644 index 000000000..914bd48cd --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CS72_PrivateProtected.cs @@ -0,0 +1,31 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty +{ + internal class CS72_PrivateProtected + { + private protected int Property { + get; + } + + private protected void Method() + { + } + } +} diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CS72_PrivateProtected.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CS72_PrivateProtected.opt.roslyn.il new file mode 100644 index 000000000..7f5300105 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CS72_PrivateProtected.opt.roslyn.il @@ -0,0 +1,83 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. All rights reserved. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly CS72_PrivateProtected +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) + .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + + // --- The following custom attribute is added automatically, do not uncomment ------- + // .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 02 00 00 00 00 00 ) + + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module CS72_PrivateProtected.dll +// MVID: {16957694-0DCC-41BA-B992-22F83B96A9D7} +.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) +.imagebase 0x10000000 +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 // WINDOWS_CUI +.corflags 0x00000001 // ILONLY +// Image base: 0x031E0000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.CS72_PrivateProtected + extends [mscorlib]System.Object +{ + .field private initonly int32 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .method famandassem hidebysig specialname + instance int32 get_Property() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.CS72_PrivateProtected::'k__BackingField' + IL_0006: ret + } // end of method CS72_PrivateProtected::get_Property + + .method famandassem hidebysig instance void + Method() cil managed + { + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method CS72_PrivateProtected::Method + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method CS72_PrivateProtected::.ctor + + .property instance int32 Property() + { + .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.CS72_PrivateProtected::get_Property() + } // end of property CS72_PrivateProtected::Property +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CS72_PrivateProtected + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CS72_PrivateProtected.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CS72_PrivateProtected.roslyn.il new file mode 100644 index 000000000..03f508c0b --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/CS72_PrivateProtected.roslyn.il @@ -0,0 +1,86 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. All rights reserved. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly CS72_PrivateProtected +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) + .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + + // --- The following custom attribute is added automatically, do not uncomment ------- + // .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 07 01 00 00 00 00 ) + + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module CS72_PrivateProtected.dll +// MVID: {056F9D5F-A186-4957-9181-B6C798C15C6C} +.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) +.imagebase 0x10000000 +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 // WINDOWS_CUI +.corflags 0x00000001 // ILONLY +// Image base: 0x03A40000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.CS72_PrivateProtected + extends [mscorlib]System.Object +{ + .field private initonly int32 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .method famandassem hidebysig specialname + instance int32 get_Property() cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.CS72_PrivateProtected::'k__BackingField' + IL_0006: ret + } // end of method CS72_PrivateProtected::get_Property + + .method famandassem hidebysig instance void + Method() cil managed + { + // Code size 2 (0x2) + .maxstack 8 + IL_0000: nop + IL_0001: ret + } // end of method CS72_PrivateProtected::Method + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + // Code size 8 (0x8) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method CS72_PrivateProtected::.ctor + + .property instance int32 Property() + { + .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.CS72_PrivateProtected::get_Property() + } // end of property CS72_PrivateProtected::Property +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.CS72_PrivateProtected + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** From b91cf16aa0b283437dc3991014fbd1590fef807e Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 19 Dec 2017 16:50:37 +0100 Subject: [PATCH 14/36] Add overlay icon for private protected. --- ILSpy/ILSpy.csproj | 1 + ILSpy/Images/AccessOverlayIcon.cs | 1 + ILSpy/Images/ILSpyNewIconList.txt | 2 +- ILSpy/Images/Images.cs | 4 ++++ ILSpy/Images/OverlayPrivateProtected.png | Bin 0 -> 562 bytes ILSpy/TreeNodes/EventTreeNode.cs | 3 ++- ILSpy/TreeNodes/FieldTreeNode.cs | 3 ++- ILSpy/TreeNodes/MethodTreeNode.cs | 3 ++- ILSpy/TreeNodes/PropertyTreeNode.cs | 3 ++- ILSpy/TreeNodes/TypeTreeNode.cs | 4 +++- 10 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 ILSpy/Images/OverlayPrivateProtected.png diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj index e685145a9..2650580fc 100644 --- a/ILSpy/ILSpy.csproj +++ b/ILSpy/ILSpy.csproj @@ -349,6 +349,7 @@ + diff --git a/ILSpy/Images/AccessOverlayIcon.cs b/ILSpy/Images/AccessOverlayIcon.cs index ca11c46c4..5db1d75d3 100644 --- a/ILSpy/Images/AccessOverlayIcon.cs +++ b/ILSpy/Images/AccessOverlayIcon.cs @@ -26,6 +26,7 @@ namespace ICSharpCode.ILSpy Internal, ProtectedInternal, Private, + PrivateProtected, CompilerControlled } } diff --git a/ILSpy/Images/ILSpyNewIconList.txt b/ILSpy/Images/ILSpyNewIconList.txt index a2a35d8eb..deeeaf3e2 100644 --- a/ILSpy/Images/ILSpyNewIconList.txt +++ b/ILSpy/Images/ILSpyNewIconList.txt @@ -39,7 +39,7 @@ OverlayProtected.png new (Fugue derived) OverlayProtectedInternal.png new (Fugue derived) OverlayStatic.png new (Fugue derived) PInvokeMethod.png new (Fugue-Icon-Mashup) -PrivateInternal.png new (Fugue derived) +OverlayPrivateProtected.png new (Fugue derived) Property.png ClassBrowserIcons\Icons.16x16.Property.png ReferenceFolder.Closed.png ProjectBrowserIcons\ReferenceFolder.Closed.png ReferenceFolder.Open.png ProjectBrowserIcons\ReferenceFolder.Open.png diff --git a/ILSpy/Images/Images.cs b/ILSpy/Images/Images.cs index a8376f646..2bf680b3d 100644 --- a/ILSpy/Images/Images.cs +++ b/ILSpy/Images/Images.cs @@ -95,6 +95,7 @@ namespace ICSharpCode.ILSpy private static readonly BitmapImage OverlayInternal = LoadBitmap("OverlayInternal"); private static readonly BitmapImage OverlayProtectedInternal = LoadBitmap("OverlayProtectedInternal"); private static readonly BitmapImage OverlayPrivate = LoadBitmap("OverlayPrivate"); + private static readonly BitmapImage OverlayPrivateProtected = LoadBitmap("OverlayPrivateProtected"); private static readonly BitmapImage OverlayCompilerControlled = LoadBitmap("OverlayCompilerControlled"); private static readonly BitmapImage OverlayStatic = LoadBitmap("OverlayStatic"); @@ -295,6 +296,9 @@ namespace ICSharpCode.ILSpy case AccessOverlayIcon.Private: overlayImage = Images.OverlayPrivate; break; + case AccessOverlayIcon.PrivateProtected: + overlayImage = Images.OverlayPrivateProtected; + break; case AccessOverlayIcon.CompilerControlled: overlayImage = Images.OverlayCompilerControlled; break; diff --git a/ILSpy/Images/OverlayPrivateProtected.png b/ILSpy/Images/OverlayPrivateProtected.png new file mode 100644 index 0000000000000000000000000000000000000000..497753285b37332db45777cdd969ccacbc2349c5 GIT binary patch literal 562 zcmV-20?qx2P)pF8FWQhbW?9;ba!ELWdLwtX>N2bZe?^J zG%heMF*(%MvSa`N0k26!K~y+TV;BWA0{iQk8Mjq2>24@v%G?OVJF1y<4>T|{LZxv7 zWo6~CqN2k8DZa9sm)5Es{C%tS?uTdDk0BtpX2;w&lJsT{~tB}-_fqHWNAL5K2$j-0BHu|)$LJ?lm35O`+q`>zUfU~Li!R6haU;e*Z`2YXyN&oL}3;6%< zO6LCqGpx>(`7?M!wV(o^0X-WwZ1}%r%N8Ks{J*z0{{Qm6;QtSfHvK=fBJ}&RMy;cT z-VC|*p$tq=EvUfA$f*0yojd=_%gg^473TlXN>BP<8KeCF>6zyLmo_KEX;o+GhCMGsXK|x_28ynkBS2f1x&(5{} z_tIp%mT1mk3sp)yh}36r3fE=W3! Date: Tue, 19 Dec 2017 23:30:48 +0100 Subject: [PATCH 15/36] Fix #1014: fix assembly load errors causing ILSpy to crash --- ILSpy/MainWindow.xaml.cs | 4 ++-- ILSpy/SearchPane.cs | 2 +- ILSpy/TreeNodes/Analyzer/AnalyzerEntityTreeNode.cs | 2 +- ILSpy/TreeNodes/AssemblyListTreeNode.cs | 2 +- ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs | 2 +- ILSpy/TreeNodes/AssemblyTreeNode.cs | 7 ++++--- ILSpy/TreeNodes/DerivedTypesTreeNode.cs | 2 +- TestPlugin/ContextMenuCommand.cs | 2 +- 8 files changed, 12 insertions(+), 11 deletions(-) diff --git a/ILSpy/MainWindow.xaml.cs b/ILSpy/MainWindow.xaml.cs index 419658af8..93c0eb658 100644 --- a/ILSpy/MainWindow.xaml.cs +++ b/ILSpy/MainWindow.xaml.cs @@ -273,7 +273,7 @@ namespace ICSharpCode.ILSpy } } else { foreach (LoadedAssembly asm in commandLineLoadedAssemblies) { - ModuleDefinition def = asm.GetModuleDefinitionAsync().Result; + ModuleDefinition def = asm.GetModuleDefinitionOrNull(); if (def != null) { MemberReference mr = XmlDocKeyProvider.FindMemberByKey(def, args.NavigateTo); if (mr != null) { @@ -292,7 +292,7 @@ namespace ICSharpCode.ILSpy } else if (commandLineLoadedAssemblies.Count == 1) { // NavigateTo == null and an assembly was given on the command-line: // Select the newly loaded assembly - JumpToReference(commandLineLoadedAssemblies[0].GetModuleDefinitionAsync().Result); + JumpToReference(commandLineLoadedAssemblies[0].GetModuleDefinitionOrNull()); } if (args.Search != null) { diff --git a/ILSpy/SearchPane.cs b/ILSpy/SearchPane.cs index 39a143f03..364fe3fe3 100644 --- a/ILSpy/SearchPane.cs +++ b/ILSpy/SearchPane.cs @@ -216,7 +216,7 @@ namespace ICSharpCode.ILSpy try { var searcher = GetSearchStrategy(searchMode, searchTerm); foreach (var loadedAssembly in assemblies) { - ModuleDefinition module = loadedAssembly.GetModuleDefinitionAsync().Result; + ModuleDefinition module = loadedAssembly.GetModuleDefinitionOrNull(); if (module == null) continue; CancellationToken cancellationToken = cts.Token; diff --git a/ILSpy/TreeNodes/Analyzer/AnalyzerEntityTreeNode.cs b/ILSpy/TreeNodes/Analyzer/AnalyzerEntityTreeNode.cs index afd890465..5f7b3d0b9 100644 --- a/ILSpy/TreeNodes/Analyzer/AnalyzerEntityTreeNode.cs +++ b/ILSpy/TreeNodes/Analyzer/AnalyzerEntityTreeNode.cs @@ -38,7 +38,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer public override bool HandleAssemblyListChanged(ICollection removedAssemblies, ICollection addedAssemblies) { foreach (LoadedAssembly asm in removedAssemblies) { - if (this.Member.Module == asm.GetModuleDefinitionAsync().Result) + if (this.Member.Module == asm.GetModuleDefinitionOrNull()) return false; // remove this node } this.Children.RemoveAll( diff --git a/ILSpy/TreeNodes/AssemblyListTreeNode.cs b/ILSpy/TreeNodes/AssemblyListTreeNode.cs index 428967a7b..602fb4614 100644 --- a/ILSpy/TreeNodes/AssemblyListTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyListTreeNode.cs @@ -185,7 +185,7 @@ namespace ICSharpCode.ILSpy.TreeNodes return null; App.Current.Dispatcher.VerifyAccess(); foreach (AssemblyTreeNode node in this.Children) { - if (node.LoadedAssembly.IsLoaded && node.LoadedAssembly.GetModuleDefinitionAsync().Result == module) + if (node.LoadedAssembly.IsLoaded && node.LoadedAssembly.GetModuleDefinitionOrNull() == module) return node; } return null; diff --git a/ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs b/ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs index 6c3d1ef42..fa8a9b243 100644 --- a/ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs @@ -77,7 +77,7 @@ namespace ICSharpCode.ILSpy.TreeNodes if (assemblyListNode != null) { var refNode = assemblyListNode.FindAssemblyNode(parentAssembly.LoadedAssembly.LookupReferencedAssembly(r)); if (refNode != null) { - ModuleDefinition module = refNode.LoadedAssembly.GetModuleDefinitionAsync().Result; + ModuleDefinition module = refNode.LoadedAssembly.GetModuleDefinitionOrNull(); if (module != null) { foreach (var childRef in module.AssemblyReferences) this.Children.Add(new AssemblyReferenceTreeNode(childRef, refNode)); diff --git a/ILSpy/TreeNodes/AssemblyTreeNode.cs b/ILSpy/TreeNodes/AssemblyTreeNode.cs index 8e418b6ef..fe10213c1 100644 --- a/ILSpy/TreeNodes/AssemblyTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyTreeNode.cs @@ -145,7 +145,7 @@ namespace ICSharpCode.ILSpy.TreeNodes protected override void LoadChildren() { - ModuleDefinition moduleDefinition = assembly.GetModuleDefinitionAsync().Result; + ModuleDefinition moduleDefinition = assembly.GetModuleDefinitionOrNull(); if (moduleDefinition == null) { // if we crashed on loading, then we don't have any children return; @@ -396,8 +396,9 @@ namespace ICSharpCode.ILSpy.TreeNodes return; foreach (var node in context.SelectedTreeNodes) { var la = ((AssemblyTreeNode)node).LoadedAssembly; - if (!la.HasLoadError) { - foreach (var assyRef in la.GetModuleDefinitionAsync().Result.AssemblyReferences) { + var module = la.GetModuleDefinitionOrNull(); + if (module != null) { + foreach (var assyRef in module.AssemblyReferences) { la.LookupReferencedAssembly(assyRef); } } diff --git a/ILSpy/TreeNodes/DerivedTypesTreeNode.cs b/ILSpy/TreeNodes/DerivedTypesTreeNode.cs index 881cf2104..696afc8c9 100644 --- a/ILSpy/TreeNodes/DerivedTypesTreeNode.cs +++ b/ILSpy/TreeNodes/DerivedTypesTreeNode.cs @@ -60,7 +60,7 @@ namespace ICSharpCode.ILSpy.TreeNodes IEnumerable FetchChildren(CancellationToken cancellationToken) { // FetchChildren() runs on the main thread; but the enumerator will be consumed on a background thread - var assemblies = list.GetAssemblies().Select(node => node.GetModuleDefinitionAsync().Result).Where(asm => asm != null).ToArray(); + var assemblies = list.GetAssemblies().Select(node => node.GetModuleDefinitionOrNull()).Where(asm => asm != null).ToArray(); return FindDerivedTypes(type, assemblies, cancellationToken); } diff --git a/TestPlugin/ContextMenuCommand.cs b/TestPlugin/ContextMenuCommand.cs index c67d38879..8305e3535 100644 --- a/TestPlugin/ContextMenuCommand.cs +++ b/TestPlugin/ContextMenuCommand.cs @@ -27,7 +27,7 @@ namespace TestPlugin if (context.SelectedTreeNodes == null) return; AssemblyTreeNode node = (AssemblyTreeNode)context.SelectedTreeNodes[0]; - AssemblyDefinition asm = node.LoadedAssembly.GetAssemblyDefinitionAsync().Result; + AssemblyDefinition asm = node.LoadedAssembly.GetAssemblyDefinitionOrNull(); if (asm != null) { SaveFileDialog dlg = new SaveFileDialog(); dlg.FileName = node.LoadedAssembly.FileName; From 871f28c90fea972a723537236651dac8bf3081b1 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Tue, 19 Dec 2017 23:43:08 +0100 Subject: [PATCH 16/36] Set version number to 3.0.1 --- ILSpy/Properties/AssemblyInfo.template.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ILSpy/Properties/AssemblyInfo.template.cs b/ILSpy/Properties/AssemblyInfo.template.cs index b40fac15c..eb322ec17 100644 --- a/ILSpy/Properties/AssemblyInfo.template.cs +++ b/ILSpy/Properties/AssemblyInfo.template.cs @@ -40,7 +40,7 @@ internal static class RevisionClass { public const string Major = "3"; public const string Minor = "0"; - public const string Build = "0"; + public const string Build = "1"; public const string Revision = "$INSERTREVISION$"; public const string VersionName = null; From d18b4c2a1faddf2a8f4130e4ea13cd8cf80ddc99 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Tue, 19 Dec 2017 23:30:48 +0100 Subject: [PATCH 17/36] Fix #1014: fix assembly load errors causing ILSpy to crash --- ILSpy/MainWindow.xaml.cs | 4 ++-- ILSpy/SearchPane.cs | 2 +- ILSpy/TreeNodes/Analyzer/AnalyzerEntityTreeNode.cs | 2 +- ILSpy/TreeNodes/AssemblyListTreeNode.cs | 2 +- ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs | 2 +- ILSpy/TreeNodes/AssemblyTreeNode.cs | 7 ++++--- ILSpy/TreeNodes/DerivedTypesTreeNode.cs | 2 +- TestPlugin/ContextMenuCommand.cs | 2 +- 8 files changed, 12 insertions(+), 11 deletions(-) diff --git a/ILSpy/MainWindow.xaml.cs b/ILSpy/MainWindow.xaml.cs index 419658af8..93c0eb658 100644 --- a/ILSpy/MainWindow.xaml.cs +++ b/ILSpy/MainWindow.xaml.cs @@ -273,7 +273,7 @@ namespace ICSharpCode.ILSpy } } else { foreach (LoadedAssembly asm in commandLineLoadedAssemblies) { - ModuleDefinition def = asm.GetModuleDefinitionAsync().Result; + ModuleDefinition def = asm.GetModuleDefinitionOrNull(); if (def != null) { MemberReference mr = XmlDocKeyProvider.FindMemberByKey(def, args.NavigateTo); if (mr != null) { @@ -292,7 +292,7 @@ namespace ICSharpCode.ILSpy } else if (commandLineLoadedAssemblies.Count == 1) { // NavigateTo == null and an assembly was given on the command-line: // Select the newly loaded assembly - JumpToReference(commandLineLoadedAssemblies[0].GetModuleDefinitionAsync().Result); + JumpToReference(commandLineLoadedAssemblies[0].GetModuleDefinitionOrNull()); } if (args.Search != null) { diff --git a/ILSpy/SearchPane.cs b/ILSpy/SearchPane.cs index 39a143f03..364fe3fe3 100644 --- a/ILSpy/SearchPane.cs +++ b/ILSpy/SearchPane.cs @@ -216,7 +216,7 @@ namespace ICSharpCode.ILSpy try { var searcher = GetSearchStrategy(searchMode, searchTerm); foreach (var loadedAssembly in assemblies) { - ModuleDefinition module = loadedAssembly.GetModuleDefinitionAsync().Result; + ModuleDefinition module = loadedAssembly.GetModuleDefinitionOrNull(); if (module == null) continue; CancellationToken cancellationToken = cts.Token; diff --git a/ILSpy/TreeNodes/Analyzer/AnalyzerEntityTreeNode.cs b/ILSpy/TreeNodes/Analyzer/AnalyzerEntityTreeNode.cs index afd890465..5f7b3d0b9 100644 --- a/ILSpy/TreeNodes/Analyzer/AnalyzerEntityTreeNode.cs +++ b/ILSpy/TreeNodes/Analyzer/AnalyzerEntityTreeNode.cs @@ -38,7 +38,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer public override bool HandleAssemblyListChanged(ICollection removedAssemblies, ICollection addedAssemblies) { foreach (LoadedAssembly asm in removedAssemblies) { - if (this.Member.Module == asm.GetModuleDefinitionAsync().Result) + if (this.Member.Module == asm.GetModuleDefinitionOrNull()) return false; // remove this node } this.Children.RemoveAll( diff --git a/ILSpy/TreeNodes/AssemblyListTreeNode.cs b/ILSpy/TreeNodes/AssemblyListTreeNode.cs index 428967a7b..602fb4614 100644 --- a/ILSpy/TreeNodes/AssemblyListTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyListTreeNode.cs @@ -185,7 +185,7 @@ namespace ICSharpCode.ILSpy.TreeNodes return null; App.Current.Dispatcher.VerifyAccess(); foreach (AssemblyTreeNode node in this.Children) { - if (node.LoadedAssembly.IsLoaded && node.LoadedAssembly.GetModuleDefinitionAsync().Result == module) + if (node.LoadedAssembly.IsLoaded && node.LoadedAssembly.GetModuleDefinitionOrNull() == module) return node; } return null; diff --git a/ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs b/ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs index 6c3d1ef42..fa8a9b243 100644 --- a/ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs @@ -77,7 +77,7 @@ namespace ICSharpCode.ILSpy.TreeNodes if (assemblyListNode != null) { var refNode = assemblyListNode.FindAssemblyNode(parentAssembly.LoadedAssembly.LookupReferencedAssembly(r)); if (refNode != null) { - ModuleDefinition module = refNode.LoadedAssembly.GetModuleDefinitionAsync().Result; + ModuleDefinition module = refNode.LoadedAssembly.GetModuleDefinitionOrNull(); if (module != null) { foreach (var childRef in module.AssemblyReferences) this.Children.Add(new AssemblyReferenceTreeNode(childRef, refNode)); diff --git a/ILSpy/TreeNodes/AssemblyTreeNode.cs b/ILSpy/TreeNodes/AssemblyTreeNode.cs index 8e418b6ef..fe10213c1 100644 --- a/ILSpy/TreeNodes/AssemblyTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyTreeNode.cs @@ -145,7 +145,7 @@ namespace ICSharpCode.ILSpy.TreeNodes protected override void LoadChildren() { - ModuleDefinition moduleDefinition = assembly.GetModuleDefinitionAsync().Result; + ModuleDefinition moduleDefinition = assembly.GetModuleDefinitionOrNull(); if (moduleDefinition == null) { // if we crashed on loading, then we don't have any children return; @@ -396,8 +396,9 @@ namespace ICSharpCode.ILSpy.TreeNodes return; foreach (var node in context.SelectedTreeNodes) { var la = ((AssemblyTreeNode)node).LoadedAssembly; - if (!la.HasLoadError) { - foreach (var assyRef in la.GetModuleDefinitionAsync().Result.AssemblyReferences) { + var module = la.GetModuleDefinitionOrNull(); + if (module != null) { + foreach (var assyRef in module.AssemblyReferences) { la.LookupReferencedAssembly(assyRef); } } diff --git a/ILSpy/TreeNodes/DerivedTypesTreeNode.cs b/ILSpy/TreeNodes/DerivedTypesTreeNode.cs index 881cf2104..696afc8c9 100644 --- a/ILSpy/TreeNodes/DerivedTypesTreeNode.cs +++ b/ILSpy/TreeNodes/DerivedTypesTreeNode.cs @@ -60,7 +60,7 @@ namespace ICSharpCode.ILSpy.TreeNodes IEnumerable FetchChildren(CancellationToken cancellationToken) { // FetchChildren() runs on the main thread; but the enumerator will be consumed on a background thread - var assemblies = list.GetAssemblies().Select(node => node.GetModuleDefinitionAsync().Result).Where(asm => asm != null).ToArray(); + var assemblies = list.GetAssemblies().Select(node => node.GetModuleDefinitionOrNull()).Where(asm => asm != null).ToArray(); return FindDerivedTypes(type, assemblies, cancellationToken); } diff --git a/TestPlugin/ContextMenuCommand.cs b/TestPlugin/ContextMenuCommand.cs index c67d38879..8305e3535 100644 --- a/TestPlugin/ContextMenuCommand.cs +++ b/TestPlugin/ContextMenuCommand.cs @@ -27,7 +27,7 @@ namespace TestPlugin if (context.SelectedTreeNodes == null) return; AssemblyTreeNode node = (AssemblyTreeNode)context.SelectedTreeNodes[0]; - AssemblyDefinition asm = node.LoadedAssembly.GetAssemblyDefinitionAsync().Result; + AssemblyDefinition asm = node.LoadedAssembly.GetAssemblyDefinitionOrNull(); if (asm != null) { SaveFileDialog dlg = new SaveFileDialog(); dlg.FileName = node.LoadedAssembly.FileName; From c4bafdde2e58ae0fdbc3db6c896f4a2f870884f9 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 20 Dec 2017 20:51:12 +0100 Subject: [PATCH 18/36] Fix assembly reference logging bug: References found in the assembly list should not be marked unresolved. --- .../DotNetCore/DotNetCorePathFinderExtensions.cs | 15 +++++++++++++++ ILSpy/LoadedAssembly.cs | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinderExtensions.cs b/ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinderExtensions.cs index 5ab6e3139..7fb8f2561 100644 --- a/ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinderExtensions.cs +++ b/ICSharpCode.Decompiler/DotNetCore/DotNetCorePathFinderExtensions.cs @@ -43,6 +43,21 @@ namespace ICSharpCode.Decompiler } } + public void AddMessageOnce(string fullName, MessageKind kind, string message) + { + lock (loadedAssemblyReferences) { + if (!loadedAssemblyReferences.TryGetValue(fullName, out var referenceInfo)) { + referenceInfo = new UnresolvedAssemblyNameReference(fullName); + loadedAssemblyReferences.Add(fullName, referenceInfo); + referenceInfo.Messages.Add((kind, message)); + } else { + var lastMsg = referenceInfo.Messages.LastOrDefault(); + if (kind != lastMsg.Item1 && message != lastMsg.Item2) + referenceInfo.Messages.Add((kind, message)); + } + } + } + public bool TryGetInfo(string fullName, out UnresolvedAssemblyNameReference info) { lock (loadedAssemblyReferences) { diff --git a/ILSpy/LoadedAssembly.cs b/ILSpy/LoadedAssembly.cs index 483136b3b..6ec5c113a 100644 --- a/ILSpy/LoadedAssembly.cs +++ b/ILSpy/LoadedAssembly.cs @@ -267,6 +267,7 @@ namespace ICSharpCode.ILSpy foreach (LoadedAssembly loaded in assemblyList.GetAssemblies()) { var asmDef = loaded.GetAssemblyDefinitionOrNull(); if (asmDef != null && data.fullName.Equals(data.isWinRT ? asmDef.Name.Name : asmDef.FullName, StringComparison.OrdinalIgnoreCase)) { + LoadedAssemblyReferencesInfo.AddMessageOnce(data.fullName, MessageKind.Info, "Success - Found in Assembly List"); return loaded; } } @@ -295,7 +296,7 @@ namespace ICSharpCode.ILSpy LoadedAssemblyReferencesInfo.AddMessage(data.fullName, MessageKind.Info, "Success - Loading from: " + file); asm = new LoadedAssembly(assemblyList, file) { IsAutoLoaded = true }; } else { - LoadedAssemblyReferencesInfo.AddMessage(data.fullName, MessageKind.Error, "Could not find reference: " + data.fullName); + LoadedAssemblyReferencesInfo.AddMessageOnce(data.fullName, MessageKind.Error, "Could not find reference: " + data.fullName); return null; } loadingAssemblies.Add(file, asm); From 9da1d4c1bb3559baff5310f25e67aa168d5893d2 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 20 Dec 2017 21:24:32 +0100 Subject: [PATCH 19/36] Fix "Show/Hide internal types and members option" for members. --- ILSpy/TreeNodes/EventTreeNode.cs | 2 ++ ILSpy/TreeNodes/FieldTreeNode.cs | 2 ++ ILSpy/TreeNodes/MethodTreeNode.cs | 2 ++ ILSpy/TreeNodes/PropertyTreeNode.cs | 2 ++ 4 files changed, 8 insertions(+) diff --git a/ILSpy/TreeNodes/EventTreeNode.cs b/ILSpy/TreeNodes/EventTreeNode.cs index 0885db852..6a9679c33 100644 --- a/ILSpy/TreeNodes/EventTreeNode.cs +++ b/ILSpy/TreeNodes/EventTreeNode.cs @@ -90,6 +90,8 @@ namespace ICSharpCode.ILSpy.TreeNodes public override FilterResult Filter(FilterSettings settings) { + if (!settings.ShowInternalApi && !IsPublicAPI) + return FilterResult.Hidden; if (settings.SearchTermMatches(EventDefinition.Name) && settings.Language.ShowMember(EventDefinition)) return FilterResult.Match; else diff --git a/ILSpy/TreeNodes/FieldTreeNode.cs b/ILSpy/TreeNodes/FieldTreeNode.cs index 61d4e30ee..e53070919 100644 --- a/ILSpy/TreeNodes/FieldTreeNode.cs +++ b/ILSpy/TreeNodes/FieldTreeNode.cs @@ -104,6 +104,8 @@ namespace ICSharpCode.ILSpy.TreeNodes public override FilterResult Filter(FilterSettings settings) { + if (!settings.ShowInternalApi && !IsPublicAPI) + return FilterResult.Hidden; if (settings.SearchTermMatches(FieldDefinition.Name) && settings.Language.ShowMember(FieldDefinition)) return FilterResult.Match; else diff --git a/ILSpy/TreeNodes/MethodTreeNode.cs b/ILSpy/TreeNodes/MethodTreeNode.cs index 4744aa761..1ddf59ab1 100644 --- a/ILSpy/TreeNodes/MethodTreeNode.cs +++ b/ILSpy/TreeNodes/MethodTreeNode.cs @@ -126,6 +126,8 @@ namespace ICSharpCode.ILSpy.TreeNodes public override FilterResult Filter(FilterSettings settings) { + if (!settings.ShowInternalApi && !IsPublicAPI) + return FilterResult.Hidden; if (settings.SearchTermMatches(MethodDefinition.Name) && settings.Language.ShowMember(MethodDefinition)) return FilterResult.Match; else diff --git a/ILSpy/TreeNodes/PropertyTreeNode.cs b/ILSpy/TreeNodes/PropertyTreeNode.cs index 4e92ccc8d..07c6cd779 100644 --- a/ILSpy/TreeNodes/PropertyTreeNode.cs +++ b/ILSpy/TreeNodes/PropertyTreeNode.cs @@ -158,6 +158,8 @@ namespace ICSharpCode.ILSpy.TreeNodes public override FilterResult Filter(FilterSettings settings) { + if (!settings.ShowInternalApi && !IsPublicAPI) + return FilterResult.Hidden; if (settings.SearchTermMatches(PropertyDefinition.Name) && settings.Language.ShowMember(PropertyDefinition)) return FilterResult.Match; else From 10b932ae0bbf1900cfff393835b3a917dbd5e438 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 20 Dec 2017 21:51:35 +0100 Subject: [PATCH 20/36] Fix assembly loading glitch when decompiling assembly nodes (assembly attributes + header) --- ILSpy/LoadedAssembly.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ILSpy/LoadedAssembly.cs b/ILSpy/LoadedAssembly.cs index 6ec5c113a..fd856d8c8 100644 --- a/ILSpy/LoadedAssembly.cs +++ b/ILSpy/LoadedAssembly.cs @@ -272,9 +272,6 @@ namespace ICSharpCode.ILSpy } } - if (assemblyLoadDisableCount > 0) - return null; - if (data.isWinRT) { file = Path.Combine(Environment.SystemDirectory, "WinMetadata", data.fullName + ".winmd"); } else { @@ -292,6 +289,9 @@ namespace ICSharpCode.ILSpy if (file != null && loadingAssemblies.TryGetValue(file, out asm)) return asm; + if (assemblyLoadDisableCount > 0) + return null; + if (file != null) { LoadedAssemblyReferencesInfo.AddMessage(data.fullName, MessageKind.Info, "Success - Loading from: " + file); asm = new LoadedAssembly(assemblyList, file) { IsAutoLoaded = true }; From da847e726ead51dfc269afa749b849f6bff79d8e Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 21 Dec 2017 07:53:25 +0100 Subject: [PATCH 21/36] Push VSIX to artifacts on build server. --- appveyor.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 64a4a9cea..ac9a4d993 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -34,5 +34,7 @@ for: artifacts: - path: ILSpy_binaries.zip name: ILSpy %APPVEYOR_REPO_BRANCH% %ILSPY_VERSION_NUMBER% binaries + - path: '**\*.vsix' + name: ILSpy %APPVEYOR_REPO_BRANCH% %ILSPY_VERSION_NUMBER% VS AddIn - path: '**\*.nupkg' - name: ICSharpCode.Decompiler %APPVEYOR_REPO_BRANCH% %ILSPY_VERSION_NUMBER% NuGet \ No newline at end of file + name: ICSharpCode.Decompiler %APPVEYOR_REPO_BRANCH% %ILSPY_VERSION_NUMBER% NuGet From b4974eb559fb03fd6d6555378e5048fddc86e919 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 21 Dec 2017 14:10:13 +0100 Subject: [PATCH 22/36] Add preparerelease.bat --- BuildTools/update-assemblyinfo.ps1 | 9 ++++++--- appveyor.yml | 1 + preparerelease.bat | 29 +++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 preparerelease.bat diff --git a/BuildTools/update-assemblyinfo.ps1 b/BuildTools/update-assemblyinfo.ps1 index 06ef977d2..da1e408e2 100644 --- a/BuildTools/update-assemblyinfo.ps1 +++ b/BuildTools/update-assemblyinfo.ps1 @@ -3,6 +3,8 @@ $baseCommit = "d779383cb85003d6dabeb976f0845631e07bf463"; $baseCommitRev = 1; +$masterBranches = @("master", "3.0.x"); + $globalAssemblyInfoTemplateFile = "ILSpy/Properties/AssemblyInfo.template.cs"; function Test-File([string]$filename) { @@ -96,10 +98,11 @@ try { $branchName = gitBranch; $gitCommitHash = gitCommitHash; - $postfixBranchName = ""; - if ($branchName -ne "master") { + if ($masterBranches -contains $branchName) { + $postfixBranchName = ""; + } else { $postfixBranchName = "-$branchName"; - } + } if ($versionName -eq "null") { $versionName = ""; diff --git a/appveyor.yml b/appveyor.yml index ac9a4d993..9e8bc1b46 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -31,6 +31,7 @@ for: - branches: only: - master + - 3.0.x artifacts: - path: ILSpy_binaries.zip name: ILSpy %APPVEYOR_REPO_BRANCH% %ILSPY_VERSION_NUMBER% binaries diff --git a/preparerelease.bat b/preparerelease.bat new file mode 100644 index 000000000..60fadaabe --- /dev/null +++ b/preparerelease.bat @@ -0,0 +1,29 @@ +@setlocal enabledelayedexpansion +@set MSBUILD= +@for /D %%M in ("%ProgramFiles(x86)%\Microsoft Visual Studio\2017"\*) do ( + @if exist "%%M\MSBuild\15.0\Bin\MSBuild.exe" ( + @set "MSBUILD=%%M\MSBuild\15.0\Bin\MSBuild.exe" + ) +) +@if "%MSBUILD%" == "" ( + @echo Could not find VS2017 MSBuild + @exit /b 1 +) +@del ICSharpCode.Decompiler\bin\Release\*.nupkg +"%MSBUILD%" ILSpy.sln /p:Configuration=Release "/p:Platform=Any CPU" +@IF %ERRORLEVEL% NEQ 0 ( + @pause + @exit /b 1 +) +@if not exist "%ProgramFiles%\7-zip\7z.exe" ( + @echo Could not find 7zip + @exit /b 1 +) +@del artifacts.zip +@rmdir /Q /S artifacts +@mkdir artifacts +"%ProgramFiles%\7-zip\7z.exe" a artifacts\ILSpy_binaries.zip %cd%\ILSpy\bin\Release\net46\*.dll %cd%\ILSpy\bin\Release\net46\*.exe %cd%\ILSpy\bin\Release\net46\*.config +@copy ILSpy.AddIn\bin\Release\net46\ILSpy.AddIn.vsix artifacts\ +@copy ICSharpCode.Decompiler\bin\Release\*.nupkg artifacts\ +"%ProgramFiles%\7-zip\7z.exe" a artifacts.zip %cd%\artifacts\* +@exit /b 0 From bb23d0d7ba020c842702a043a063be196e12a680 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 21 Dec 2017 07:53:25 +0100 Subject: [PATCH 23/36] Push VSIX to artifacts on build server. --- appveyor.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 64a4a9cea..ac9a4d993 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -34,5 +34,7 @@ for: artifacts: - path: ILSpy_binaries.zip name: ILSpy %APPVEYOR_REPO_BRANCH% %ILSPY_VERSION_NUMBER% binaries + - path: '**\*.vsix' + name: ILSpy %APPVEYOR_REPO_BRANCH% %ILSPY_VERSION_NUMBER% VS AddIn - path: '**\*.nupkg' - name: ICSharpCode.Decompiler %APPVEYOR_REPO_BRANCH% %ILSPY_VERSION_NUMBER% NuGet \ No newline at end of file + name: ICSharpCode.Decompiler %APPVEYOR_REPO_BRANCH% %ILSPY_VERSION_NUMBER% NuGet From 98b22f3f1fa8864dd993d2d9a41490943575d78b Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 21 Dec 2017 14:10:13 +0100 Subject: [PATCH 24/36] Add preparerelease.bat --- BuildTools/update-assemblyinfo.ps1 | 9 ++++++--- appveyor.yml | 1 + preparerelease.bat | 29 +++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 preparerelease.bat diff --git a/BuildTools/update-assemblyinfo.ps1 b/BuildTools/update-assemblyinfo.ps1 index 06ef977d2..da1e408e2 100644 --- a/BuildTools/update-assemblyinfo.ps1 +++ b/BuildTools/update-assemblyinfo.ps1 @@ -3,6 +3,8 @@ $baseCommit = "d779383cb85003d6dabeb976f0845631e07bf463"; $baseCommitRev = 1; +$masterBranches = @("master", "3.0.x"); + $globalAssemblyInfoTemplateFile = "ILSpy/Properties/AssemblyInfo.template.cs"; function Test-File([string]$filename) { @@ -96,10 +98,11 @@ try { $branchName = gitBranch; $gitCommitHash = gitCommitHash; - $postfixBranchName = ""; - if ($branchName -ne "master") { + if ($masterBranches -contains $branchName) { + $postfixBranchName = ""; + } else { $postfixBranchName = "-$branchName"; - } + } if ($versionName -eq "null") { $versionName = ""; diff --git a/appveyor.yml b/appveyor.yml index ac9a4d993..9e8bc1b46 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -31,6 +31,7 @@ for: - branches: only: - master + - 3.0.x artifacts: - path: ILSpy_binaries.zip name: ILSpy %APPVEYOR_REPO_BRANCH% %ILSPY_VERSION_NUMBER% binaries diff --git a/preparerelease.bat b/preparerelease.bat new file mode 100644 index 000000000..60fadaabe --- /dev/null +++ b/preparerelease.bat @@ -0,0 +1,29 @@ +@setlocal enabledelayedexpansion +@set MSBUILD= +@for /D %%M in ("%ProgramFiles(x86)%\Microsoft Visual Studio\2017"\*) do ( + @if exist "%%M\MSBuild\15.0\Bin\MSBuild.exe" ( + @set "MSBUILD=%%M\MSBuild\15.0\Bin\MSBuild.exe" + ) +) +@if "%MSBUILD%" == "" ( + @echo Could not find VS2017 MSBuild + @exit /b 1 +) +@del ICSharpCode.Decompiler\bin\Release\*.nupkg +"%MSBUILD%" ILSpy.sln /p:Configuration=Release "/p:Platform=Any CPU" +@IF %ERRORLEVEL% NEQ 0 ( + @pause + @exit /b 1 +) +@if not exist "%ProgramFiles%\7-zip\7z.exe" ( + @echo Could not find 7zip + @exit /b 1 +) +@del artifacts.zip +@rmdir /Q /S artifacts +@mkdir artifacts +"%ProgramFiles%\7-zip\7z.exe" a artifacts\ILSpy_binaries.zip %cd%\ILSpy\bin\Release\net46\*.dll %cd%\ILSpy\bin\Release\net46\*.exe %cd%\ILSpy\bin\Release\net46\*.config +@copy ILSpy.AddIn\bin\Release\net46\ILSpy.AddIn.vsix artifacts\ +@copy ICSharpCode.Decompiler\bin\Release\*.nupkg artifacts\ +"%ProgramFiles%\7-zip\7z.exe" a artifacts.zip %cd%\artifacts\* +@exit /b 0 From c3e1f4100914b3a703e73c0ba12f5300a30867b7 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 21 Dec 2017 14:21:08 +0100 Subject: [PATCH 25/36] Add 3.0.x branch handling to appveyor-install.ps1 --- BuildTools/appveyor-install.ps1 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/BuildTools/appveyor-install.ps1 b/BuildTools/appveyor-install.ps1 index 63afea63c..7edf389ee 100644 --- a/BuildTools/appveyor-install.ps1 +++ b/BuildTools/appveyor-install.ps1 @@ -3,6 +3,8 @@ $ErrorActionPreference = "Stop" $baseCommit = "d779383cb85003d6dabeb976f0845631e07bf463"; $baseCommitRev = 1; +$masterBranches = @("master", "3.0.x"); + $globalAssemblyInfoTemplateFile = "ILSpy/Properties/AssemblyInfo.template.cs"; $versionParts = @{}; @@ -18,10 +20,10 @@ if ($versionName -ne "null") { } else { $versionName = ""; } -if ($env:APPVEYOR_REPO_BRANCH -ne 'master') { - $branch = "-$env:APPVEYOR_REPO_BRANCH"; -} else { +if ($masterBranches -contains $env:APPVEYOR_REPO_BRANCH) { $branch = ""; +} else { + $branch = "-$env:APPVEYOR_REPO_BRANCH"; } if ($env:APPVEYOR_PULL_REQUEST_NUMBER) { $suffix = "-pr$env:APPVEYOR_PULL_REQUEST_NUMBER"; From a734955cc55fc473f7c419aabef99325c29c8cb3 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 21 Dec 2017 14:26:11 +0100 Subject: [PATCH 26/36] Push VSIX version number to 1.7.2 --- ILSpy.AddIn/source.extension.vsixmanifest | 2 +- appveyor.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ILSpy.AddIn/source.extension.vsixmanifest b/ILSpy.AddIn/source.extension.vsixmanifest index ef25f9c59..eea1fe093 100644 --- a/ILSpy.AddIn/source.extension.vsixmanifest +++ b/ILSpy.AddIn/source.extension.vsixmanifest @@ -1,7 +1,7 @@  - + ILSpy Integrates the ILSpy decompiler into Visual Studio. http://www.ilspy.net diff --git a/appveyor.yml b/appveyor.yml index 9e8bc1b46..6cb536409 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -36,6 +36,6 @@ for: - path: ILSpy_binaries.zip name: ILSpy %APPVEYOR_REPO_BRANCH% %ILSPY_VERSION_NUMBER% binaries - path: '**\*.vsix' - name: ILSpy %APPVEYOR_REPO_BRANCH% %ILSPY_VERSION_NUMBER% VS AddIn + name: ILSpy AddIn for Visual Studio - path: '**\*.nupkg' name: ICSharpCode.Decompiler %APPVEYOR_REPO_BRANCH% %ILSPY_VERSION_NUMBER% NuGet From 97efc7b7f5807c47c0316bd7ec51ebb661c4a4a4 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Thu, 11 Jan 2018 19:56:59 +0100 Subject: [PATCH 27/36] Fix some value type stack slots incorrectly being decompiled to a variable of type "object". --- .../CSharp/ExpressionBuilder.cs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs index c7c8b373a..035859733 100644 --- a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs @@ -436,12 +436,23 @@ namespace ICSharpCode.Decompiler.CSharp protected internal override TranslatedExpression VisitStLoc(StLoc inst, TranslationContext context) { var translatedValue = Translate(inst.Value, typeHint: inst.Variable.Type); - if (inst.Variable.Kind == VariableKind.StackSlot && inst.Variable.IsSingleDefinition - && inst.Variable.StackType == translatedValue.Type.GetStackType() - && translatedValue.Type.Kind != TypeKind.Null && !loadedVariablesSet.Contains(inst.Variable)) { - inst.Variable.Type = translatedValue.Type; + if (inst.Variable.Kind == VariableKind.StackSlot && !loadedVariablesSet.Contains(inst.Variable)) { + // Stack slots in the ILAst have inaccurate types (e.g. System.Object for StackType.O) + // so we should replace them with more accurate types where possible: + if ((inst.Variable.IsSingleDefinition || IsOtherValueType(translatedValue.Type)) + && inst.Variable.StackType == translatedValue.Type.GetStackType() + && translatedValue.Type.Kind != TypeKind.Null) { + inst.Variable.Type = translatedValue.Type; + } else if (inst.Value.MatchDefaultValue(out var type) && IsOtherValueType(type)) { + inst.Variable.Type = type; + } } return Assignment(ConvertVariable(inst.Variable).WithoutILInstruction(), translatedValue).WithILInstruction(inst); + + bool IsOtherValueType(IType type) + { + return type.IsReferenceType == false && type.GetStackType() == StackType.O; + } } protected internal override TranslatedExpression VisitComp(Comp inst, TranslationContext context) From 66d806b2d9a0a21407074d3867a81c846c900217 Mon Sep 17 00:00:00 2001 From: MikeFH Date: Mon, 15 Jan 2018 17:34:04 +0100 Subject: [PATCH 28/36] Add support for async main method --- .../ICSharpCode.Decompiler.Tests.csproj | 1 + .../PrettyTestRunner.cs | 69 ++--- .../TestCases/Pretty/AsyncMain.cs | 14 ++ .../TestCases/Pretty/AsyncMain.opt.roslyn.il | 209 +++++++++++++++ .../TestCases/Pretty/AsyncMain.roslyn.il | 237 ++++++++++++++++++ .../CSharp/CSharpDecompiler.cs | 2 + .../IL/ControlFlow/AsyncAwaitDecompiler.cs | 6 + 7 files changed, 509 insertions(+), 29 deletions(-) create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncMain.cs create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncMain.opt.roslyn.il create mode 100644 ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncMain.roslyn.il diff --git a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj index 4653b56ad..f92b8c612 100644 --- a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj +++ b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj @@ -63,6 +63,7 @@ + diff --git a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs index d246eed85..6e5e021a0 100644 --- a/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs @@ -69,167 +69,178 @@ namespace ICSharpCode.Decompiler.Tests [Test] public void HelloWorld() { - Run(); - Run(asmOptions: AssemblerOptions.UseDebug); + RunForLibrary(); + RunForLibrary(asmOptions: AssemblerOptions.UseDebug); } [Test] public void InlineAssignmentTest([ValueSource("defaultOptions")] CompilerOptions cscOptions) { - Run(cscOptions: cscOptions); + RunForLibrary(cscOptions: cscOptions); } [Test] public void CompoundAssignmentTest([ValueSource("defaultOptions")] CompilerOptions cscOptions) { - Run(cscOptions: cscOptions); + RunForLibrary(cscOptions: cscOptions); } [Test] public void ShortCircuit([ValueSource("defaultOptions")] CompilerOptions cscOptions) { - Run(cscOptions: cscOptions); + RunForLibrary(cscOptions: cscOptions); } [Test] public void ExceptionHandling([ValueSource("defaultOptions")] CompilerOptions cscOptions) { - Run(cscOptions: cscOptions); + RunForLibrary(cscOptions: cscOptions); } [Test] public void Switch([ValueSource("defaultOptions")] CompilerOptions cscOptions) { - Run(cscOptions: cscOptions); + RunForLibrary(cscOptions: cscOptions); } [Test] public void DelegateConstruction([ValueSource("defaultOptions")] CompilerOptions cscOptions) { - Run(cscOptions: cscOptions); + RunForLibrary(cscOptions: cscOptions); } [Test] public void AnonymousTypes([Values(CompilerOptions.None, CompilerOptions.Optimize)] CompilerOptions cscOptions) { - Run(cscOptions: cscOptions); + RunForLibrary(cscOptions: cscOptions); } [Test] public void Async([ValueSource("defaultOptions")] CompilerOptions cscOptions) { - Run(cscOptions: cscOptions); + RunForLibrary(cscOptions: cscOptions); } [Test] public void Lock([ValueSource("defaultOptions")] CompilerOptions cscOptions) { - Run(cscOptions: cscOptions); + RunForLibrary(cscOptions: cscOptions); } [Test] public void Using([ValueSource("defaultOptions")] CompilerOptions cscOptions) { - Run(cscOptions: cscOptions); + RunForLibrary(cscOptions: cscOptions); } [Test] public void LiftedOperators([ValueSource("defaultOptions")] CompilerOptions cscOptions) { - Run(cscOptions: cscOptions); + RunForLibrary(cscOptions: cscOptions); } [Test] public void Generics([ValueSource("defaultOptions")] CompilerOptions cscOptions) { - Run(cscOptions: cscOptions); + RunForLibrary(cscOptions: cscOptions); } [Test] public void Loops([ValueSource("defaultOptions")] CompilerOptions cscOptions) { - Run(cscOptions: cscOptions); + RunForLibrary(cscOptions: cscOptions); } [Test] public void PropertiesAndEvents([ValueSource("defaultOptions")] CompilerOptions cscOptions) { - Run(cscOptions: cscOptions); + RunForLibrary(cscOptions: cscOptions); } [Test] public void AutoProperties([ValueSource("roslynOnlyOptions")] CompilerOptions cscOptions) { - Run(cscOptions: cscOptions); + RunForLibrary(cscOptions: cscOptions); } [Test] public void QueryExpressions([ValueSource("defaultOptions")] CompilerOptions cscOptions) { - Run(cscOptions: cscOptions); + RunForLibrary(cscOptions: cscOptions); } [Test] public void TypeAnalysisTests([ValueSource("defaultOptions")] CompilerOptions cscOptions) { - Run(cscOptions: cscOptions); + RunForLibrary(cscOptions: cscOptions); } [Test] public void CheckedUnchecked([ValueSource("defaultOptions")] CompilerOptions cscOptions) { - Run(cscOptions: cscOptions); + RunForLibrary(cscOptions: cscOptions); } [Test] public void UnsafeCode([ValueSource("defaultOptions")] CompilerOptions cscOptions) { - Run(cscOptions: cscOptions); + RunForLibrary(cscOptions: cscOptions); } [Test] public void PInvoke([ValueSource("defaultOptions")] CompilerOptions cscOptions) { // This tests needs our own disassembler; ildasm has a bug with marshalinfo. - Run(cscOptions: cscOptions, asmOptions: AssemblerOptions.UseOwnDisassembler); + RunForLibrary(cscOptions: cscOptions, asmOptions: AssemblerOptions.UseOwnDisassembler); } [Test] public void InitializerTests([ValueSource("defaultOptions")] CompilerOptions cscOptions) { - Run(cscOptions: cscOptions); + RunForLibrary(cscOptions: cscOptions); } [Test] public void ExpressionTrees([ValueSource("defaultOptions")] CompilerOptions cscOptions) { - Run(cscOptions: cscOptions); + RunForLibrary(cscOptions: cscOptions); } [Test] public void FixProxyCalls([Values(CompilerOptions.None, CompilerOptions.Optimize, CompilerOptions.UseRoslyn)] CompilerOptions cscOptions) { - Run(cscOptions: cscOptions); + RunForLibrary(cscOptions: cscOptions); } [Test] public void VariableNaming([ValueSource("defaultOptions")] CompilerOptions cscOptions) { - Run(cscOptions: cscOptions); + RunForLibrary(cscOptions: cscOptions); } [Test] public void VariableNamingWithoutSymbols([ValueSource("defaultOptions")] CompilerOptions cscOptions) { - Run(cscOptions: cscOptions, decompilerSettings: new DecompilerSettings { UseDebugSymbols = false }); + RunForLibrary(cscOptions: cscOptions, decompilerSettings: new DecompilerSettings { UseDebugSymbols = false }); } [Test] public void CS72_PrivateProtected([ValueSource("roslynOnlyOptions")] CompilerOptions cscOptions) + { + RunForLibrary(cscOptions: cscOptions); + } + + [Test] + public void AsyncMain([ValueSource("roslynOnlyOptions")] CompilerOptions cscOptions) { Run(cscOptions: cscOptions); } + void RunForLibrary([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CompilerOptions cscOptions = CompilerOptions.None, DecompilerSettings decompilerSettings = null) + { + Run(testName, asmOptions | AssemblerOptions.Library, cscOptions | CompilerOptions.Library, decompilerSettings); + } + void Run([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CompilerOptions cscOptions = CompilerOptions.None, DecompilerSettings decompilerSettings = null) { var ilFile = Path.Combine(TestCasePath, testName) + Tester.GetSuffix(cscOptions) + ".il"; @@ -239,7 +250,7 @@ namespace ICSharpCode.Decompiler.Tests // re-create .il file if necessary CompilerResults output = null; try { - output = Tester.CompileCSharp(csFile, cscOptions | CompilerOptions.Library); + output = Tester.CompileCSharp(csFile, cscOptions); Tester.Disassemble(output.PathToAssembly, ilFile, asmOptions); } finally { if (output != null) @@ -247,7 +258,7 @@ namespace ICSharpCode.Decompiler.Tests } } - var executable = Tester.AssembleIL(ilFile, asmOptions | AssemblerOptions.Library); + var executable = Tester.AssembleIL(ilFile, asmOptions); var decompiled = Tester.DecompileCSharp(executable, decompilerSettings); CodeAssert.FilesAreEqual(csFile, decompiled, Tester.GetPreprocessorSymbols(cscOptions).ToArray()); diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncMain.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncMain.cs new file mode 100644 index 000000000..0722cbaf6 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncMain.cs @@ -0,0 +1,14 @@ +using System; +using System.Threading.Tasks; + +namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty +{ + public class AsyncMain + { + public static async Task Main(string[] args) + { + await Task.Delay(1000); + Console.WriteLine("Hello Wolrd!"); + } + } +} diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncMain.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncMain.opt.roslyn.il new file mode 100644 index 000000000..868dddd8f --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncMain.opt.roslyn.il @@ -0,0 +1,209 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. Tous droits r?serv?s. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly AsyncMain +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) + .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + + // --- The following custom attribute is added automatically, do not uncomment ------- + // .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 02 00 00 00 00 00 ) + + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module AsyncMain.exe +// MVID: {B9141C5A-989C-49C7-986D-91A53478FC26} +.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) +.imagebase 0x00400000 +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 // WINDOWS_CUI +.corflags 0x00000001 // ILONLY +// Image base: 0x050A0000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain + extends [mscorlib]System.Object +{ + .class auto ansi sealed nested private beforefieldinit '
d__0' + extends [mscorlib]System.ValueType + implements [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 '<>1__state' + .field public valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder '<>t__builder' + .field private valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter '<>u__1' + .method private hidebysig newslot virtual final + instance void MoveNext() cil managed + { + .override [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine::MoveNext + // Code size 157 (0x9d) + .maxstack 3 + .locals init (int32 V_0, + valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter V_1, + class [mscorlib]System.Exception V_2) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>1__state' + IL_0006: stloc.0 + .try + { + IL_0007: ldloc.0 + IL_0008: brfalse.s IL_0043 + + IL_000a: ldc.i4 0x3e8 + IL_000f: call class [mscorlib]System.Threading.Tasks.Task [mscorlib]System.Threading.Tasks.Task::Delay(int32) + IL_0014: callvirt instance valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter [mscorlib]System.Threading.Tasks.Task::GetAwaiter() + IL_0019: stloc.1 + IL_001a: ldloca.s V_1 + IL_001c: call instance bool [mscorlib]System.Runtime.CompilerServices.TaskAwaiter::get_IsCompleted() + IL_0021: brtrue.s IL_005f + + IL_0023: ldarg.0 + IL_0024: ldc.i4.0 + IL_0025: dup + IL_0026: stloc.0 + IL_0027: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>1__state' + IL_002c: ldarg.0 + IL_002d: ldloc.1 + IL_002e: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>u__1' + IL_0033: ldarg.0 + IL_0034: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>t__builder' + IL_0039: ldloca.s V_1 + IL_003b: ldarg.0 + IL_003c: call instance void [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder::AwaitUnsafeOnCompletedd__0'>(!!0&, + !!1&) + IL_0041: leave.s IL_009c + + IL_0043: ldarg.0 + IL_0044: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>u__1' + IL_0049: stloc.1 + IL_004a: ldarg.0 + IL_004b: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>u__1' + IL_0050: initobj [mscorlib]System.Runtime.CompilerServices.TaskAwaiter + IL_0056: ldarg.0 + IL_0057: ldc.i4.m1 + IL_0058: dup + IL_0059: stloc.0 + IL_005a: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>1__state' + IL_005f: ldloca.s V_1 + IL_0061: call instance void [mscorlib]System.Runtime.CompilerServices.TaskAwaiter::GetResult() + IL_0066: ldstr "Hello Wolrd!" + IL_006b: call void [mscorlib]System.Console::WriteLine(string) + IL_0070: leave.s IL_0089 + + } // end .try + catch [mscorlib]System.Exception + { + IL_0072: stloc.2 + IL_0073: ldarg.0 + IL_0074: ldc.i4.s -2 + IL_0076: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>1__state' + IL_007b: ldarg.0 + IL_007c: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>t__builder' + IL_0081: ldloc.2 + IL_0082: call instance void [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder::SetException(class [mscorlib]System.Exception) + IL_0087: leave.s IL_009c + + } // end handler + IL_0089: ldarg.0 + IL_008a: ldc.i4.s -2 + IL_008c: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>1__state' + IL_0091: ldarg.0 + IL_0092: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>t__builder' + IL_0097: call instance void [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder::SetResult() + IL_009c: ret + } // end of method '
d__0'::MoveNext + + .method private hidebysig newslot virtual final + instance void SetStateMachine(class [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine stateMachine) cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine::SetStateMachine + // Code size 13 (0xd) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>t__builder' + IL_0006: ldarg.1 + IL_0007: call instance void [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder::SetStateMachine(class [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine) + IL_000c: ret + } // end of method '
d__0'::SetStateMachine + + } // end of class '
d__0' + + .method public hidebysig static class [mscorlib]System.Threading.Tasks.Task + Main(string[] args) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.AsyncStateMachineAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 42 49 43 53 68 61 72 70 43 6F 64 65 2E 44 // ..BICSharpCode.D + 65 63 6F 6D 70 69 6C 65 72 2E 54 65 73 74 73 2E // ecompiler.Tests. + 54 65 73 74 43 61 73 65 73 2E 50 72 65 74 74 79 // TestCases.Pretty + 2E 41 73 79 6E 63 4D 61 69 6E 2B 3C 4D 61 69 6E // .AsyncMain+
d__0.. + // Code size 49 (0x31) + .maxstack 2 + .locals init (valuetype ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0' V_0, + valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder V_1) + IL_0000: ldloca.s V_0 + IL_0002: call valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder::Create() + IL_0007: stfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>t__builder' + IL_000c: ldloca.s V_0 + IL_000e: ldc.i4.m1 + IL_000f: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>1__state' + IL_0014: ldloc.0 + IL_0015: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>t__builder' + IL_001a: stloc.1 + IL_001b: ldloca.s V_1 + IL_001d: ldloca.s V_0 + IL_001f: call instance void [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder::Startd__0'>(!!0&) + IL_0024: ldloca.s V_0 + IL_0026: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>t__builder' + IL_002b: call instance class [mscorlib]System.Threading.Tasks.Task [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder::get_Task() + IL_0030: ret + } // end of method AsyncMain::Main + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: ret + } // end of method AsyncMain::.ctor + + .method private hidebysig specialname static + void '
'(string[] args) cil managed + { + .entrypoint + // Code size 20 (0x14) + .maxstack 1 + .locals init (valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter V_0) + IL_0000: ldarg.0 + IL_0001: call class [mscorlib]System.Threading.Tasks.Task ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain::Main(string[]) + IL_0006: callvirt instance valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter [mscorlib]System.Threading.Tasks.Task::GetAwaiter() + IL_000b: stloc.0 + IL_000c: ldloca.s V_0 + IL_000e: call instance void [mscorlib]System.Runtime.CompilerServices.TaskAwaiter::GetResult() + IL_0013: ret + } // end of method AsyncMain::'
' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncMain.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncMain.roslyn.il new file mode 100644 index 000000000..fab746d38 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncMain.roslyn.il @@ -0,0 +1,237 @@ + +// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0 +// Copyright (c) Microsoft Corporation. Tous droits r?serv?s. + + + +// Metadata version: v4.0.30319 +.assembly extern mscorlib +{ + .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. + .ver 4:0:0:0 +} +.assembly AsyncMain +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) + .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx + 63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows. + + // --- The following custom attribute is added automatically, do not uncomment ------- + // .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 07 01 00 00 00 00 ) + + .permissionset reqmin + = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module AsyncMain.exe +// MVID: {9AD23895-984A-4198-A22B-F506741986BA} +.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) +.imagebase 0x00400000 +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 // WINDOWS_CUI +.corflags 0x00000001 // ILONLY +// Image base: 0x04F10000 + + +// =============== CLASS MEMBERS DECLARATION =================== + +.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain + extends [mscorlib]System.Object +{ + .class auto ansi sealed nested private beforefieldinit '
d__0' + extends [mscorlib]System.Object + implements [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public int32 '<>1__state' + .field public valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder '<>t__builder' + .field public string[] args + .field private valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter '<>u__1' + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + // Code size 8 (0x8) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method '
d__0'::.ctor + + .method private hidebysig newslot virtual final + instance void MoveNext() cil managed + { + .override [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine::MoveNext + // Code size 170 (0xaa) + .maxstack 3 + .locals init (int32 V_0, + valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter V_1, + class ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0' V_2, + class [mscorlib]System.Exception V_3) + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>1__state' + IL_0006: stloc.0 + .try + { + IL_0007: ldloc.0 + IL_0008: brfalse.s IL_000c + + IL_000a: br.s IL_000e + + IL_000c: br.s IL_004c + + IL_000e: nop + IL_000f: ldc.i4 0x3e8 + IL_0014: call class [mscorlib]System.Threading.Tasks.Task [mscorlib]System.Threading.Tasks.Task::Delay(int32) + IL_0019: callvirt instance valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter [mscorlib]System.Threading.Tasks.Task::GetAwaiter() + IL_001e: stloc.1 + IL_001f: ldloca.s V_1 + IL_0021: call instance bool [mscorlib]System.Runtime.CompilerServices.TaskAwaiter::get_IsCompleted() + IL_0026: brtrue.s IL_0068 + + IL_0028: ldarg.0 + IL_0029: ldc.i4.0 + IL_002a: dup + IL_002b: stloc.0 + IL_002c: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>1__state' + IL_0031: ldarg.0 + IL_0032: ldloc.1 + IL_0033: stfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>u__1' + IL_0038: ldarg.0 + IL_0039: stloc.2 + IL_003a: ldarg.0 + IL_003b: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>t__builder' + IL_0040: ldloca.s V_1 + IL_0042: ldloca.s V_2 + IL_0044: call instance void [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder::AwaitUnsafeOnCompletedd__0'>(!!0&, + !!1&) + IL_0049: nop + IL_004a: leave.s IL_00a9 + + IL_004c: ldarg.0 + IL_004d: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>u__1' + IL_0052: stloc.1 + IL_0053: ldarg.0 + IL_0054: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>u__1' + IL_0059: initobj [mscorlib]System.Runtime.CompilerServices.TaskAwaiter + IL_005f: ldarg.0 + IL_0060: ldc.i4.m1 + IL_0061: dup + IL_0062: stloc.0 + IL_0063: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>1__state' + IL_0068: ldloca.s V_1 + IL_006a: call instance void [mscorlib]System.Runtime.CompilerServices.TaskAwaiter::GetResult() + IL_006f: nop + IL_0070: ldstr "Hello Wolrd!" + IL_0075: call void [mscorlib]System.Console::WriteLine(string) + IL_007a: nop + IL_007b: leave.s IL_0095 + + } // end .try + catch [mscorlib]System.Exception + { + IL_007d: stloc.3 + IL_007e: ldarg.0 + IL_007f: ldc.i4.s -2 + IL_0081: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>1__state' + IL_0086: ldarg.0 + IL_0087: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>t__builder' + IL_008c: ldloc.3 + IL_008d: call instance void [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder::SetException(class [mscorlib]System.Exception) + IL_0092: nop + IL_0093: leave.s IL_00a9 + + } // end handler + IL_0095: ldarg.0 + IL_0096: ldc.i4.s -2 + IL_0098: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>1__state' + IL_009d: ldarg.0 + IL_009e: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>t__builder' + IL_00a3: call instance void [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder::SetResult() + IL_00a8: nop + IL_00a9: ret + } // end of method '
d__0'::MoveNext + + .method private hidebysig newslot virtual final + instance void SetStateMachine(class [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine stateMachine) cil managed + { + .custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 ) + .override [mscorlib]System.Runtime.CompilerServices.IAsyncStateMachine::SetStateMachine + // Code size 1 (0x1) + .maxstack 8 + IL_0000: ret + } // end of method '
d__0'::SetStateMachine + + } // end of class '
d__0' + + .method public hidebysig static class [mscorlib]System.Threading.Tasks.Task + Main(string[] args) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.AsyncStateMachineAttribute::.ctor(class [mscorlib]System.Type) = ( 01 00 42 49 43 53 68 61 72 70 43 6F 64 65 2E 44 // ..BICSharpCode.D + 65 63 6F 6D 70 69 6C 65 72 2E 54 65 73 74 73 2E // ecompiler.Tests. + 54 65 73 74 43 61 73 65 73 2E 50 72 65 74 74 79 // TestCases.Pretty + 2E 41 73 79 6E 63 4D 61 69 6E 2B 3C 4D 61 69 6E // .AsyncMain+
d__0.. + .custom instance void [mscorlib]System.Diagnostics.DebuggerStepThroughAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 59 (0x3b) + .maxstack 2 + .locals init (class ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0' V_0, + valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder V_1) + IL_0000: newobj instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::.ctor() + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: stfld string[] ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::args + IL_000d: ldloc.0 + IL_000e: call valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder::Create() + IL_0013: stfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>t__builder' + IL_0018: ldloc.0 + IL_0019: ldc.i4.m1 + IL_001a: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>1__state' + IL_001f: ldloc.0 + IL_0020: ldfld valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>t__builder' + IL_0025: stloc.1 + IL_0026: ldloca.s V_1 + IL_0028: ldloca.s V_0 + IL_002a: call instance void [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder::Startd__0'>(!!0&) + IL_002f: ldloc.0 + IL_0030: ldflda valuetype [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain/'
d__0'::'<>t__builder' + IL_0035: call instance class [mscorlib]System.Threading.Tasks.Task [mscorlib]System.Runtime.CompilerServices.AsyncTaskMethodBuilder::get_Task() + IL_003a: ret + } // end of method AsyncMain::Main + + .method public hidebysig specialname rtspecialname + instance void .ctor() cil managed + { + // Code size 8 (0x8) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [mscorlib]System.Object::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method AsyncMain::.ctor + + .method private hidebysig specialname static + void '
'(string[] args) cil managed + { + .entrypoint + // Code size 20 (0x14) + .maxstack 1 + .locals init (valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter V_0) + IL_0000: ldarg.0 + IL_0001: call class [mscorlib]System.Threading.Tasks.Task ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain::Main(string[]) + IL_0006: callvirt instance valuetype [mscorlib]System.Runtime.CompilerServices.TaskAwaiter [mscorlib]System.Threading.Tasks.Task::GetAwaiter() + IL_000b: stloc.0 + IL_000c: ldloca.s V_0 + IL_000e: call instance void [mscorlib]System.Runtime.CompilerServices.TaskAwaiter::GetResult() + IL_0013: ret + } // end of method AsyncMain::'
' + +} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.AsyncMain + + +// ============================================================= + +// *********** DISASSEMBLY COMPLETE *********************** diff --git a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs index 731c7c964..dc5901dbc 100644 --- a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs @@ -204,6 +204,8 @@ namespace ICSharpCode.Decompiler.CSharp return true; if (settings.AnonymousMethods && method.HasGeneratedName() && method.IsCompilerGenerated()) return true; + if (settings.AsyncAwait && AsyncAwaitDecompiler.IsCompilerGeneratedMainMethod(method)) + return true; } TypeDefinition type = member as TypeDefinition; diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs b/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs index 3746df2ad..31f87c729 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs @@ -20,6 +20,7 @@ using ICSharpCode.Decompiler.CSharp; using ICSharpCode.Decompiler.IL.Transforms; using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.Util; +using Mono.Cecil; using System; using System.Collections.Generic; using System.Diagnostics; @@ -44,6 +45,11 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow return false; } + public static bool IsCompilerGeneratedMainMethod(MethodDefinition method) + { + return method.Name.Equals("
", StringComparison.Ordinal); + } + enum AsyncMethodType { Void, From 14f9577a815bab03170df05fad97280eb5c0442d Mon Sep 17 00:00:00 2001 From: MikeFH Date: Mon, 15 Jan 2018 22:17:41 +0100 Subject: [PATCH 29/36] Fix lines starting with spaces --- ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncMain.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncMain.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncMain.cs index 0722cbaf6..6d7f03bf6 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncMain.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncMain.cs @@ -4,11 +4,11 @@ using System.Threading.Tasks; namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { public class AsyncMain - { + { public static async Task Main(string[] args) { await Task.Delay(1000); Console.WriteLine("Hello Wolrd!"); } - } + } } From 8af973ef35d2bfc014057c764ef6af4273d446c4 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 17 Jan 2018 18:37:40 +0100 Subject: [PATCH 30/36] Fix #1013, #1034: Option to show code unfolded (expanded) by default --- ICSharpCode.Decompiler/DecompilerSettings.cs | 12 ++++++++++++ .../Disassembler/ReflectionDisassembler.cs | 6 ++++-- ICSharpCode.Decompiler/Output/TextTokenWriter.cs | 3 ++- ILSpy/Languages/CSharpLanguage.cs | 2 +- ILSpy/Languages/ILLanguage.cs | 3 ++- ILSpy/Options/DecompilerSettingsPanel.xaml | 1 + ILSpy/Options/DecompilerSettingsPanel.xaml.cs | 5 ++++- ILSpy/Options/DisplaySettings.cs | 9 +++------ ILSpy/Options/DisplaySettingsPanel.xaml | 2 +- ILSpy/Options/DisplaySettingsPanel.xaml.cs | 6 +++--- 10 files changed, 33 insertions(+), 16 deletions(-) diff --git a/ICSharpCode.Decompiler/DecompilerSettings.cs b/ICSharpCode.Decompiler/DecompilerSettings.cs index 77e7f9e4d..c352a871c 100644 --- a/ICSharpCode.Decompiler/DecompilerSettings.cs +++ b/ICSharpCode.Decompiler/DecompilerSettings.cs @@ -345,6 +345,18 @@ namespace ICSharpCode.Decompiler } } + bool expandMemberDefinitions = false; + + public bool ExpandMemberDefinitions { + get { return expandMemberDefinitions; } + set { + if (expandMemberDefinitions != value) { + expandMemberDefinitions = value; + OnPropertyChanged(); + } + } + } + #region Options to aid VB decompilation bool introduceIncrementAndDecrement = true; diff --git a/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs b/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs index 851c47842..8455c34c0 100644 --- a/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs +++ b/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs @@ -45,6 +45,8 @@ namespace ICSharpCode.Decompiler.Disassembler set => methodBodyDisassembler.ShowSequencePoints = value; } + public bool ExpandMemberDefinitions { get; set; } = false; + public ReflectionDisassembler(ITextOutput output, CancellationToken cancellationToken) : this(output, new MethodBodyDisassembler(output, cancellationToken), cancellationToken) { @@ -846,7 +848,7 @@ namespace ICSharpCode.Decompiler.Disassembler output.Write(DisassemblerHelpers.Escape(type.DeclaringType != null ? type.Name : type.FullName)); WriteTypeParameters(output, type); - output.MarkFoldStart(defaultCollapsed: isInType); + output.MarkFoldStart(defaultCollapsed: !ExpandMemberDefinitions && isInType); output.WriteLine(); if (type.BaseType != null) { @@ -1003,7 +1005,7 @@ namespace ICSharpCode.Decompiler.Disassembler void OpenBlock(bool defaultCollapsed) { - output.MarkFoldStart(defaultCollapsed: defaultCollapsed); + output.MarkFoldStart(defaultCollapsed: !ExpandMemberDefinitions && defaultCollapsed); output.WriteLine(); output.WriteLine("{"); output.Indent(); diff --git a/ICSharpCode.Decompiler/Output/TextTokenWriter.cs b/ICSharpCode.Decompiler/Output/TextTokenWriter.cs index 5ce584f1d..4273562db 100644 --- a/ICSharpCode.Decompiler/Output/TextTokenWriter.cs +++ b/ICSharpCode.Decompiler/Output/TextTokenWriter.cs @@ -40,6 +40,7 @@ namespace ICSharpCode.Decompiler bool lastUsingDeclaration; public bool FoldBraces = false; + public bool ExpandMemberDefinitions = false; public TextTokenWriter(ITextOutput output, DecompilerSettings settings, IDecompilerTypeSystem typeSystem) { @@ -216,7 +217,7 @@ namespace ICSharpCode.Decompiler if (braceLevelWithinType >= 0 || nodeStack.Peek() is TypeDeclaration) braceLevelWithinType++; if (nodeStack.OfType().Count() <= 1 || FoldBraces) { - output.MarkFoldStart(defaultCollapsed: braceLevelWithinType == 1); + output.MarkFoldStart(defaultCollapsed: !ExpandMemberDefinitions && braceLevelWithinType == 1); } output.Write("{"); break; diff --git a/ILSpy/Languages/CSharpLanguage.cs b/ILSpy/Languages/CSharpLanguage.cs index 0a71362d0..e76746b53 100644 --- a/ILSpy/Languages/CSharpLanguage.cs +++ b/ILSpy/Languages/CSharpLanguage.cs @@ -98,7 +98,7 @@ namespace ICSharpCode.ILSpy void WriteCode(ITextOutput output, DecompilerSettings settings, SyntaxTree syntaxTree, IDecompilerTypeSystem typeSystem) { syntaxTree.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true }); - TokenWriter tokenWriter = new TextTokenWriter(output, settings, typeSystem) { FoldBraces = settings.FoldBraces }; + TokenWriter tokenWriter = new TextTokenWriter(output, settings, typeSystem) { FoldBraces = settings.FoldBraces, ExpandMemberDefinitions = settings.ExpandMemberDefinitions }; if (output is ISmartTextOutput highlightingOutput) { tokenWriter = new CSharpHighlightingTokenWriter(tokenWriter, highlightingOutput); } diff --git a/ILSpy/Languages/ILLanguage.cs b/ILSpy/Languages/ILLanguage.cs index 36b58402d..04b30ec0d 100644 --- a/ILSpy/Languages/ILLanguage.cs +++ b/ILSpy/Languages/ILLanguage.cs @@ -48,7 +48,8 @@ namespace ICSharpCode.ILSpy { return new ReflectionDisassembler(output, options.CancellationToken) { DetectControlStructure = detectControlStructure, - ShowSequencePoints = options.DecompilerSettings.ShowDebugInfo + ShowSequencePoints = options.DecompilerSettings.ShowDebugInfo, + ExpandMemberDefinitions = options.DecompilerSettings.ExpandMemberDefinitions }; } diff --git a/ILSpy/Options/DecompilerSettingsPanel.xaml b/ILSpy/Options/DecompilerSettingsPanel.xaml index ec976b7b2..a7143f461 100644 --- a/ILSpy/Options/DecompilerSettingsPanel.xaml +++ b/ILSpy/Options/DecompilerSettingsPanel.xaml @@ -18,5 +18,6 @@ Insert using declarations Fully qualify ambiguous type names Always use braces + Expand member definitions after decompilation \ No newline at end of file diff --git a/ILSpy/Options/DecompilerSettingsPanel.xaml.cs b/ILSpy/Options/DecompilerSettingsPanel.xaml.cs index b261faa38..22577878f 100644 --- a/ILSpy/Options/DecompilerSettingsPanel.xaml.cs +++ b/ILSpy/Options/DecompilerSettingsPanel.xaml.cs @@ -61,6 +61,8 @@ namespace ICSharpCode.ILSpy.Options s.ShowDebugInfo = (bool?)e.Attribute("showDebugInfo") ?? s.ShowDebugInfo; s.ShowXmlDocumentation = (bool?)e.Attribute("xmlDoc") ?? s.ShowXmlDocumentation; s.FoldBraces = (bool?)e.Attribute("foldBraces") ?? s.FoldBraces; + s.ExpandMemberDefinitions = (bool?)e.Attribute("expandMemberDefinitions") ?? s.ExpandMemberDefinitions; + s.RemoveDeadCode = (bool?)e.Attribute("removeDeadCode") ?? s.RemoveDeadCode; s.UsingDeclarations = (bool?)e.Attribute("usingDeclarations") ?? s.UsingDeclarations; s.FullyQualifyAmbiguousTypeNames = (bool?)e.Attribute("fullyQualifyAmbiguousTypeNames") ?? s.FullyQualifyAmbiguousTypeNames; s.AlwaysUseBraces = (bool?)e.Attribute("alwaysUseBraces") ?? s.AlwaysUseBraces; @@ -82,7 +84,8 @@ namespace ICSharpCode.ILSpy.Options section.SetAttributeValue("showDebugInfo", s.ShowDebugInfo); section.SetAttributeValue("xmlDoc", s.ShowXmlDocumentation); section.SetAttributeValue("foldBraces", s.FoldBraces); - section.SetAttributeValue("foldBraces", s.RemoveDeadCode); + section.SetAttributeValue("expandMemberDefinitions", s.ExpandMemberDefinitions); + section.SetAttributeValue("removeDeadCode", s.RemoveDeadCode); section.SetAttributeValue("usingDeclarations", s.UsingDeclarations); section.SetAttributeValue("fullyQualifyAmbiguousTypeNames", s.FullyQualifyAmbiguousTypeNames); section.SetAttributeValue("alwaysUseBraces", s.AlwaysUseBraces); diff --git a/ILSpy/Options/DisplaySettings.cs b/ILSpy/Options/DisplaySettings.cs index 5b048c0db..a023428bd 100644 --- a/ILSpy/Options/DisplaySettings.cs +++ b/ILSpy/Options/DisplaySettings.cs @@ -110,13 +110,10 @@ namespace ICSharpCode.ILSpy.Options bool sortResults = true; - public bool SortResults - { + public bool SortResults { get { return sortResults; } - set - { - if (sortResults != value) - { + set { + if (sortResults != value) { sortResults = value; OnPropertyChanged(); } diff --git a/ILSpy/Options/DisplaySettingsPanel.xaml b/ILSpy/Options/DisplaySettingsPanel.xaml index 5a56bafbd..9cd20de05 100644 --- a/ILSpy/Options/DisplaySettingsPanel.xaml +++ b/ILSpy/Options/DisplaySettingsPanel.xaml @@ -61,7 +61,7 @@ Show line numbers Show metadata tokens - Enable word wrap + Enable word wrap Sort results by fitness diff --git a/ILSpy/Options/DisplaySettingsPanel.xaml.cs b/ILSpy/Options/DisplaySettingsPanel.xaml.cs index d4b1ee547..e9afecf1f 100644 --- a/ILSpy/Options/DisplaySettingsPanel.xaml.cs +++ b/ILSpy/Options/DisplaySettingsPanel.xaml.cs @@ -102,8 +102,8 @@ namespace ICSharpCode.ILSpy.Options s.ShowLineNumbers = (bool?)e.Attribute("ShowLineNumbers") ?? false; s.ShowMetadataTokens = (bool?) e.Attribute("ShowMetadataTokens") ?? false; s.EnableWordWrap = (bool?)e.Attribute("EnableWordWrap") ?? false; - s.SortResults = (bool?)e.Attribute("SortResults") ?? false; - + s.SortResults = (bool?)e.Attribute("SortResults") ?? true; + return s; } @@ -118,7 +118,7 @@ namespace ICSharpCode.ILSpy.Options section.SetAttributeValue("ShowMetadataTokens", s.ShowMetadataTokens); section.SetAttributeValue("EnableWordWrap", s.EnableWordWrap); section.SetAttributeValue("SortResults", s.SortResults); - + XElement existingElement = root.Element("DisplaySettings"); if (existingElement != null) existingElement.ReplaceWith(section); From 1e14c8ffae72f42257c8a291bc474f7117ecfb77 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 17 Jan 2018 22:39:49 +0100 Subject: [PATCH 31/36] Close #1033: Add TFM for net45 --- ICSharpCode.Decompiler/CSharp/CallBuilder.cs | 6 +++--- ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj | 4 ++-- .../ICSharpCode.Decompiler.nuspec.template | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs index 619ab3355..88417af5f 100644 --- a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs @@ -117,7 +117,7 @@ namespace ICSharpCode.Decompiler.CSharp expandedArguments.Add(expressionBuilder.GetDefaultValueExpression(elementType).WithoutILInstruction()); } } - if (IsUnambiguousCall(expectedTargetDetails, method, target, Array.Empty(), expandedArguments) == OverloadResolutionErrors.None) { + if (IsUnambiguousCall(expectedTargetDetails, method, target, Empty.Array, expandedArguments) == OverloadResolutionErrors.None) { isExpandedForm = true; expectedParameters = expandedParameters; arguments = expandedArguments.SelectList(a => new TranslatedExpression(a.Expression.Detach())); @@ -170,7 +170,7 @@ namespace ICSharpCode.Decompiler.CSharp .WithRR(rr); } else { - if (IsUnambiguousCall(expectedTargetDetails, method, target, Array.Empty(), arguments) != OverloadResolutionErrors.None) { + if (IsUnambiguousCall(expectedTargetDetails, method, target, Empty.Array, arguments) != OverloadResolutionErrors.None) { for (int i = 0; i < arguments.Count; i++) { if (settings.AnonymousTypes && expectedParameters[i].Type.ContainsAnonymousType()) { if (arguments[i].Expression is LambdaExpression lambda) { @@ -199,7 +199,7 @@ namespace ICSharpCode.Decompiler.CSharp bool requireTypeArguments = false; bool targetCasted = false; bool argumentsCasted = false; - IType[] typeArguments = Array.Empty(); + IType[] typeArguments = Empty.Array; OverloadResolutionErrors errors; while ((errors = IsUnambiguousCall(expectedTargetDetails, method, target, typeArguments, arguments)) != OverloadResolutionErrors.None) { diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj index 40bfd51dc..a60307ea0 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj @@ -4,12 +4,12 @@ netstandard2.0 - netstandard2.0;net46 + netstandard2.0;net46;net45 IL decompiler engine ic#code ILSpy - Copyright 2011-2017 AlphaSierraPapa for the SharpDevelop Team + Copyright 2011-2018 AlphaSierraPapa for the SharpDevelop Team en-US False False diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.nuspec.template b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.nuspec.template index ec83848be..7d5c743bb 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.nuspec.template +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.nuspec.template @@ -25,6 +25,9 @@ + + + From c299304034cf36388fc3a063b56510433f435dd2 Mon Sep 17 00:00:00 2001 From: MikeFH Date: Thu, 18 Jan 2018 13:59:26 +0100 Subject: [PATCH 32/36] Check that method is actually the entry point --- ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs b/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs index 31f87c729..adc55b685 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs @@ -47,7 +47,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow public static bool IsCompilerGeneratedMainMethod(MethodDefinition method) { - return method.Name.Equals("
", StringComparison.Ordinal); + return method == method.Module.Assembly?.EntryPoint && method.Name.Equals("
", StringComparison.Ordinal); } enum AsyncMethodType From 2848707838f1f12a51a02adc56b24f6e4634bda9 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 23 Jan 2018 19:11:20 +0100 Subject: [PATCH 33/36] Fix #1031: Do not crash during search, if Cecil throws an exception. --- ILSpy/SearchStrategies.cs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/ILSpy/SearchStrategies.cs b/ILSpy/SearchStrategies.cs index 46385006d..e8f7b4539 100644 --- a/ILSpy/SearchStrategies.cs +++ b/ILSpy/SearchStrategies.cs @@ -139,12 +139,17 @@ namespace ICSharpCode.ILSpy } } - void Add(IEnumerable items, TypeDefinition type, Language language, Action addResult, Func matcher, Func image) where T : MemberReference + void Add(Func> itemsGetter, TypeDefinition type, Language language, Action addResult, Func matcher, Func image) where T : MemberReference { + IEnumerable items = Enumerable.Empty(); + try { + items = itemsGetter(); + } catch (Exception ex) { + System.Diagnostics.Debug.Print(ex.ToString()); + } foreach (var item in items) { if (matcher(item, language)) { - addResult(new SearchResult - { + addResult(new SearchResult { Member = item, Fitness = CalculateFitness(item), Image = image(item), @@ -158,10 +163,10 @@ namespace ICSharpCode.ILSpy public virtual void Search(TypeDefinition type, Language language, Action addResult) { - Add(type.Fields, type, language, addResult, IsMatch, FieldTreeNode.GetIcon); - Add(type.Properties, type, language, addResult, IsMatch, p => PropertyTreeNode.GetIcon(p)); - Add(type.Events, type, language, addResult, IsMatch, EventTreeNode.GetIcon); - Add(type.Methods.Where(NotSpecialMethod), type, language, addResult, IsMatch, MethodTreeNode.GetIcon); + Add(() => type.Fields, type, language, addResult, IsMatch, FieldTreeNode.GetIcon); + Add(() => type.Properties, type, language, addResult, IsMatch, p => PropertyTreeNode.GetIcon(p)); + Add(() => type.Events, type, language, addResult, IsMatch, EventTreeNode.GetIcon); + Add(() => type.Methods.Where(NotSpecialMethod), type, language, addResult, IsMatch, MethodTreeNode.GetIcon); foreach (TypeDefinition nestedType in type.NestedTypes) { Search(nestedType, language, addResult); From 4cccf9fac59e20434896646025848774da02d110 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 23 Jan 2018 23:44:31 +0100 Subject: [PATCH 34/36] Fix crash described in #1038. --- .../CSharp/Transforms/ConvertConstructorCallIntoInitializer.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/ConvertConstructorCallIntoInitializer.cs b/ICSharpCode.Decompiler/CSharp/Transforms/ConvertConstructorCallIntoInitializer.cs index 60703b48a..053777942 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/ConvertConstructorCallIntoInitializer.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/ConvertConstructorCallIntoInitializer.cs @@ -132,7 +132,8 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms if (!(fieldOrPropertyOrEvent is IField) && !(fieldOrPropertyOrEvent is IProperty) && !(fieldOrPropertyOrEvent is IEvent)) break; AstNode fieldOrPropertyOrEventDecl = members.FirstOrDefault(f => f.GetSymbol() == fieldOrPropertyOrEvent); - if (fieldOrPropertyOrEventDecl == null) + // Cannot transform if member is not found or if it is a custom event. + if (fieldOrPropertyOrEventDecl == null || fieldOrPropertyOrEventDecl is CustomEventDeclaration) break; Expression initializer = m.Get("initializer").Single(); // 'this'/'base' cannot be used in initializers From 96896675153d01edf72f2b82eddb5a3d5dac27ae Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 24 Jan 2018 18:40:51 +0100 Subject: [PATCH 35/36] Fix #1042: Wrong decompile result for collection initializers --- .../TestCases/Pretty/InitializerTests.cs | 15 ++++++ .../TestCases/Pretty/InitializerTests.il | 12 ++--- .../TestCases/Pretty/InitializerTests.opt.il | 12 ++--- .../Pretty/InitializerTests.opt.roslyn.il | 45 +++++++++++++---- .../Pretty/InitializerTests.roslyn.il | 50 +++++++++++++++---- ...ransformCollectionAndObjectInitializers.cs | 2 +- 6 files changed, 103 insertions(+), 33 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs index b02789cd7..f96939cb1 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs @@ -376,6 +376,21 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } }); } + + public void NestedListWithIndexInitializer() + { +#if !OPT + List> list = new List> { +#else + List> obj = new List> { +#endif + [0] = { + 1, + 2, + 3 + } + }; + } #endif public static void ObjectInitializerWithInitializationOfDeeplyNestedObjects() diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il index 576d1b39b..e4dc50f38 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.il @@ -15,7 +15,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly '31sn40gd' +.assembly rzivg0mq { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx @@ -25,15 +25,15 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module '31sn40gd.dll' -// MVID: {EE7CB403-8040-4C94-B17A-F697CE60CA23} +.module rzivg0mq.dll +// MVID: {66592AAC-07E3-4F52-A96F-0428775E7A0F} .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .imagebase 0x10000000 .file alignment 0x00000200 .stackreserve 0x00100000 .subsystem 0x0003 // WINDOWS_CUI .corflags 0x00000001 // ILONLY -// Image base: 0x02FB0000 +// Image base: 0x00E00000 // =============== CLASS MEMBERS DECLARATION =================== @@ -1513,8 +1513,8 @@ IL_0006: ret } // end of method InitializerTests::.ctor - .method private hidebysig static void 'b__7'(object sender, - class [mscorlib]System.EventArgs e) cil managed + .method private hidebysig static void 'b__7'(object param0, + class [mscorlib]System.EventArgs param1) cil managed { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) // Code size 8 (0x8) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il index 05f0d4bdd..0719f6acd 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.il @@ -15,7 +15,7 @@ .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. .ver 4:0:0:0 } -.assembly awwuldf0 +.assembly n52bfodk { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx @@ -25,15 +25,15 @@ .hash algorithm 0x00008004 .ver 0:0:0:0 } -.module awwuldf0.dll -// MVID: {59891EFA-EBA3-4F9A-9034-4F24037CEC15} +.module n52bfodk.dll +// MVID: {2B30E2AC-D797-4A69-ACEC-93251C343504} .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .imagebase 0x10000000 .file alignment 0x00000200 .stackreserve 0x00100000 .subsystem 0x0003 // WINDOWS_CUI .corflags 0x00000001 // ILONLY -// Image base: 0x03070000 +// Image base: 0x037A0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -1275,8 +1275,8 @@ IL_0006: ret } // end of method InitializerTests::.ctor - .method private hidebysig static void 'b__7'(object sender, - class [mscorlib]System.EventArgs e) cil managed + .method private hidebysig static void 'b__7'(object param0, + class [mscorlib]System.EventArgs param1) cil managed { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) // Code size 6 (0x6) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il index 72b5a9640..32e73d96e 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.opt.roslyn.il @@ -30,14 +30,14 @@ .ver 0:0:0:0 } .module InitializerTests.dll -// MVID: {8AE31202-72A4-4C73-86BF-EE49F9DE8C56} +// MVID: {AA17E92F-AE3B-4AA5-91C9-716D2E842EE5} .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .imagebase 0x10000000 .file alignment 0x00000200 .stackreserve 0x00100000 .subsystem 0x0003 // WINDOWS_CUI .corflags 0x00000001 // ILONLY -// Image base: 0x02EC0000 +// Image base: 0x01160000 // =============== CLASS MEMBERS DECLARATION =================== @@ -504,7 +504,7 @@ .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field public static initonly class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c' '<>9' .field public static class [mscorlib]System.EventHandler '<>9__23_0' - .field public static class [mscorlib]System.Func`2 '<>9__42_0' + .field public static class [mscorlib]System.Func`2 '<>9__43_0' .method private hidebysig specialname rtspecialname static void .cctor() cil managed { @@ -526,8 +526,8 @@ } // end of method '<>c'::.ctor .method assembly hidebysig instance void - 'b__23_0'(object sender, - class [mscorlib]System.EventArgs e) cil managed + 'b__23_0'(object '', + class [mscorlib]System.EventArgs '') cil managed { // Code size 6 (0x6) .maxstack 8 @@ -536,7 +536,7 @@ } // end of method '<>c'::'b__23_0' .method assembly hidebysig instance bool - 'b__42_0'(class [mscorlib]System.Globalization.NumberFormatInfo format) cil managed + 'b__43_0'(class [mscorlib]System.Globalization.NumberFormatInfo format) cil managed { // Code size 17 (0x11) .maxstack 8 @@ -546,7 +546,7 @@ IL_000b: call bool [mscorlib]System.String::op_Equality(string, string) IL_0010: ret - } // end of method '<>c'::'b__42_0' + } // end of method '<>c'::'b__43_0' } // end of class '<>c' @@ -1064,6 +1064,31 @@ IL_0081: ret } // end of method InitializerTests::MixedObjectAndDictInitializer + .method public hidebysig instance void + NestedListWithIndexInitializer() cil managed + { + // Code size 46 (0x2e) + .maxstack 8 + IL_0000: newobj instance void class [mscorlib]System.Collections.Generic.List`1>::.ctor() + IL_0005: dup + IL_0006: ldc.i4.0 + IL_0007: callvirt instance !0 class [mscorlib]System.Collections.Generic.List`1>::get_Item(int32) + IL_000c: ldc.i4.1 + IL_000d: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0012: dup + IL_0013: ldc.i4.0 + IL_0014: callvirt instance !0 class [mscorlib]System.Collections.Generic.List`1>::get_Item(int32) + IL_0019: ldc.i4.2 + IL_001a: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_001f: dup + IL_0020: ldc.i4.0 + IL_0021: callvirt instance !0 class [mscorlib]System.Collections.Generic.List`1>::get_Item(int32) + IL_0026: ldc.i4.3 + IL_0027: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_002c: pop + IL_002d: ret + } // end of method InitializerTests::NestedListWithIndexInitializer + .method public hidebysig static void ObjectInitializerWithInitializationOfDeeplyNestedObjects() cil managed { // Code size 77 (0x4d) @@ -1282,17 +1307,17 @@ IL_0033: callvirt instance void [mscorlib]System.Globalization.CultureInfo::set_DateTimeFormat(class [mscorlib]System.Globalization.DateTimeFormatInfo) IL_0038: dup IL_0039: ldloc.0 - IL_003a: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9__42_0' + IL_003a: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9__43_0' IL_003f: dup IL_0040: brtrue.s IL_0059 IL_0042: pop IL_0043: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9' - IL_0048: ldftn instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'b__42_0'(class [mscorlib]System.Globalization.NumberFormatInfo) + IL_0048: ldftn instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'b__43_0'(class [mscorlib]System.Globalization.NumberFormatInfo) IL_004e: newobj instance void class [mscorlib]System.Func`2::.ctor(object, native int) IL_0053: dup - IL_0054: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9__42_0' + IL_0054: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9__43_0' IL_0059: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Where(class [mscorlib]System.Collections.Generic.IEnumerable`1, class [mscorlib]System.Func`2) IL_005e: call !!0 [System.Core]System.Linq.Enumerable::First(class [mscorlib]System.Collections.Generic.IEnumerable`1) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il index ced96cb2f..65ab40c5b 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.roslyn.il @@ -30,14 +30,14 @@ .ver 0:0:0:0 } .module InitializerTests.dll -// MVID: {4E6BCF8B-3662-4EB0-88AA-8085A69A4D25} +// MVID: {3A200EF2-470A-47EB-B524-B0751246AB5E} .custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 ) .imagebase 0x10000000 .file alignment 0x00000200 .stackreserve 0x00100000 .subsystem 0x0003 // WINDOWS_CUI .corflags 0x00000001 // ILONLY -// Image base: 0x02C10000 +// Image base: 0x010E0000 // =============== CLASS MEMBERS DECLARATION =================== @@ -531,7 +531,7 @@ .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field public static initonly class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c' '<>9' .field public static class [mscorlib]System.EventHandler '<>9__23_0' - .field public static class [mscorlib]System.Func`2 '<>9__42_0' + .field public static class [mscorlib]System.Func`2 '<>9__43_0' .method private hidebysig specialname rtspecialname static void .cctor() cil managed { @@ -554,8 +554,8 @@ } // end of method '<>c'::.ctor .method assembly hidebysig instance void - 'b__23_0'(object sender, - class [mscorlib]System.EventArgs e) cil managed + 'b__23_0'(object '', + class [mscorlib]System.EventArgs '') cil managed { // Code size 8 (0x8) .maxstack 8 @@ -566,7 +566,7 @@ } // end of method '<>c'::'b__23_0' .method assembly hidebysig instance bool - 'b__42_0'(class [mscorlib]System.Globalization.NumberFormatInfo format) cil managed + 'b__43_0'(class [mscorlib]System.Globalization.NumberFormatInfo format) cil managed { // Code size 17 (0x11) .maxstack 8 @@ -576,7 +576,7 @@ IL_000b: call bool [mscorlib]System.String::op_Equality(string, string) IL_0010: ret - } // end of method '<>c'::'b__42_0' + } // end of method '<>c'::'b__43_0' } // end of class '<>c' @@ -1245,6 +1245,36 @@ IL_0088: ret } // end of method InitializerTests::MixedObjectAndDictInitializer + .method public hidebysig instance void + NestedListWithIndexInitializer() cil managed + { + // Code size 50 (0x32) + .maxstack 3 + .locals init (class [mscorlib]System.Collections.Generic.List`1> V_0) + IL_0000: nop + IL_0001: newobj instance void class [mscorlib]System.Collections.Generic.List`1>::.ctor() + IL_0006: dup + IL_0007: ldc.i4.0 + IL_0008: callvirt instance !0 class [mscorlib]System.Collections.Generic.List`1>::get_Item(int32) + IL_000d: ldc.i4.1 + IL_000e: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0013: nop + IL_0014: dup + IL_0015: ldc.i4.0 + IL_0016: callvirt instance !0 class [mscorlib]System.Collections.Generic.List`1>::get_Item(int32) + IL_001b: ldc.i4.2 + IL_001c: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_0021: nop + IL_0022: dup + IL_0023: ldc.i4.0 + IL_0024: callvirt instance !0 class [mscorlib]System.Collections.Generic.List`1>::get_Item(int32) + IL_0029: ldc.i4.3 + IL_002a: callvirt instance void class [mscorlib]System.Collections.Generic.List`1::Add(!0) + IL_002f: nop + IL_0030: stloc.0 + IL_0031: ret + } // end of method InitializerTests::NestedListWithIndexInitializer + .method public hidebysig static void ObjectInitializerWithInitializationOfDeeplyNestedObjects() cil managed { // Code size 82 (0x52) @@ -1499,17 +1529,17 @@ IL_003b: nop IL_003c: dup IL_003d: ldloc.0 - IL_003e: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9__42_0' + IL_003e: ldsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9__43_0' IL_0043: dup IL_0044: brtrue.s IL_005d IL_0046: pop IL_0047: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9' - IL_004c: ldftn instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'b__42_0'(class [mscorlib]System.Globalization.NumberFormatInfo) + IL_004c: ldftn instance bool ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'b__43_0'(class [mscorlib]System.Globalization.NumberFormatInfo) IL_0052: newobj instance void class [mscorlib]System.Func`2::.ctor(object, native int) IL_0057: dup - IL_0058: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9__42_0' + IL_0058: stsfld class [mscorlib]System.Func`2 ICSharpCode.Decompiler.Tests.TestCases.Pretty.InitializerTests/'<>c'::'<>9__43_0' IL_005d: call class [mscorlib]System.Collections.Generic.IEnumerable`1 [System.Core]System.Linq.Enumerable::Where(class [mscorlib]System.Collections.Generic.IEnumerable`1, class [mscorlib]System.Func`2) IL_0062: call !!0 [System.Core]System.Linq.Enumerable::First(class [mscorlib]System.Collections.Generic.IEnumerable`1) diff --git a/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs b/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs index 2e16ecc9d..6bf64d829 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs @@ -254,7 +254,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms instruction = call.Arguments[0]; if (method.IsAccessor) { var property = method.AccessorOwner as IProperty; - var isGetter = property?.Getter == method; + var isGetter = method.Equals(property?.Getter); var indices = call.Arguments.Skip(1).Take(call.Arguments.Count - (isGetter ? 1 : 2)).ToArray(); if (possibleIndexVariables != null) { // Mark all index variables as used From b33bb70dcb2731cd18a1ad9039b588b6c4de4428 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 24 Jan 2018 20:30:31 +0100 Subject: [PATCH 36/36] Fix #1044: Spelling: GetTopLevelTypeDefinitons --- ICSharpCode.Decompiler/TypeSystem/TypeSystemExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler/TypeSystem/TypeSystemExtensions.cs b/ICSharpCode.Decompiler/TypeSystem/TypeSystemExtensions.cs index fab533a31..1fdc8ecf5 100644 --- a/ICSharpCode.Decompiler/TypeSystem/TypeSystemExtensions.cs +++ b/ICSharpCode.Decompiler/TypeSystem/TypeSystemExtensions.cs @@ -430,7 +430,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// Gets all top level type definitions in the compilation. /// This may include types from referenced assemblies that are not accessible in the main assembly. /// - public static IEnumerable GetTopLevelTypeDefinitons (this ICompilation compilation) + public static IEnumerable GetTopLevelTypeDefinitions (this ICompilation compilation) { return compilation.Assemblies.SelectMany(a => a.TopLevelTypeDefinitions); }