From bdea1950a84cdc4b74cdd74b2c4e1c04e7d08368 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 6 Jun 2020 15:48:26 +0200 Subject: [PATCH] Add `#if !NETCORE` around extension methods that are included with .NET Core 3 --- ICSharpCode.Decompiler/IL/ILReader.cs | 8 ++++---- .../IL/Instructions/DynamicInstructions.cs | 1 + ICSharpCode.Decompiler/IL/Transforms/CopyPropagation.cs | 2 +- ICSharpCode.Decompiler/Util/CollectionExtensions.cs | 8 ++++++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/ILReader.cs b/ICSharpCode.Decompiler/IL/ILReader.cs index e86597bd9..c85375d2d 100644 --- a/ICSharpCode.Decompiler/IL/ILReader.cs +++ b/ICSharpCode.Decompiler/IL/ILReader.cs @@ -515,10 +515,10 @@ namespace ICSharpCode.Decompiler.IL var blockBuilder = new BlockBuilder(body, variableByExceptionHandler); blockBuilder.CreateBlocks(mainContainer, instructionBuilder, isBranchTarget, cancellationToken); var function = new ILFunction(this.method, body.GetCodeSize(), this.genericContext, mainContainer, kind); - CollectionExtensions.AddRange(function.Variables, parameterVariables); - CollectionExtensions.AddRange(function.Variables, localVariables); - CollectionExtensions.AddRange(function.Variables, stackVariables); - CollectionExtensions.AddRange(function.Variables, variableByExceptionHandler.Values); + function.Variables.AddRange(parameterVariables); + function.Variables.AddRange(localVariables); + function.Variables.AddRange(stackVariables); + function.Variables.AddRange(variableByExceptionHandler.Values); function.AddRef(); // mark the root node var removedBlocks = new List(); foreach (var c in function.Descendants.OfType()) { diff --git a/ICSharpCode.Decompiler/IL/Instructions/DynamicInstructions.cs b/ICSharpCode.Decompiler/IL/Instructions/DynamicInstructions.cs index 5a3b64b54..d11c69171 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/DynamicInstructions.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/DynamicInstructions.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Linq.Expressions; using ICSharpCode.Decompiler.IL.Patterns; using ICSharpCode.Decompiler.TypeSystem; diff --git a/ICSharpCode.Decompiler/IL/Transforms/CopyPropagation.cs b/ICSharpCode.Decompiler/IL/Transforms/CopyPropagation.cs index b96909efc..4c5fe176d 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/CopyPropagation.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/CopyPropagation.cs @@ -138,7 +138,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms }; block.Instructions.Insert(i++, new StLoc(uninlinedArgs[j], arg)); } - CollectionExtensions.AddRange(v.Function.Variables, uninlinedArgs); + v.Function.Variables.AddRange(uninlinedArgs); // perform copy propagation: foreach (var expr in v.LoadInstructions.ToArray()) { var clone = copiedExpr.Clone(); diff --git a/ICSharpCode.Decompiler/Util/CollectionExtensions.cs b/ICSharpCode.Decompiler/Util/CollectionExtensions.cs index 4c01285df..df585d159 100644 --- a/ICSharpCode.Decompiler/Util/CollectionExtensions.cs +++ b/ICSharpCode.Decompiler/Util/CollectionExtensions.cs @@ -12,10 +12,12 @@ namespace ICSharpCode.Decompiler.Util value = pair.Value; } +#if !NETCORE public static IEnumerable<(A, B)> Zip(this IEnumerable input1, IEnumerable input2) { return input1.Zip(input2, (a, b) => (a, b)); } +#endif public static IEnumerable<(A, B)> ZipLongest(this IEnumerable input1, IEnumerable input2) { @@ -51,10 +53,12 @@ namespace ICSharpCode.Decompiler.Util } } +#if !NETCORE public static HashSet ToHashSet(this IEnumerable input) { return new HashSet(input); } +#endif public static IEnumerable SkipLast(this IReadOnlyCollection input, int count) { @@ -323,7 +327,7 @@ namespace ICSharpCode.Decompiler.Util return first; } - #region Aliases/shortcuts for Enumerable extension methods +#region Aliases/shortcuts for Enumerable extension methods public static bool Any(this ICollection list) => list.Count > 0; public static bool Any(this T[] array, Predicate match) => Array.Exists(array, match); public static bool Any(this List list, Predicate match) => list.Exists(match); @@ -335,6 +339,6 @@ namespace ICSharpCode.Decompiler.Util public static T FirstOrDefault(this List list, Predicate predicate) => list.Find(predicate); public static T Last(this IList list) => list[list.Count - 1]; - #endregion +#endregion } }