From 7a976f197fe3ce1164ee1f3b7e6425540aeec1a2 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 28 Apr 2019 09:30:53 +0200 Subject: [PATCH] Fix #1500: anonymous type creation expression cannot have an object initializer. --- .../IL/Transforms/TransformCollectionAndObjectInitializers.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs b/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs index b2eb71718..c982f5f35 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs @@ -66,6 +66,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; if (DelegateConstruction.IsDelegateConstruction(newObjInst) || DelegateConstruction.IsPotentialClosure(context, newObjInst)) return false; + // Cannot build a collection/object initializer attached to an AnonymousTypeCreateExpression:s + // anon = new { A = 5 } { 3,4,5 } is invalid syntax. + if (newObjInst.Method.DeclaringType.ContainsAnonymousType()) + return false; instType = newObjInst.Method.DeclaringType; break; case DefaultValue defaultVal: