diff --git a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
index 97dfc1c44..2c3e9f93f 100644
--- a/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
+++ b/ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
@@ -152,6 +152,8 @@
+
+
diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoNewOfT.Expected.cs b/ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoNewOfT.Expected.cs
new file mode 100644
index 000000000..9cdf26361
--- /dev/null
+++ b/ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoNewOfT.Expected.cs
@@ -0,0 +1,68 @@
+using System;
+using System.Collections.Generic;
+
+namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly
+{
+ internal class NoNewOfT where TOnType : new()
+ {
+ public static TOnType CreateTOnType()
+ {
+#if !ROSLYN
+#if OPT
+ if (default(TOnType) != null)
+ {
+ return default(TOnType);
+ }
+ return Activator.CreateInstance();
+#else
+ return (default(TOnType) == null) ? Activator.CreateInstance() : default(TOnType);
+#endif
+#else
+ return Activator.CreateInstance();
+#endif
+ }
+
+ public static T CreateUnconstrainedT() where T : new()
+ {
+#if !ROSLYN
+#if OPT
+ if (default(T) != null)
+ {
+ return default(T);
+ }
+ return Activator.CreateInstance();
+#else
+ return (default(T) == null) ? Activator.CreateInstance() : default(T);
+#endif
+#else
+ return Activator.CreateInstance();
+#endif
+ }
+
+ public static T CreateClassT() where T : class, new()
+ {
+ return Activator.CreateInstance();
+ }
+
+ public static T CollectionInitializer() where T : IList, new()
+ {
+#if ROSLYN
+ T result = Activator.CreateInstance();
+ result.Add(1);
+ result.Add(2);
+ result.Add(3);
+ result.Add(4);
+ result.Add(5);
+ return result;
+#else
+ T val = ((default(T) == null) ? Activator.CreateInstance() : default(T));
+ val.Add(1);
+ val.Add(2);
+ val.Add(3);
+ val.Add(4);
+ val.Add(5);
+ return val;
+#endif
+ }
+ }
+}
diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoNewOfT.cs b/ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoNewOfT.cs
new file mode 100644
index 000000000..2ceec6ec2
--- /dev/null
+++ b/ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoNewOfT.cs
@@ -0,0 +1,27 @@
+using System.Collections.Generic;
+
+namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly
+{
+ internal class NoNewOfT where TOnType : new()
+ {
+ public static TOnType CreateTOnType()
+ {
+ return new TOnType();
+ }
+
+ public static T CreateUnconstrainedT() where T : new()
+ {
+ return new T();
+ }
+
+ public static T CreateClassT() where T : class, new()
+ {
+ return new T();
+ }
+
+ public static T CollectionInitializer() where T : IList, new()
+ {
+ return new T() { 1, 2, 3, 4, 5 };
+ }
+ }
+}
diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoNewOfT.il b/ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoNewOfT.il
new file mode 100644
index 000000000..59e8de7fd
--- /dev/null
+++ b/ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoNewOfT.il
@@ -0,0 +1,176 @@
+
+// .NET IL Disassembler. Version 9.0.4
+
+
+
+// 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 tmpvpdwr1
+{
+ .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.
+ .permissionset reqmin
+ = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}}
+ .hash algorithm 0x00008004
+ .ver 0:0:0:0
+}
+.module tmpvpdwr1.tmp
+// MVID: {8447adbb-757d-4626-b7b7-846d745d90d0}
+.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
+
+
+// =============== CLASS MEMBERS DECLARATION ===================
+
+.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoNewOfT`1<.ctor TOnType>
+ extends [mscorlib]System.Object
+{
+ .method public hidebysig static !TOnType
+ CreateTOnType() cil managed
+ {
+ // Code size 39 (0x27)
+ .maxstack 1
+ .locals init (!TOnType V_0,
+ !TOnType V_1)
+ IL_0000: nop
+ IL_0001: ldloca.s V_1
+ IL_0003: initobj !TOnType
+ IL_0009: ldloc.1
+ IL_000a: box !TOnType
+ IL_000f: brfalse.s IL_001c
+
+ IL_0011: ldloca.s V_1
+ IL_0013: initobj !TOnType
+ IL_0019: ldloc.1
+ IL_001a: br.s IL_0021
+
+ IL_001c: call !!0 [mscorlib]System.Activator::CreateInstance()
+ IL_0021: nop
+ IL_0022: stloc.0
+ IL_0023: br.s IL_0025
+
+ IL_0025: ldloc.0
+ IL_0026: ret
+ } // end of method NoNewOfT`1::CreateTOnType
+
+ .method public hidebysig static !!T CreateUnconstrainedT<.ctor T>() cil managed
+ {
+ // Code size 39 (0x27)
+ .maxstack 1
+ .locals init (!!T V_0,
+ !!T V_1)
+ IL_0000: nop
+ IL_0001: ldloca.s V_1
+ IL_0003: initobj !!T
+ IL_0009: ldloc.1
+ IL_000a: box !!T
+ IL_000f: brfalse.s IL_001c
+
+ IL_0011: ldloca.s V_1
+ IL_0013: initobj !!T
+ IL_0019: ldloc.1
+ IL_001a: br.s IL_0021
+
+ IL_001c: call !!0 [mscorlib]System.Activator::CreateInstance()
+ IL_0021: nop
+ IL_0022: stloc.0
+ IL_0023: br.s IL_0025
+
+ IL_0025: ldloc.0
+ IL_0026: ret
+ } // end of method NoNewOfT`1::CreateUnconstrainedT
+
+ .method public hidebysig static !!T CreateClassT() cil managed
+ {
+ // Code size 11 (0xb)
+ .maxstack 1
+ .locals init (!!T V_0)
+ IL_0000: nop
+ IL_0001: call !!0 [mscorlib]System.Activator::CreateInstance()
+ IL_0006: stloc.0
+ IL_0007: br.s IL_0009
+
+ IL_0009: ldloc.0
+ IL_000a: ret
+ } // end of method NoNewOfT`1::CreateClassT
+
+ .method public hidebysig static !!T CollectionInitializer<.ctor (class [mscorlib]System.Collections.Generic.IList`1) T>() cil managed
+ {
+ // Code size 106 (0x6a)
+ .maxstack 2
+ .locals init (!!T V_0,
+ !!T V_1,
+ !!T V_2)
+ IL_0000: nop
+ IL_0001: ldloca.s V_2
+ IL_0003: initobj !!T
+ IL_0009: ldloc.2
+ IL_000a: box !!T
+ IL_000f: brfalse.s IL_001c
+
+ IL_0011: ldloca.s V_2
+ IL_0013: initobj !!T
+ IL_0019: ldloc.2
+ IL_001a: br.s IL_0021
+
+ IL_001c: call !!0 [mscorlib]System.Activator::CreateInstance()
+ IL_0021: nop
+ IL_0022: stloc.0
+ IL_0023: ldloc.0
+ IL_0024: box !!T
+ IL_0029: ldc.i4.1
+ IL_002a: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_002f: nop
+ IL_0030: ldloc.0
+ IL_0031: box !!T
+ IL_0036: ldc.i4.2
+ IL_0037: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_003c: nop
+ IL_003d: ldloc.0
+ IL_003e: box !!T
+ IL_0043: ldc.i4.3
+ IL_0044: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_0049: nop
+ IL_004a: ldloc.0
+ IL_004b: box !!T
+ IL_0050: ldc.i4.4
+ IL_0051: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_0056: nop
+ IL_0057: ldloc.0
+ IL_0058: box !!T
+ IL_005d: ldc.i4.5
+ IL_005e: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_0063: nop
+ IL_0064: ldloc.0
+ IL_0065: stloc.1
+ IL_0066: br.s IL_0068
+
+ IL_0068: ldloc.1
+ IL_0069: ret
+ } // end of method NoNewOfT`1::CollectionInitializer
+
+ .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 NoNewOfT`1::.ctor
+
+} // end of class ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoNewOfT`1
+
+
+// =============================================================
+
+// *********** DISASSEMBLY COMPLETE ***********************
diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoNewOfT.net40.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoNewOfT.net40.roslyn.il
new file mode 100644
index 000000000..a46e2be15
--- /dev/null
+++ b/ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoNewOfT.net40.roslyn.il
@@ -0,0 +1,241 @@
+
+// .NET IL Disassembler. Version 9.0.4
+
+
+
+// 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 tmpyccvci
+{
+ .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 tmpyccvci.tmp
+// MVID: {ff6a33b6-7f19-447b-b168-f5c528dc4b6f}
+.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
+.custom instance void System.Runtime.CompilerServices.RefSafetyRulesAttribute::.ctor(int32) = ( 01 00 0B 00 00 00 00 00 )
+.imagebase 0x10000000
+.file alignment 0x00000200
+.stackreserve 0x00100000
+.subsystem 0x0003 // WINDOWS_CUI
+.corflags 0x00000001 // ILONLY
+
+
+// =============== CLASS MEMBERS DECLARATION ===================
+
+.class private auto ansi sealed beforefieldinit Microsoft.CodeAnalysis.EmbeddedAttribute
+ extends [mscorlib]System.Attribute
+{
+ .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
+ .custom instance void Microsoft.CodeAnalysis.EmbeddedAttribute::.ctor() = ( 01 00 00 00 )
+ .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.Attribute::.ctor()
+ IL_0006: nop
+ IL_0007: ret
+ } // end of method EmbeddedAttribute::.ctor
+
+} // end of class Microsoft.CodeAnalysis.EmbeddedAttribute
+
+.class private auto ansi sealed beforefieldinit System.Runtime.CompilerServices.RefSafetyRulesAttribute
+ extends [mscorlib]System.Attribute
+{
+ .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
+ .custom instance void Microsoft.CodeAnalysis.EmbeddedAttribute::.ctor() = ( 01 00 00 00 )
+ .custom instance void [mscorlib]System.AttributeUsageAttribute::.ctor(valuetype [mscorlib]System.AttributeTargets) = ( 01 00 02 00 00 00 02 00 54 02 0D 41 6C 6C 6F 77 // ........T..Allow
+ 4D 75 6C 74 69 70 6C 65 00 54 02 09 49 6E 68 65 // Multiple.T..Inhe
+ 72 69 74 65 64 00 ) // rited.
+ .field public initonly int32 Version
+ .method public hidebysig specialname rtspecialname
+ instance void .ctor(int32 A_1) cil managed
+ {
+ // Code size 15 (0xf)
+ .maxstack 8
+ IL_0000: ldarg.0
+ IL_0001: call instance void [mscorlib]System.Attribute::.ctor()
+ IL_0006: nop
+ IL_0007: ldarg.0
+ IL_0008: ldarg.1
+ IL_0009: stfld int32 System.Runtime.CompilerServices.RefSafetyRulesAttribute::Version
+ IL_000e: ret
+ } // end of method RefSafetyRulesAttribute::.ctor
+
+} // end of class System.Runtime.CompilerServices.RefSafetyRulesAttribute
+
+.class private auto ansi sealed beforefieldinit System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute
+ extends [mscorlib]System.Attribute
+{
+ .custom instance void [mscorlib]System.AttributeUsageAttribute::.ctor(valuetype [mscorlib]System.AttributeTargets) = ( 01 00 FF 7F 00 00 02 00 54 02 0D 41 6C 6C 6F 77 // ........T..Allow
+ 4D 75 6C 74 69 70 6C 65 01 54 02 09 49 6E 68 65 // Multiple.T..Inhe
+ 72 69 74 65 64 00 ) // rited.
+ .method public hidebysig specialname rtspecialname
+ instance void .ctor(string featureName) cil managed
+ {
+ // Code size 9 (0x9)
+ .maxstack 8
+ IL_0000: ldarg.0
+ IL_0001: call instance void [mscorlib]System.Attribute::.ctor()
+ IL_0006: nop
+ IL_0007: nop
+ IL_0008: ret
+ } // end of method CompilerFeatureRequiredAttribute::.ctor
+
+} // end of class System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute
+
+.class private auto ansi beforefieldinit System.Runtime.CompilerServices.IsExternalInit
+ extends [mscorlib]System.Object
+{
+ .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 IsExternalInit::.ctor
+
+} // end of class System.Runtime.CompilerServices.IsExternalInit
+
+.class private auto ansi sealed beforefieldinit System.Runtime.CompilerServices.RequiredMemberAttribute
+ extends [mscorlib]System.Attribute
+{
+ .custom instance void [mscorlib]System.AttributeUsageAttribute::.ctor(valuetype [mscorlib]System.AttributeTargets) = ( 01 00 8C 01 00 00 02 00 54 02 0D 41 6C 6C 6F 77 // ........T..Allow
+ 4D 75 6C 74 69 70 6C 65 00 54 02 09 49 6E 68 65 // Multiple.T..Inhe
+ 72 69 74 65 64 00 ) // rited.
+ .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.Attribute::.ctor()
+ IL_0006: nop
+ IL_0007: ret
+ } // end of method RequiredMemberAttribute::.ctor
+
+} // end of class System.Runtime.CompilerServices.RequiredMemberAttribute
+
+.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoNewOfT`1<.ctor TOnType>
+ extends [mscorlib]System.Object
+{
+ .method public hidebysig static !TOnType
+ CreateTOnType() cil managed
+ {
+ // Code size 11 (0xb)
+ .maxstack 1
+ .locals init (!TOnType V_0)
+ IL_0000: nop
+ IL_0001: call !!0 [mscorlib]System.Activator::CreateInstance()
+ IL_0006: stloc.0
+ IL_0007: br.s IL_0009
+
+ IL_0009: ldloc.0
+ IL_000a: ret
+ } // end of method NoNewOfT`1::CreateTOnType
+
+ .method public hidebysig static !!T CreateUnconstrainedT<.ctor T>() cil managed
+ {
+ // Code size 11 (0xb)
+ .maxstack 1
+ .locals init (!!T V_0)
+ IL_0000: nop
+ IL_0001: call !!0 [mscorlib]System.Activator::CreateInstance()
+ IL_0006: stloc.0
+ IL_0007: br.s IL_0009
+
+ IL_0009: ldloc.0
+ IL_000a: ret
+ } // end of method NoNewOfT`1::CreateUnconstrainedT
+
+ .method public hidebysig static !!T CreateClassT() cil managed
+ {
+ // Code size 11 (0xb)
+ .maxstack 1
+ .locals init (!!T V_0)
+ IL_0000: nop
+ IL_0001: call !!0 [mscorlib]System.Activator::CreateInstance()
+ IL_0006: stloc.0
+ IL_0007: br.s IL_0009
+
+ IL_0009: ldloc.0
+ IL_000a: ret
+ } // end of method NoNewOfT`1::CreateClassT
+
+ .method public hidebysig static !!T CollectionInitializer<.ctor (class [mscorlib]System.Collections.Generic.IList`1) T>() cil managed
+ {
+ // Code size 88 (0x58)
+ .maxstack 2
+ .locals init (!!T V_0,
+ !!T V_1)
+ IL_0000: nop
+ IL_0001: call !!0 [mscorlib]System.Activator::CreateInstance()
+ IL_0006: stloc.0
+ IL_0007: ldloca.s V_0
+ IL_0009: ldc.i4.1
+ IL_000a: constrained. !!T
+ IL_0010: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_0015: nop
+ IL_0016: ldloca.s V_0
+ IL_0018: ldc.i4.2
+ IL_0019: constrained. !!T
+ IL_001f: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_0024: nop
+ IL_0025: ldloca.s V_0
+ IL_0027: ldc.i4.3
+ IL_0028: constrained. !!T
+ IL_002e: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_0033: nop
+ IL_0034: ldloca.s V_0
+ IL_0036: ldc.i4.4
+ IL_0037: constrained. !!T
+ IL_003d: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_0042: nop
+ IL_0043: ldloca.s V_0
+ IL_0045: ldc.i4.5
+ IL_0046: constrained. !!T
+ IL_004c: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_0051: nop
+ IL_0052: ldloc.0
+ IL_0053: stloc.1
+ IL_0054: br.s IL_0056
+
+ IL_0056: ldloc.1
+ IL_0057: ret
+ } // end of method NoNewOfT`1::CollectionInitializer
+
+ .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 NoNewOfT`1::.ctor
+
+} // end of class ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoNewOfT`1
+
+
+// =============================================================
+
+// *********** DISASSEMBLY COMPLETE ***********************
diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoNewOfT.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoNewOfT.opt.il
new file mode 100644
index 000000000..c49b5ab54
--- /dev/null
+++ b/ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoNewOfT.opt.il
@@ -0,0 +1,147 @@
+
+// .NET IL Disassembler. Version 9.0.4
+
+
+
+// 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 tmp1ekgox
+{
+ .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.
+ .permissionset reqmin
+ = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}}
+ .hash algorithm 0x00008004
+ .ver 0:0:0:0
+}
+.module tmp1ekgox.tmp
+// MVID: {67ce32bd-0144-4136-a198-2fc9f941f624}
+.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
+
+
+// =============== CLASS MEMBERS DECLARATION ===================
+
+.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoNewOfT`1<.ctor TOnType>
+ extends [mscorlib]System.Object
+{
+ .method public hidebysig static !TOnType
+ CreateTOnType() cil managed
+ {
+ // Code size 32 (0x20)
+ .maxstack 1
+ .locals init (!TOnType V_0,
+ !TOnType V_1)
+ IL_0000: ldloca.s V_0
+ IL_0002: initobj !TOnType
+ IL_0008: ldloc.0
+ IL_0009: box !TOnType
+ IL_000e: brfalse.s IL_001a
+
+ IL_0010: ldloca.s V_1
+ IL_0012: initobj !TOnType
+ IL_0018: ldloc.1
+ IL_0019: ret
+
+ IL_001a: call !!0 [mscorlib]System.Activator::CreateInstance()
+ IL_001f: ret
+ } // end of method NoNewOfT`1::CreateTOnType
+
+ .method public hidebysig static !!T CreateUnconstrainedT<.ctor T>() cil managed
+ {
+ // Code size 32 (0x20)
+ .maxstack 1
+ .locals init (!!T V_0,
+ !!T V_1)
+ IL_0000: ldloca.s V_0
+ IL_0002: initobj !!T
+ IL_0008: ldloc.0
+ IL_0009: box !!T
+ IL_000e: brfalse.s IL_001a
+
+ IL_0010: ldloca.s V_1
+ IL_0012: initobj !!T
+ IL_0018: ldloc.1
+ IL_0019: ret
+
+ IL_001a: call !!0 [mscorlib]System.Activator::CreateInstance()
+ IL_001f: ret
+ } // end of method NoNewOfT`1::CreateUnconstrainedT
+
+ .method public hidebysig static !!T CreateClassT() cil managed
+ {
+ // Code size 6 (0x6)
+ .maxstack 8
+ IL_0000: call !!0 [mscorlib]System.Activator::CreateInstance()
+ IL_0005: ret
+ } // end of method NoNewOfT`1::CreateClassT
+
+ .method public hidebysig static !!T CollectionInitializer<.ctor (class [mscorlib]System.Collections.Generic.IList`1) T>() cil managed
+ {
+ // Code size 95 (0x5f)
+ .maxstack 2
+ .locals init (!!T V_0,
+ !!T V_1,
+ !!T V_2)
+ IL_0000: ldloca.s V_1
+ IL_0002: initobj !!T
+ IL_0008: ldloc.1
+ IL_0009: box !!T
+ IL_000e: brfalse.s IL_001b
+
+ IL_0010: ldloca.s V_2
+ IL_0012: initobj !!T
+ IL_0018: ldloc.2
+ IL_0019: br.s IL_0020
+
+ IL_001b: call !!0 [mscorlib]System.Activator::CreateInstance()
+ IL_0020: stloc.0
+ IL_0021: ldloc.0
+ IL_0022: box !!T
+ IL_0027: ldc.i4.1
+ IL_0028: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_002d: ldloc.0
+ IL_002e: box !!T
+ IL_0033: ldc.i4.2
+ IL_0034: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_0039: ldloc.0
+ IL_003a: box !!T
+ IL_003f: ldc.i4.3
+ IL_0040: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_0045: ldloc.0
+ IL_0046: box !!T
+ IL_004b: ldc.i4.4
+ IL_004c: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_0051: ldloc.0
+ IL_0052: box !!T
+ IL_0057: ldc.i4.5
+ IL_0058: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_005d: ldloc.0
+ IL_005e: ret
+ } // end of method NoNewOfT`1::CollectionInitializer
+
+ .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 NoNewOfT`1::.ctor
+
+} // end of class ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoNewOfT`1
+
+
+// =============================================================
+
+// *********** DISASSEMBLY COMPLETE ***********************
diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoNewOfT.opt.net40.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoNewOfT.opt.net40.roslyn.il
new file mode 100644
index 000000000..849b7843d
--- /dev/null
+++ b/ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoNewOfT.opt.net40.roslyn.il
@@ -0,0 +1,205 @@
+
+// .NET IL Disassembler. Version 9.0.4
+
+
+
+// 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 tmp4xstme
+{
+ .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 tmp4xstme.tmp
+// MVID: {a031faef-fcb2-420c-9cd3-6e9b01e7f81e}
+.custom instance void [mscorlib]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
+.custom instance void System.Runtime.CompilerServices.RefSafetyRulesAttribute::.ctor(int32) = ( 01 00 0B 00 00 00 00 00 )
+.imagebase 0x10000000
+.file alignment 0x00000200
+.stackreserve 0x00100000
+.subsystem 0x0003 // WINDOWS_CUI
+.corflags 0x00000001 // ILONLY
+
+
+// =============== CLASS MEMBERS DECLARATION ===================
+
+.class private auto ansi sealed beforefieldinit Microsoft.CodeAnalysis.EmbeddedAttribute
+ extends [mscorlib]System.Attribute
+{
+ .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
+ .custom instance void Microsoft.CodeAnalysis.EmbeddedAttribute::.ctor() = ( 01 00 00 00 )
+ .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.Attribute::.ctor()
+ IL_0006: ret
+ } // end of method EmbeddedAttribute::.ctor
+
+} // end of class Microsoft.CodeAnalysis.EmbeddedAttribute
+
+.class private auto ansi sealed beforefieldinit System.Runtime.CompilerServices.RefSafetyRulesAttribute
+ extends [mscorlib]System.Attribute
+{
+ .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
+ .custom instance void Microsoft.CodeAnalysis.EmbeddedAttribute::.ctor() = ( 01 00 00 00 )
+ .custom instance void [mscorlib]System.AttributeUsageAttribute::.ctor(valuetype [mscorlib]System.AttributeTargets) = ( 01 00 02 00 00 00 02 00 54 02 0D 41 6C 6C 6F 77 // ........T..Allow
+ 4D 75 6C 74 69 70 6C 65 00 54 02 09 49 6E 68 65 // Multiple.T..Inhe
+ 72 69 74 65 64 00 ) // rited.
+ .field public initonly int32 Version
+ .method public hidebysig specialname rtspecialname
+ instance void .ctor(int32 A_1) cil managed
+ {
+ // Code size 14 (0xe)
+ .maxstack 8
+ IL_0000: ldarg.0
+ IL_0001: call instance void [mscorlib]System.Attribute::.ctor()
+ IL_0006: ldarg.0
+ IL_0007: ldarg.1
+ IL_0008: stfld int32 System.Runtime.CompilerServices.RefSafetyRulesAttribute::Version
+ IL_000d: ret
+ } // end of method RefSafetyRulesAttribute::.ctor
+
+} // end of class System.Runtime.CompilerServices.RefSafetyRulesAttribute
+
+.class private auto ansi sealed beforefieldinit System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute
+ extends [mscorlib]System.Attribute
+{
+ .custom instance void [mscorlib]System.AttributeUsageAttribute::.ctor(valuetype [mscorlib]System.AttributeTargets) = ( 01 00 FF 7F 00 00 02 00 54 02 0D 41 6C 6C 6F 77 // ........T..Allow
+ 4D 75 6C 74 69 70 6C 65 01 54 02 09 49 6E 68 65 // Multiple.T..Inhe
+ 72 69 74 65 64 00 ) // rited.
+ .method public hidebysig specialname rtspecialname
+ instance void .ctor(string featureName) cil managed
+ {
+ // Code size 7 (0x7)
+ .maxstack 8
+ IL_0000: ldarg.0
+ IL_0001: call instance void [mscorlib]System.Attribute::.ctor()
+ IL_0006: ret
+ } // end of method CompilerFeatureRequiredAttribute::.ctor
+
+} // end of class System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute
+
+.class private auto ansi beforefieldinit System.Runtime.CompilerServices.IsExternalInit
+ extends [mscorlib]System.Object
+{
+ .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 IsExternalInit::.ctor
+
+} // end of class System.Runtime.CompilerServices.IsExternalInit
+
+.class private auto ansi sealed beforefieldinit System.Runtime.CompilerServices.RequiredMemberAttribute
+ extends [mscorlib]System.Attribute
+{
+ .custom instance void [mscorlib]System.AttributeUsageAttribute::.ctor(valuetype [mscorlib]System.AttributeTargets) = ( 01 00 8C 01 00 00 02 00 54 02 0D 41 6C 6C 6F 77 // ........T..Allow
+ 4D 75 6C 74 69 70 6C 65 00 54 02 09 49 6E 68 65 // Multiple.T..Inhe
+ 72 69 74 65 64 00 ) // rited.
+ .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.Attribute::.ctor()
+ IL_0006: ret
+ } // end of method RequiredMemberAttribute::.ctor
+
+} // end of class System.Runtime.CompilerServices.RequiredMemberAttribute
+
+.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoNewOfT`1<.ctor TOnType>
+ extends [mscorlib]System.Object
+{
+ .method public hidebysig static !TOnType
+ CreateTOnType() cil managed
+ {
+ // Code size 6 (0x6)
+ .maxstack 8
+ IL_0000: call !!0 [mscorlib]System.Activator::CreateInstance()
+ IL_0005: ret
+ } // end of method NoNewOfT`1::CreateTOnType
+
+ .method public hidebysig static !!T CreateUnconstrainedT<.ctor T>() cil managed
+ {
+ // Code size 6 (0x6)
+ .maxstack 8
+ IL_0000: call !!0 [mscorlib]System.Activator::CreateInstance()
+ IL_0005: ret
+ } // end of method NoNewOfT`1::CreateUnconstrainedT
+
+ .method public hidebysig static !!T CreateClassT() cil managed
+ {
+ // Code size 6 (0x6)
+ .maxstack 8
+ IL_0000: call !!0 [mscorlib]System.Activator::CreateInstance()
+ IL_0005: ret
+ } // end of method NoNewOfT`1::CreateClassT
+
+ .method public hidebysig static !!T CollectionInitializer<.ctor (class [mscorlib]System.Collections.Generic.IList`1) T>() cil managed
+ {
+ // Code size 78 (0x4e)
+ .maxstack 2
+ .locals init (!!T V_0)
+ IL_0000: call !!0 [mscorlib]System.Activator::CreateInstance()
+ IL_0005: stloc.0
+ IL_0006: ldloca.s V_0
+ IL_0008: ldc.i4.1
+ IL_0009: constrained. !!T
+ IL_000f: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_0014: ldloca.s V_0
+ IL_0016: ldc.i4.2
+ IL_0017: constrained. !!T
+ IL_001d: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_0022: ldloca.s V_0
+ IL_0024: ldc.i4.3
+ IL_0025: constrained. !!T
+ IL_002b: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_0030: ldloca.s V_0
+ IL_0032: ldc.i4.4
+ IL_0033: constrained. !!T
+ IL_0039: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_003e: ldloca.s V_0
+ IL_0040: ldc.i4.5
+ IL_0041: constrained. !!T
+ IL_0047: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_004c: ldloc.0
+ IL_004d: ret
+ } // end of method NoNewOfT`1::CollectionInitializer
+
+ .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 NoNewOfT`1::.ctor
+
+} // end of class ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoNewOfT`1
+
+
+// =============================================================
+
+// *********** DISASSEMBLY COMPLETE ***********************
diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoNewOfT.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoNewOfT.opt.roslyn.il
new file mode 100644
index 000000000..75c9478f9
--- /dev/null
+++ b/ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoNewOfT.opt.roslyn.il
@@ -0,0 +1,115 @@
+
+// .NET IL Disassembler. Version 9.0.4
+
+
+
+// Metadata version: v4.0.30319
+.assembly extern System.Runtime
+{
+ .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) // .?_....:
+ .ver 10:0:0:0
+}
+.assembly tmpauzspg
+{
+ .custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
+ .custom instance void [System.Runtime]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 [System.Runtime]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [System.Runtime]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 02 00 00 00 00 00 )
+
+ .custom instance void [System.Runtime]System.Runtime.Versioning.TargetFrameworkAttribute::.ctor(string) = ( 01 00 19 2E 4E 45 54 43 6F 72 65 41 70 70 2C 56 // ....NETCoreApp,V
+ 65 72 73 69 6F 6E 3D 76 31 30 2E 30 00 00 ) // ersion=v10.0..
+ .permissionset reqmin
+ = {[System.Runtime]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}}
+ .hash algorithm 0x00008004
+ .ver 0:0:0:0
+}
+.module tmpauzspg.tmp
+// MVID: {6d3a3b63-d01c-49f7-9515-565421f78266}
+.custom instance void [System.Runtime]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
+.custom instance void [System.Runtime]System.Runtime.CompilerServices.RefSafetyRulesAttribute::.ctor(int32) = ( 01 00 0B 00 00 00 00 00 )
+.imagebase 0x10000000
+.file alignment 0x00000200
+.stackreserve 0x00100000
+.subsystem 0x0003 // WINDOWS_CUI
+.corflags 0x00000001 // ILONLY
+
+
+// =============== CLASS MEMBERS DECLARATION ===================
+
+.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoNewOfT`1<.ctor TOnType>
+ extends [System.Runtime]System.Object
+{
+ .method public hidebysig static !TOnType
+ CreateTOnType() cil managed
+ {
+ // Code size 6 (0x6)
+ .maxstack 8
+ IL_0000: call !!0 [System.Runtime]System.Activator::CreateInstance()
+ IL_0005: ret
+ } // end of method NoNewOfT`1::CreateTOnType
+
+ .method public hidebysig static !!T CreateUnconstrainedT<.ctor T>() cil managed
+ {
+ // Code size 6 (0x6)
+ .maxstack 8
+ IL_0000: call !!0 [System.Runtime]System.Activator::CreateInstance()
+ IL_0005: ret
+ } // end of method NoNewOfT`1::CreateUnconstrainedT
+
+ .method public hidebysig static !!T CreateClassT() cil managed
+ {
+ // Code size 6 (0x6)
+ .maxstack 8
+ IL_0000: call !!0 [System.Runtime]System.Activator::CreateInstance()
+ IL_0005: ret
+ } // end of method NoNewOfT`1::CreateClassT
+
+ .method public hidebysig static !!T CollectionInitializer<.ctor (class [System.Runtime]System.Collections.Generic.IList`1) T>() cil managed
+ {
+ // Code size 78 (0x4e)
+ .maxstack 2
+ .locals init (!!T V_0)
+ IL_0000: call !!0 [System.Runtime]System.Activator::CreateInstance()
+ IL_0005: stloc.0
+ IL_0006: ldloca.s V_0
+ IL_0008: ldc.i4.1
+ IL_0009: constrained. !!T
+ IL_000f: callvirt instance void class [System.Runtime]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_0014: ldloca.s V_0
+ IL_0016: ldc.i4.2
+ IL_0017: constrained. !!T
+ IL_001d: callvirt instance void class [System.Runtime]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_0022: ldloca.s V_0
+ IL_0024: ldc.i4.3
+ IL_0025: constrained. !!T
+ IL_002b: callvirt instance void class [System.Runtime]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_0030: ldloca.s V_0
+ IL_0032: ldc.i4.4
+ IL_0033: constrained. !!T
+ IL_0039: callvirt instance void class [System.Runtime]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_003e: ldloca.s V_0
+ IL_0040: ldc.i4.5
+ IL_0041: constrained. !!T
+ IL_0047: callvirt instance void class [System.Runtime]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_004c: ldloc.0
+ IL_004d: ret
+ } // end of method NoNewOfT`1::CollectionInitializer
+
+ .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 [System.Runtime]System.Object::.ctor()
+ IL_0006: ret
+ } // end of method NoNewOfT`1::.ctor
+
+} // end of class ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoNewOfT`1
+
+
+// =============================================================
+
+// *********** DISASSEMBLY COMPLETE ***********************
diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoNewOfT.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoNewOfT.roslyn.il
new file mode 100644
index 000000000..3706f9e89
--- /dev/null
+++ b/ICSharpCode.Decompiler.Tests/TestCases/Ugly/NoNewOfT.roslyn.il
@@ -0,0 +1,145 @@
+
+// .NET IL Disassembler. Version 9.0.4
+
+
+
+// Metadata version: v4.0.30319
+.assembly extern System.Runtime
+{
+ .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) // .?_....:
+ .ver 10:0:0:0
+}
+.assembly tmpybdlca
+{
+ .custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 )
+ .custom instance void [System.Runtime]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 [System.Runtime]System.Diagnostics.DebuggableAttribute::.ctor(valuetype [System.Runtime]System.Diagnostics.DebuggableAttribute/DebuggingModes) = ( 01 00 07 01 00 00 00 00 )
+
+ .custom instance void [System.Runtime]System.Runtime.Versioning.TargetFrameworkAttribute::.ctor(string) = ( 01 00 19 2E 4E 45 54 43 6F 72 65 41 70 70 2C 56 // ....NETCoreApp,V
+ 65 72 73 69 6F 6E 3D 76 31 30 2E 30 00 00 ) // ersion=v10.0..
+ .permissionset reqmin
+ = {[System.Runtime]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}}
+ .hash algorithm 0x00008004
+ .ver 0:0:0:0
+}
+.module tmpybdlca.tmp
+// MVID: {b57f13a4-d291-42ea-b595-3766c1f1470c}
+.custom instance void [System.Runtime]System.Security.UnverifiableCodeAttribute::.ctor() = ( 01 00 00 00 )
+.custom instance void [System.Runtime]System.Runtime.CompilerServices.RefSafetyRulesAttribute::.ctor(int32) = ( 01 00 0B 00 00 00 00 00 )
+.imagebase 0x10000000
+.file alignment 0x00000200
+.stackreserve 0x00100000
+.subsystem 0x0003 // WINDOWS_CUI
+.corflags 0x00000001 // ILONLY
+
+
+// =============== CLASS MEMBERS DECLARATION ===================
+
+.class private auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoNewOfT`1<.ctor TOnType>
+ extends [System.Runtime]System.Object
+{
+ .method public hidebysig static !TOnType
+ CreateTOnType() cil managed
+ {
+ // Code size 11 (0xb)
+ .maxstack 1
+ .locals init (!TOnType V_0)
+ IL_0000: nop
+ IL_0001: call !!0 [System.Runtime]System.Activator::CreateInstance()
+ IL_0006: stloc.0
+ IL_0007: br.s IL_0009
+
+ IL_0009: ldloc.0
+ IL_000a: ret
+ } // end of method NoNewOfT`1::CreateTOnType
+
+ .method public hidebysig static !!T CreateUnconstrainedT<.ctor T>() cil managed
+ {
+ // Code size 11 (0xb)
+ .maxstack 1
+ .locals init (!!T V_0)
+ IL_0000: nop
+ IL_0001: call !!0 [System.Runtime]System.Activator::CreateInstance()
+ IL_0006: stloc.0
+ IL_0007: br.s IL_0009
+
+ IL_0009: ldloc.0
+ IL_000a: ret
+ } // end of method NoNewOfT`1::CreateUnconstrainedT
+
+ .method public hidebysig static !!T CreateClassT() cil managed
+ {
+ // Code size 11 (0xb)
+ .maxstack 1
+ .locals init (!!T V_0)
+ IL_0000: nop
+ IL_0001: call !!0 [System.Runtime]System.Activator::CreateInstance()
+ IL_0006: stloc.0
+ IL_0007: br.s IL_0009
+
+ IL_0009: ldloc.0
+ IL_000a: ret
+ } // end of method NoNewOfT`1::CreateClassT
+
+ .method public hidebysig static !!T CollectionInitializer<.ctor (class [System.Runtime]System.Collections.Generic.IList`1) T>() cil managed
+ {
+ // Code size 88 (0x58)
+ .maxstack 2
+ .locals init (!!T V_0,
+ !!T V_1)
+ IL_0000: nop
+ IL_0001: call !!0 [System.Runtime]System.Activator::CreateInstance()
+ IL_0006: stloc.0
+ IL_0007: ldloca.s V_0
+ IL_0009: ldc.i4.1
+ IL_000a: constrained. !!T
+ IL_0010: callvirt instance void class [System.Runtime]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_0015: nop
+ IL_0016: ldloca.s V_0
+ IL_0018: ldc.i4.2
+ IL_0019: constrained. !!T
+ IL_001f: callvirt instance void class [System.Runtime]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_0024: nop
+ IL_0025: ldloca.s V_0
+ IL_0027: ldc.i4.3
+ IL_0028: constrained. !!T
+ IL_002e: callvirt instance void class [System.Runtime]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_0033: nop
+ IL_0034: ldloca.s V_0
+ IL_0036: ldc.i4.4
+ IL_0037: constrained. !!T
+ IL_003d: callvirt instance void class [System.Runtime]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_0042: nop
+ IL_0043: ldloca.s V_0
+ IL_0045: ldc.i4.5
+ IL_0046: constrained. !!T
+ IL_004c: callvirt instance void class [System.Runtime]System.Collections.Generic.ICollection`1::Add(!0)
+ IL_0051: nop
+ IL_0052: ldloc.0
+ IL_0053: stloc.1
+ IL_0054: br.s IL_0056
+
+ IL_0056: ldloc.1
+ IL_0057: ret
+ } // end of method NoNewOfT`1::CollectionInitializer
+
+ .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 [System.Runtime]System.Object::.ctor()
+ IL_0006: nop
+ IL_0007: ret
+ } // end of method NoNewOfT`1::.ctor
+
+} // end of class ICSharpCode.Decompiler.Tests.TestCases.Ugly.NoNewOfT`1
+
+
+// =============================================================
+
+// *********** DISASSEMBLY COMPLETE ***********************
diff --git a/ICSharpCode.Decompiler.Tests/UglyTestRunner.cs b/ICSharpCode.Decompiler.Tests/UglyTestRunner.cs
index bc60f38c9..f6b05db1b 100644
--- a/ICSharpCode.Decompiler.Tests/UglyTestRunner.cs
+++ b/ICSharpCode.Decompiler.Tests/UglyTestRunner.cs
@@ -17,7 +17,6 @@
// DEALINGS IN THE SOFTWARE.
using System;
-using System.CodeDom.Compiler;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
@@ -132,6 +131,12 @@ namespace ICSharpCode.Decompiler.Tests
});
}
+ [Test]
+ public async Task NoNewOfT([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
+ {
+ await RunForLibrary(cscOptions: cscOptions, decompilerSettings: new DecompilerSettings(CSharp.LanguageVersion.CSharp1));
+ }
+
async Task RunForLibrary([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CompilerOptions cscOptions = CompilerOptions.None, DecompilerSettings decompilerSettings = null)
{
await Run(testName, asmOptions | AssemblerOptions.Library, cscOptions | CompilerOptions.Library, decompilerSettings);
diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/ReplaceMethodCallsWithOperators.cs b/ICSharpCode.Decompiler/CSharp/Transforms/ReplaceMethodCallsWithOperators.cs
index 287d7e3f3..37e8409d4 100644
--- a/ICSharpCode.Decompiler/CSharp/Transforms/ReplaceMethodCallsWithOperators.cs
+++ b/ICSharpCode.Decompiler/CSharp/Transforms/ReplaceMethodCallsWithOperators.cs
@@ -138,7 +138,10 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
break;
*/
case "System.Activator.CreateInstance":
- if (arguments.Length == 0 && method.TypeArguments.Count == 1 && IsInstantiableTypeParameter(method.TypeArguments[0]))
+ if (context.Settings.UseObjectCreationOfGenericTypeParameter &&
+ arguments.Length == 0 &&
+ method.TypeArguments.Count == 1 &&
+ IsInstantiableTypeParameter(method.TypeArguments[0]))
{
invocationExpression.ReplaceWith(new ObjectCreateExpression(context.TypeSystemAstBuilder.ConvertType(method.TypeArguments.First())));
}
diff --git a/ICSharpCode.Decompiler/DecompilerSettings.cs b/ICSharpCode.Decompiler/DecompilerSettings.cs
index 980fcef13..6a0078a8d 100644
--- a/ICSharpCode.Decompiler/DecompilerSettings.cs
+++ b/ICSharpCode.Decompiler/DecompilerSettings.cs
@@ -63,6 +63,7 @@ namespace ICSharpCode.Decompiler
liftNullables = false;
yieldReturn = false;
useImplicitMethodGroupConversion = false;
+ useObjectCreationOfGenericTypeParameter = false;
}
if (languageVersion < CSharp.LanguageVersion.CSharp3)
{
@@ -210,7 +211,7 @@ namespace ICSharpCode.Decompiler
if (anonymousTypes || objectCollectionInitializers || automaticProperties
|| queryExpressions || expressionTrees)
return CSharp.LanguageVersion.CSharp3;
- if (anonymousMethods || liftNullables || yieldReturn || useImplicitMethodGroupConversion)
+ if (anonymousMethods || liftNullables || yieldReturn || useImplicitMethodGroupConversion || useObjectCreationOfGenericTypeParameter)
return CSharp.LanguageVersion.CSharp2;
return CSharp.LanguageVersion.CSharp1;
}
@@ -986,6 +987,26 @@ namespace ICSharpCode.Decompiler
}
}
+ bool useObjectCreationOfGenericTypeParameter = true;
+
+ ///
+ /// Gets/Sets whether to use object creation expressions for generic types with new() constraint.
+ /// true: T t = new T();
+ /// false: T t = Activator.CreateInstance<T>()
+ ///
+ [Category("C# 2.0 / VS 2005")]
+ [Description("DecompilerSettings.UseObjectCreationOfGenericTypeParameter")]
+ public bool UseObjectCreationOfGenericTypeParameter {
+ get { return useObjectCreationOfGenericTypeParameter; }
+ set {
+ if (useObjectCreationOfGenericTypeParameter != value)
+ {
+ useObjectCreationOfGenericTypeParameter = value;
+ OnPropertyChanged();
+ }
+ }
+ }
+
bool alwaysCastTargetsOfExplicitInterfaceImplementationCalls = false;
///
diff --git a/ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs b/ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs
index f73f624f1..c6ce6443a 100644
--- a/ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs
+++ b/ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs
@@ -532,7 +532,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms
inst.Condition.AcceptVisitor(this);
if (new NullableLiftingTransform(context).Run(inst))
+ {
+ context.Step("NullableLiftingTransform", inst);
return;
+ }
if (TransformDynamicAddAssignOrRemoveAssign(inst))
return;
diff --git a/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs b/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs
index ea32c3972..908138ca9 100644
--- a/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs
+++ b/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs
@@ -76,6 +76,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms
instType = defaultVal.Type;
break;
case Call c when c.Method.FullNameIs("System.Activator", "CreateInstance") && c.Method.TypeArguments.Count == 1:
+ if (!context.Settings.UseObjectCreationOfGenericTypeParameter)
+ {
+ return;
+ }
instType = c.Method.TypeArguments[0];
blockKind = BlockKind.ObjectInitializer;
break;
diff --git a/ILSpy/Properties/Resources.Designer.cs b/ILSpy/Properties/Resources.Designer.cs
index d31af0b12..285319bdd 100644
--- a/ILSpy/Properties/Resources.Designer.cs
+++ b/ILSpy/Properties/Resources.Designer.cs
@@ -1514,6 +1514,15 @@ namespace ICSharpCode.ILSpy.Properties {
}
}
+ ///
+ /// Looks up a localized string similar to Use new T() instead of Activator.CreateInstance<T>.
+ ///
+ public static string DecompilerSettings_UseObjectCreationOfGenericTypeParameter {
+ get {
+ return ResourceManager.GetString("DecompilerSettings.UseObjectCreationOfGenericTypeParameter", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Use out variable declarations.
///
diff --git a/ILSpy/Properties/Resources.resx b/ILSpy/Properties/Resources.resx
index 840c92fb1..f53e0ca4f 100644
--- a/ILSpy/Properties/Resources.resx
+++ b/ILSpy/Properties/Resources.resx
@@ -525,6 +525,9 @@ Are you sure you want to continue?
Use non-trailing named arguments
+
+ Use new T() instead of Activator.CreateInstance<T>
+
Use out variable declarations
diff --git a/ILSpy/Properties/Resources.zh-Hans.resx b/ILSpy/Properties/Resources.zh-Hans.resx
index 3973a4805..471a79dad 100644
--- a/ILSpy/Properties/Resources.zh-Hans.resx
+++ b/ILSpy/Properties/Resources.zh-Hans.resx
@@ -492,6 +492,9 @@
使用非尾随命名参数
+
+
+
使用 out 变量声明