From 9035211d06bad64fedcebfd46ffcf457f66f4ac0 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 12 Sep 2017 11:22:21 +0200 Subject: [PATCH] Conditional defines should only be added once per symbol. --- ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs index 743aaae17..6862acb88 100644 --- a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs @@ -685,12 +685,14 @@ namespace ICSharpCode.Decompiler.CSharp } } + readonly HashSet definedSymbols = new HashSet(); + void AddDefinesForConditionalAttributes(ILFunction function) { foreach (var call in function.Descendants.OfType()) { var attr = call.Method.GetAttribute(new TopLevelTypeName("System.Diagnostics", nameof(ConditionalAttribute))); var symbolName = attr?.PositionalArguments.FirstOrDefault()?.ConstantValue as string; - if (symbolName == null) + if (symbolName == null || !definedSymbols.Add(symbolName)) continue; syntaxTree.InsertChildAfter(null, new PreProcessorDirective(PreProcessorDirectiveType.Define, symbolName), Roles.PreProcessorDirective); }