Browse Source

Use out variable declarations where possible.

pull/1087/head
Daniel Grunwald 7 years ago
parent
commit
19e840856f
  1. 1
      ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
  2. 2
      ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
  3. 36
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/AnonymousTypes.cs
  4. 24
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/AnonymousTypes.il
  5. 23
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/AnonymousTypes.opt.il
  6. 818
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/AnonymousTypes.opt.roslyn.il
  7. 857
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/AnonymousTypes.roslyn.il
  8. 10
      ICSharpCode.Decompiler/CSharp/Annotations.cs
  9. 2
      ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs
  10. 10
      ICSharpCode.Decompiler/CSharp/Syntax/Expressions/OutVarDeclarationExpression.cs
  11. 98
      ICSharpCode.Decompiler/CSharp/Transforms/DeclareVariables.cs
  12. 18
      ICSharpCode.Decompiler/DecompilerSettings.cs

1
ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

@ -78,7 +78,6 @@ @@ -78,7 +78,6 @@
<None Include="TestCases\ILPretty\Issue1047.cs" />
<Compile Include="TestCases\Correctness\NullPropagation.cs" />
<Compile Include="TestCases\ILPretty\Issue982.cs" />
<Compile Include="TestCases\Pretty\AsyncMain.cs" />
<Compile Include="TestCases\Pretty\CS72_PrivateProtected.cs" />
<Compile Include="TestCases\Pretty\CS6_StringInterpolation.cs" />
<Compile Include="TestCases\Pretty\ExpressionTrees.cs" />

2
ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

@ -123,7 +123,7 @@ namespace ICSharpCode.Decompiler.Tests @@ -123,7 +123,7 @@ namespace ICSharpCode.Decompiler.Tests
}
[Test]
public void AnonymousTypes([Values(CSharpCompilerOptions.None, CSharpCompilerOptions.Optimize)] CSharpCompilerOptions cscOptions)
public void AnonymousTypes([ValueSource("defaultOptions")] CSharpCompilerOptions cscOptions)
{
RunForLibrary(cscOptions: cscOptions);
}

36
ICSharpCode.Decompiler.Tests/TestCases/Pretty/AnonymousTypes.cs

@ -41,7 +41,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -41,7 +41,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
private void SimpleArray()
{
#if ROSLYN && OPT
var obj = new[] {
#else
var array = new[] {
#endif
new {
X = 5,
Y = 2,
@ -54,8 +58,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -54,8 +58,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
}
};
#if ROSLYN && OPT
Console.WriteLine(obj[0].X);
Console.WriteLine(obj[1].X);
#else
Console.WriteLine(array[0].X);
Console.WriteLine(array[1].X);
#endif
}
private void JaggedArray()
@ -72,6 +81,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -72,6 +81,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
Z = -6
}
};
#if ROSLYN && OPT
var obj = new[] {
array,
array
};
Console.WriteLine(array[0].X);
Console.WriteLine(array[1].X);
Console.WriteLine(obj.Length);
#else
var array2 = new[] {
array,
array
@ -80,6 +99,23 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -80,6 +99,23 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
Console.WriteLine(array[0].X);
Console.WriteLine(array[1].X);
Console.WriteLine(array2.Length);
#endif
}
#if CS70
private void AnonymousTypeOutVar()
{
AnonymousTypes.InlineVarDecl(out var anon, new {
X = 1,
Y = 2
});
Console.WriteLine(anon.X);
}
#endif
private static void InlineVarDecl<T>(out T v, T init)
{
v = init;
}
}
}

24
ICSharpCode.Decompiler.Tests/TestCases/Pretty/AnonymousTypes.il

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929
// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly d3qdmgj3
.assembly '1xvbqrhn'
{
.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
@ -20,15 +20,15 @@ @@ -20,15 +20,15 @@
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module d3qdmgj3.dll
// MVID: {580C0EC8-1048-4E5F-8BCB-8AF6994DA5B8}
.module '1xvbqrhn.dll'
// MVID: {FBEE2A5E-0EA6-4D81-AF17-0E675B5AAF7A}
.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: 0x017F0000
// Image base: 0x02CF0000
// =============== CLASS MEMBERS DECLARATION ===================
@ -184,6 +184,18 @@ @@ -184,6 +184,18 @@
IL_0057: ret
} // end of method AnonymousTypes::JaggedArray
.method private hidebysig static void InlineVarDecl<T>([out] !!T& v,
!!T 'init') cil managed
{
// Code size 9 (0x9)
.maxstack 8
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldarg.1
IL_0003: stobj !!T
IL_0008: ret
} // end of method AnonymousTypes::InlineVarDecl
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
@ -839,4 +851,4 @@ @@ -839,4 +851,4 @@
// =============================================================
// *********** DISASSEMBLY COMPLETE ***********************
// WARNING: Created Win32 resource file ../../../../ICSharpCode.Decompiler.Tests/TestCases/Pretty\AnonymousTypes.res
// WARNING: Created Win32 resource file C:\work\ILSpy\ICSharpCode.Decompiler.Tests\bin\Debug\net46\../../../TestCases/Pretty\AnonymousTypes.res

23
ICSharpCode.Decompiler.Tests/TestCases/Pretty/AnonymousTypes.opt.il

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
// Microsoft (R) .NET Framework IL Disassembler. Version 4.0.30319.17929
// Microsoft (R) .NET Framework IL Disassembler. Version 4.6.1055.0
// Copyright (c) Microsoft Corporation. All rights reserved.
@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 4:0:0:0
}
.assembly p4ukdvbx
.assembly ikebg3tc
{
.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
@ -20,15 +20,15 @@ @@ -20,15 +20,15 @@
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module p4ukdvbx.dll
// MVID: {C064CB4C-9883-4210-817E-890107A546DE}
.module ikebg3tc.dll
// MVID: {9F96FB3A-745D-4BC1-8552-8ECB86372E2A}
.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: 0x026B0000
// Image base: 0x03680000
// =============== CLASS MEMBERS DECLARATION ===================
@ -173,6 +173,17 @@ @@ -173,6 +173,17 @@
IL_0053: ret
} // end of method AnonymousTypes::JaggedArray
.method private hidebysig static void InlineVarDecl<T>([out] !!T& v,
!!T 'init') cil managed
{
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: stobj !!T
IL_0007: ret
} // end of method AnonymousTypes::InlineVarDecl
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
@ -735,4 +746,4 @@ @@ -735,4 +746,4 @@
// =============================================================
// *********** DISASSEMBLY COMPLETE ***********************
// WARNING: Created Win32 resource file ../../../../ICSharpCode.Decompiler.Tests/TestCases/Pretty\AnonymousTypes.opt.res
// WARNING: Created Win32 resource file C:\work\ILSpy\ICSharpCode.Decompiler.Tests\bin\Debug\net46\../../../TestCases/Pretty\AnonymousTypes.opt.res

818
ICSharpCode.Decompiler.Tests/TestCases/Pretty/AnonymousTypes.opt.roslyn.il

@ -0,0 +1,818 @@ @@ -0,0 +1,818 @@
// 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 AnonymousTypes
{
.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 AnonymousTypes.dll
// MVID: {1E938B8B-C865-47D8-BBD3-084FD638D111}
.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: 0x04DA0000
// =============== CLASS MEMBERS DECLARATION ===================
.class private auto ansi sealed beforefieldinit '<>f__AnonymousType0'
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// 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 '<>f__AnonymousType0'::.ctor
.method public hidebysig virtual instance bool
Equals(object 'value') cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 10 (0xa)
.maxstack 8
IL_0000: ldarg.1
IL_0001: isinst '<>f__AnonymousType0'
IL_0006: ldnull
IL_0007: cgt.un
IL_0009: ret
} // end of method '<>f__AnonymousType0'::Equals
.method public hidebysig virtual instance int32
GetHashCode() cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 2 (0x2)
.maxstack 8
IL_0000: ldc.i4.0
IL_0001: ret
} // end of method '<>f__AnonymousType0'::GetHashCode
.method public hidebysig virtual instance string
ToString() cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 6 (0x6)
.maxstack 8
IL_0000: ldstr "{ }"
IL_0005: ret
} // end of method '<>f__AnonymousType0'::ToString
} // end of class '<>f__AnonymousType0'
.class private auto ansi sealed beforefieldinit '<>f__AnonymousType1`1'<'<X>j__TPar'>
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private initonly !'<X>j__TPar' '<X>i__Field'
.custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.method public hidebysig specialname instance !'<X>j__TPar'
get_X() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld !0 class '<>f__AnonymousType1`1'<!'<X>j__TPar'>::'<X>i__Field'
IL_0006: ret
} // end of method '<>f__AnonymousType1`1'::get_X
.method public hidebysig specialname rtspecialname
instance void .ctor(!'<X>j__TPar' X) cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 14 (0xe)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ldarg.0
IL_0007: ldarg.1
IL_0008: stfld !0 class '<>f__AnonymousType1`1'<!'<X>j__TPar'>::'<X>i__Field'
IL_000d: ret
} // end of method '<>f__AnonymousType1`1'::.ctor
.method public hidebysig virtual instance bool
Equals(object 'value') cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 35 (0x23)
.maxstack 3
.locals init (class '<>f__AnonymousType1`1'<!'<X>j__TPar'> V_0)
IL_0000: ldarg.1
IL_0001: isinst class '<>f__AnonymousType1`1'<!'<X>j__TPar'>
IL_0006: stloc.0
IL_0007: ldloc.0
IL_0008: brfalse.s IL_0021
IL_000a: call class [mscorlib]System.Collections.Generic.EqualityComparer`1<!0> class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<X>j__TPar'>::get_Default()
IL_000f: ldarg.0
IL_0010: ldfld !0 class '<>f__AnonymousType1`1'<!'<X>j__TPar'>::'<X>i__Field'
IL_0015: ldloc.0
IL_0016: ldfld !0 class '<>f__AnonymousType1`1'<!'<X>j__TPar'>::'<X>i__Field'
IL_001b: callvirt instance bool class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<X>j__TPar'>::Equals(!0,
!0)
IL_0020: ret
IL_0021: ldc.i4.0
IL_0022: ret
} // end of method '<>f__AnonymousType1`1'::Equals
.method public hidebysig virtual instance int32
GetHashCode() cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 29 (0x1d)
.maxstack 8
IL_0000: ldc.i4 0xf83c6f13
IL_0005: ldc.i4 0xa5555529
IL_000a: mul
IL_000b: call class [mscorlib]System.Collections.Generic.EqualityComparer`1<!0> class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<X>j__TPar'>::get_Default()
IL_0010: ldarg.0
IL_0011: ldfld !0 class '<>f__AnonymousType1`1'<!'<X>j__TPar'>::'<X>i__Field'
IL_0016: callvirt instance int32 class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<X>j__TPar'>::GetHashCode(!0)
IL_001b: add
IL_001c: ret
} // end of method '<>f__AnonymousType1`1'::GetHashCode
.method public hidebysig virtual instance string
ToString() cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 77 (0x4d)
.maxstack 7
.locals init (!'<X>j__TPar' V_0,
!'<X>j__TPar' V_1)
IL_0000: ldnull
IL_0001: ldstr "{{ X = {0} }}"
IL_0006: ldc.i4.1
IL_0007: newarr [mscorlib]System.Object
IL_000c: dup
IL_000d: ldc.i4.0
IL_000e: ldarg.0
IL_000f: ldfld !0 class '<>f__AnonymousType1`1'<!'<X>j__TPar'>::'<X>i__Field'
IL_0014: stloc.0
IL_0015: ldloca.s V_0
IL_0017: ldloca.s V_1
IL_0019: initobj !'<X>j__TPar'
IL_001f: ldloc.1
IL_0020: box !'<X>j__TPar'
IL_0025: brtrue.s IL_003b
IL_0027: ldobj !'<X>j__TPar'
IL_002c: stloc.1
IL_002d: ldloca.s V_1
IL_002f: ldloc.1
IL_0030: box !'<X>j__TPar'
IL_0035: brtrue.s IL_003b
IL_0037: pop
IL_0038: ldnull
IL_0039: br.s IL_0046
IL_003b: constrained. !'<X>j__TPar'
IL_0041: callvirt instance string [mscorlib]System.Object::ToString()
IL_0046: stelem.ref
IL_0047: call string [mscorlib]System.String::Format(class [mscorlib]System.IFormatProvider,
string,
object[])
IL_004c: ret
} // end of method '<>f__AnonymousType1`1'::ToString
.property instance !'<X>j__TPar' X()
{
.get instance !'<X>j__TPar' '<>f__AnonymousType1`1'::get_X()
} // end of property '<>f__AnonymousType1`1'::X
} // end of class '<>f__AnonymousType1`1'
.class private auto ansi sealed beforefieldinit '<>f__AnonymousType2`2'<'<X>j__TPar','<Y>j__TPar'>
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private initonly !'<X>j__TPar' '<X>i__Field'
.custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.field private initonly !'<Y>j__TPar' '<Y>i__Field'
.custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.method public hidebysig specialname instance !'<X>j__TPar'
get_X() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld !0 class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'>::'<X>i__Field'
IL_0006: ret
} // end of method '<>f__AnonymousType2`2'::get_X
.method public hidebysig specialname instance !'<Y>j__TPar'
get_Y() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld !1 class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'>::'<Y>i__Field'
IL_0006: ret
} // end of method '<>f__AnonymousType2`2'::get_Y
.method public hidebysig specialname rtspecialname
instance void .ctor(!'<X>j__TPar' X,
!'<Y>j__TPar' Y) cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 21 (0x15)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ldarg.0
IL_0007: ldarg.1
IL_0008: stfld !0 class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'>::'<X>i__Field'
IL_000d: ldarg.0
IL_000e: ldarg.2
IL_000f: stfld !1 class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'>::'<Y>i__Field'
IL_0014: ret
} // end of method '<>f__AnonymousType2`2'::.ctor
.method public hidebysig virtual instance bool
Equals(object 'value') cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 59 (0x3b)
.maxstack 3
.locals init (class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'> V_0)
IL_0000: ldarg.1
IL_0001: isinst class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'>
IL_0006: stloc.0
IL_0007: ldloc.0
IL_0008: brfalse.s IL_0039
IL_000a: call class [mscorlib]System.Collections.Generic.EqualityComparer`1<!0> class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<X>j__TPar'>::get_Default()
IL_000f: ldarg.0
IL_0010: ldfld !0 class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'>::'<X>i__Field'
IL_0015: ldloc.0
IL_0016: ldfld !0 class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'>::'<X>i__Field'
IL_001b: callvirt instance bool class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<X>j__TPar'>::Equals(!0,
!0)
IL_0020: brfalse.s IL_0039
IL_0022: call class [mscorlib]System.Collections.Generic.EqualityComparer`1<!0> class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<Y>j__TPar'>::get_Default()
IL_0027: ldarg.0
IL_0028: ldfld !1 class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'>::'<Y>i__Field'
IL_002d: ldloc.0
IL_002e: ldfld !1 class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'>::'<Y>i__Field'
IL_0033: callvirt instance bool class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<Y>j__TPar'>::Equals(!0,
!0)
IL_0038: ret
IL_0039: ldc.i4.0
IL_003a: ret
} // end of method '<>f__AnonymousType2`2'::Equals
.method public hidebysig virtual instance int32
GetHashCode() cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 52 (0x34)
.maxstack 8
IL_0000: ldc.i4 0xe71b881e
IL_0005: ldc.i4 0xa5555529
IL_000a: mul
IL_000b: call class [mscorlib]System.Collections.Generic.EqualityComparer`1<!0> class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<X>j__TPar'>::get_Default()
IL_0010: ldarg.0
IL_0011: ldfld !0 class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'>::'<X>i__Field'
IL_0016: callvirt instance int32 class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<X>j__TPar'>::GetHashCode(!0)
IL_001b: add
IL_001c: ldc.i4 0xa5555529
IL_0021: mul
IL_0022: call class [mscorlib]System.Collections.Generic.EqualityComparer`1<!0> class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<Y>j__TPar'>::get_Default()
IL_0027: ldarg.0
IL_0028: ldfld !1 class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'>::'<Y>i__Field'
IL_002d: callvirt instance int32 class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<Y>j__TPar'>::GetHashCode(!0)
IL_0032: add
IL_0033: ret
} // end of method '<>f__AnonymousType2`2'::GetHashCode
.method public hidebysig virtual instance string
ToString() cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 136 (0x88)
.maxstack 7
.locals init (!'<X>j__TPar' V_0,
!'<X>j__TPar' V_1,
!'<Y>j__TPar' V_2,
!'<Y>j__TPar' V_3)
IL_0000: ldnull
IL_0001: ldstr "{{ X = {0}, Y = {1} }}"
IL_0006: ldc.i4.2
IL_0007: newarr [mscorlib]System.Object
IL_000c: dup
IL_000d: ldc.i4.0
IL_000e: ldarg.0
IL_000f: ldfld !0 class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'>::'<X>i__Field'
IL_0014: stloc.0
IL_0015: ldloca.s V_0
IL_0017: ldloca.s V_1
IL_0019: initobj !'<X>j__TPar'
IL_001f: ldloc.1
IL_0020: box !'<X>j__TPar'
IL_0025: brtrue.s IL_003b
IL_0027: ldobj !'<X>j__TPar'
IL_002c: stloc.1
IL_002d: ldloca.s V_1
IL_002f: ldloc.1
IL_0030: box !'<X>j__TPar'
IL_0035: brtrue.s IL_003b
IL_0037: pop
IL_0038: ldnull
IL_0039: br.s IL_0046
IL_003b: constrained. !'<X>j__TPar'
IL_0041: callvirt instance string [mscorlib]System.Object::ToString()
IL_0046: stelem.ref
IL_0047: dup
IL_0048: ldc.i4.1
IL_0049: ldarg.0
IL_004a: ldfld !1 class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'>::'<Y>i__Field'
IL_004f: stloc.2
IL_0050: ldloca.s V_2
IL_0052: ldloca.s V_3
IL_0054: initobj !'<Y>j__TPar'
IL_005a: ldloc.3
IL_005b: box !'<Y>j__TPar'
IL_0060: brtrue.s IL_0076
IL_0062: ldobj !'<Y>j__TPar'
IL_0067: stloc.3
IL_0068: ldloca.s V_3
IL_006a: ldloc.3
IL_006b: box !'<Y>j__TPar'
IL_0070: brtrue.s IL_0076
IL_0072: pop
IL_0073: ldnull
IL_0074: br.s IL_0081
IL_0076: constrained. !'<Y>j__TPar'
IL_007c: callvirt instance string [mscorlib]System.Object::ToString()
IL_0081: stelem.ref
IL_0082: call string [mscorlib]System.String::Format(class [mscorlib]System.IFormatProvider,
string,
object[])
IL_0087: ret
} // end of method '<>f__AnonymousType2`2'::ToString
.property instance !'<X>j__TPar' X()
{
.get instance !'<X>j__TPar' '<>f__AnonymousType2`2'::get_X()
} // end of property '<>f__AnonymousType2`2'::X
.property instance !'<Y>j__TPar' Y()
{
.get instance !'<Y>j__TPar' '<>f__AnonymousType2`2'::get_Y()
} // end of property '<>f__AnonymousType2`2'::Y
} // end of class '<>f__AnonymousType2`2'
.class private auto ansi sealed beforefieldinit '<>f__AnonymousType3`3'<'<X>j__TPar','<Y>j__TPar','<Z>j__TPar'>
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.field private initonly !'<X>j__TPar' '<X>i__Field'
.custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.field private initonly !'<Y>j__TPar' '<Y>i__Field'
.custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.field private initonly !'<Z>j__TPar' '<Z>i__Field'
.custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.method public hidebysig specialname instance !'<X>j__TPar'
get_X() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld !0 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<X>i__Field'
IL_0006: ret
} // end of method '<>f__AnonymousType3`3'::get_X
.method public hidebysig specialname instance !'<Y>j__TPar'
get_Y() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld !1 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<Y>i__Field'
IL_0006: ret
} // end of method '<>f__AnonymousType3`3'::get_Y
.method public hidebysig specialname instance !'<Z>j__TPar'
get_Z() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld !2 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<Z>i__Field'
IL_0006: ret
} // end of method '<>f__AnonymousType3`3'::get_Z
.method public hidebysig specialname rtspecialname
instance void .ctor(!'<X>j__TPar' X,
!'<Y>j__TPar' Y,
!'<Z>j__TPar' Z) cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 28 (0x1c)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ldarg.0
IL_0007: ldarg.1
IL_0008: stfld !0 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<X>i__Field'
IL_000d: ldarg.0
IL_000e: ldarg.2
IL_000f: stfld !1 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<Y>i__Field'
IL_0014: ldarg.0
IL_0015: ldarg.3
IL_0016: stfld !2 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<Z>i__Field'
IL_001b: ret
} // end of method '<>f__AnonymousType3`3'::.ctor
.method public hidebysig virtual instance bool
Equals(object 'value') cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 83 (0x53)
.maxstack 3
.locals init (class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'> V_0)
IL_0000: ldarg.1
IL_0001: isinst class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>
IL_0006: stloc.0
IL_0007: ldloc.0
IL_0008: brfalse.s IL_0051
IL_000a: call class [mscorlib]System.Collections.Generic.EqualityComparer`1<!0> class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<X>j__TPar'>::get_Default()
IL_000f: ldarg.0
IL_0010: ldfld !0 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<X>i__Field'
IL_0015: ldloc.0
IL_0016: ldfld !0 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<X>i__Field'
IL_001b: callvirt instance bool class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<X>j__TPar'>::Equals(!0,
!0)
IL_0020: brfalse.s IL_0051
IL_0022: call class [mscorlib]System.Collections.Generic.EqualityComparer`1<!0> class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<Y>j__TPar'>::get_Default()
IL_0027: ldarg.0
IL_0028: ldfld !1 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<Y>i__Field'
IL_002d: ldloc.0
IL_002e: ldfld !1 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<Y>i__Field'
IL_0033: callvirt instance bool class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<Y>j__TPar'>::Equals(!0,
!0)
IL_0038: brfalse.s IL_0051
IL_003a: call class [mscorlib]System.Collections.Generic.EqualityComparer`1<!0> class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<Z>j__TPar'>::get_Default()
IL_003f: ldarg.0
IL_0040: ldfld !2 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<Z>i__Field'
IL_0045: ldloc.0
IL_0046: ldfld !2 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<Z>i__Field'
IL_004b: callvirt instance bool class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<Z>j__TPar'>::Equals(!0,
!0)
IL_0050: ret
IL_0051: ldc.i4.0
IL_0052: ret
} // end of method '<>f__AnonymousType3`3'::Equals
.method public hidebysig virtual instance int32
GetHashCode() cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 75 (0x4b)
.maxstack 3
IL_0000: ldc.i4 0xb04731e1
IL_0005: ldc.i4 0xa5555529
IL_000a: mul
IL_000b: call class [mscorlib]System.Collections.Generic.EqualityComparer`1<!0> class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<X>j__TPar'>::get_Default()
IL_0010: ldarg.0
IL_0011: ldfld !0 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<X>i__Field'
IL_0016: callvirt instance int32 class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<X>j__TPar'>::GetHashCode(!0)
IL_001b: add
IL_001c: ldc.i4 0xa5555529
IL_0021: mul
IL_0022: call class [mscorlib]System.Collections.Generic.EqualityComparer`1<!0> class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<Y>j__TPar'>::get_Default()
IL_0027: ldarg.0
IL_0028: ldfld !1 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<Y>i__Field'
IL_002d: callvirt instance int32 class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<Y>j__TPar'>::GetHashCode(!0)
IL_0032: add
IL_0033: ldc.i4 0xa5555529
IL_0038: mul
IL_0039: call class [mscorlib]System.Collections.Generic.EqualityComparer`1<!0> class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<Z>j__TPar'>::get_Default()
IL_003e: ldarg.0
IL_003f: ldfld !2 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<Z>i__Field'
IL_0044: callvirt instance int32 class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<Z>j__TPar'>::GetHashCode(!0)
IL_0049: add
IL_004a: ret
} // end of method '<>f__AnonymousType3`3'::GetHashCode
.method public hidebysig virtual instance string
ToString() cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 199 (0xc7)
.maxstack 7
.locals init (!'<X>j__TPar' V_0,
!'<X>j__TPar' V_1,
!'<Y>j__TPar' V_2,
!'<Y>j__TPar' V_3,
!'<Z>j__TPar' V_4,
!'<Z>j__TPar' V_5)
IL_0000: ldnull
IL_0001: ldstr "{{ X = {0}, Y = {1}, Z = {2} }}"
IL_0006: ldc.i4.3
IL_0007: newarr [mscorlib]System.Object
IL_000c: dup
IL_000d: ldc.i4.0
IL_000e: ldarg.0
IL_000f: ldfld !0 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<X>i__Field'
IL_0014: stloc.0
IL_0015: ldloca.s V_0
IL_0017: ldloca.s V_1
IL_0019: initobj !'<X>j__TPar'
IL_001f: ldloc.1
IL_0020: box !'<X>j__TPar'
IL_0025: brtrue.s IL_003b
IL_0027: ldobj !'<X>j__TPar'
IL_002c: stloc.1
IL_002d: ldloca.s V_1
IL_002f: ldloc.1
IL_0030: box !'<X>j__TPar'
IL_0035: brtrue.s IL_003b
IL_0037: pop
IL_0038: ldnull
IL_0039: br.s IL_0046
IL_003b: constrained. !'<X>j__TPar'
IL_0041: callvirt instance string [mscorlib]System.Object::ToString()
IL_0046: stelem.ref
IL_0047: dup
IL_0048: ldc.i4.1
IL_0049: ldarg.0
IL_004a: ldfld !1 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<Y>i__Field'
IL_004f: stloc.2
IL_0050: ldloca.s V_2
IL_0052: ldloca.s V_3
IL_0054: initobj !'<Y>j__TPar'
IL_005a: ldloc.3
IL_005b: box !'<Y>j__TPar'
IL_0060: brtrue.s IL_0076
IL_0062: ldobj !'<Y>j__TPar'
IL_0067: stloc.3
IL_0068: ldloca.s V_3
IL_006a: ldloc.3
IL_006b: box !'<Y>j__TPar'
IL_0070: brtrue.s IL_0076
IL_0072: pop
IL_0073: ldnull
IL_0074: br.s IL_0081
IL_0076: constrained. !'<Y>j__TPar'
IL_007c: callvirt instance string [mscorlib]System.Object::ToString()
IL_0081: stelem.ref
IL_0082: dup
IL_0083: ldc.i4.2
IL_0084: ldarg.0
IL_0085: ldfld !2 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<Z>i__Field'
IL_008a: stloc.s V_4
IL_008c: ldloca.s V_4
IL_008e: ldloca.s V_5
IL_0090: initobj !'<Z>j__TPar'
IL_0096: ldloc.s V_5
IL_0098: box !'<Z>j__TPar'
IL_009d: brtrue.s IL_00b5
IL_009f: ldobj !'<Z>j__TPar'
IL_00a4: stloc.s V_5
IL_00a6: ldloca.s V_5
IL_00a8: ldloc.s V_5
IL_00aa: box !'<Z>j__TPar'
IL_00af: brtrue.s IL_00b5
IL_00b1: pop
IL_00b2: ldnull
IL_00b3: br.s IL_00c0
IL_00b5: constrained. !'<Z>j__TPar'
IL_00bb: callvirt instance string [mscorlib]System.Object::ToString()
IL_00c0: stelem.ref
IL_00c1: call string [mscorlib]System.String::Format(class [mscorlib]System.IFormatProvider,
string,
object[])
IL_00c6: ret
} // end of method '<>f__AnonymousType3`3'::ToString
.property instance !'<X>j__TPar' X()
{
.get instance !'<X>j__TPar' '<>f__AnonymousType3`3'::get_X()
} // end of property '<>f__AnonymousType3`3'::X
.property instance !'<Y>j__TPar' Y()
{
.get instance !'<Y>j__TPar' '<>f__AnonymousType3`3'::get_Y()
} // end of property '<>f__AnonymousType3`3'::Y
.property instance !'<Z>j__TPar' Z()
{
.get instance !'<Z>j__TPar' '<>f__AnonymousType3`3'::get_Z()
} // end of property '<>f__AnonymousType3`3'::Z
} // end of class '<>f__AnonymousType3`3'
.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.AnonymousTypes
extends [mscorlib]System.Object
{
.method private hidebysig instance void
SimpleTypes() cil managed
{
// Code size 56 (0x38)
.maxstack 3
.locals init (class '<>f__AnonymousType1`1'<int32> V_0,
class '<>f__AnonymousType2`2'<int32,int32> V_1)
IL_0000: newobj instance void '<>f__AnonymousType0'::.ctor()
IL_0005: ldc.i4.5
IL_0006: newobj instance void class '<>f__AnonymousType1`1'<int32>::.ctor(!0)
IL_000b: stloc.0
IL_000c: ldc.i4.5
IL_000d: ldc.i4.s 10
IL_000f: newobj instance void class '<>f__AnonymousType2`2'<int32,int32>::.ctor(!0,
!1)
IL_0014: stloc.1
IL_0015: call void [mscorlib]System.Console::WriteLine(object)
IL_001a: ldloc.0
IL_001b: callvirt instance !0 class '<>f__AnonymousType1`1'<int32>::get_X()
IL_0020: call void [mscorlib]System.Console::WriteLine(int32)
IL_0025: ldloc.1
IL_0026: callvirt instance !1 class '<>f__AnonymousType2`2'<int32,int32>::get_Y()
IL_002b: ldloc.1
IL_002c: callvirt instance !0 class '<>f__AnonymousType2`2'<int32,int32>::get_X()
IL_0031: add
IL_0032: call void [mscorlib]System.Console::WriteLine(int32)
IL_0037: ret
} // end of method AnonymousTypes::SimpleTypes
.method private hidebysig instance void
SimpleArray() cil managed
{
// Code size 55 (0x37)
.maxstack 8
IL_0000: ldc.i4.2
IL_0001: newarr class '<>f__AnonymousType3`3'<int32,int32,int32>
IL_0006: dup
IL_0007: ldc.i4.0
IL_0008: ldc.i4.5
IL_0009: ldc.i4.2
IL_000a: ldc.i4.m1
IL_000b: newobj instance void class '<>f__AnonymousType3`3'<int32,int32,int32>::.ctor(!0,
!1,
!2)
IL_0010: stelem.ref
IL_0011: dup
IL_0012: ldc.i4.1
IL_0013: ldc.i4.3
IL_0014: ldc.i4.6
IL_0015: ldc.i4.s -6
IL_0017: newobj instance void class '<>f__AnonymousType3`3'<int32,int32,int32>::.ctor(!0,
!1,
!2)
IL_001c: stelem.ref
IL_001d: dup
IL_001e: ldc.i4.0
IL_001f: ldelem.ref
IL_0020: callvirt instance !0 class '<>f__AnonymousType3`3'<int32,int32,int32>::get_X()
IL_0025: call void [mscorlib]System.Console::WriteLine(int32)
IL_002a: ldc.i4.1
IL_002b: ldelem.ref
IL_002c: callvirt instance !0 class '<>f__AnonymousType3`3'<int32,int32,int32>::get_X()
IL_0031: call void [mscorlib]System.Console::WriteLine(int32)
IL_0036: ret
} // end of method AnonymousTypes::SimpleArray
.method private hidebysig instance void
JaggedArray() cil managed
{
// Code size 78 (0x4e)
.maxstack 6
.locals init (class '<>f__AnonymousType3`3'<int32,int32,int32>[] V_0)
IL_0000: ldc.i4.2
IL_0001: newarr class '<>f__AnonymousType3`3'<int32,int32,int32>
IL_0006: dup
IL_0007: ldc.i4.0
IL_0008: ldc.i4.5
IL_0009: ldc.i4.2
IL_000a: ldc.i4.m1
IL_000b: newobj instance void class '<>f__AnonymousType3`3'<int32,int32,int32>::.ctor(!0,
!1,
!2)
IL_0010: stelem.ref
IL_0011: dup
IL_0012: ldc.i4.1
IL_0013: ldc.i4.3
IL_0014: ldc.i4.6
IL_0015: ldc.i4.s -6
IL_0017: newobj instance void class '<>f__AnonymousType3`3'<int32,int32,int32>::.ctor(!0,
!1,
!2)
IL_001c: stelem.ref
IL_001d: stloc.0
IL_001e: ldc.i4.2
IL_001f: newarr class '<>f__AnonymousType3`3'<int32,int32,int32>[]
IL_0024: dup
IL_0025: ldc.i4.0
IL_0026: ldloc.0
IL_0027: stelem.ref
IL_0028: dup
IL_0029: ldc.i4.1
IL_002a: ldloc.0
IL_002b: stelem.ref
IL_002c: ldloc.0
IL_002d: ldc.i4.0
IL_002e: ldelem.ref
IL_002f: callvirt instance !0 class '<>f__AnonymousType3`3'<int32,int32,int32>::get_X()
IL_0034: call void [mscorlib]System.Console::WriteLine(int32)
IL_0039: ldloc.0
IL_003a: ldc.i4.1
IL_003b: ldelem.ref
IL_003c: callvirt instance !0 class '<>f__AnonymousType3`3'<int32,int32,int32>::get_X()
IL_0041: call void [mscorlib]System.Console::WriteLine(int32)
IL_0046: ldlen
IL_0047: conv.i4
IL_0048: call void [mscorlib]System.Console::WriteLine(int32)
IL_004d: ret
} // end of method AnonymousTypes::JaggedArray
.method private hidebysig instance void
AnonymousTypeOutVar() cil managed
{
// Code size 26 (0x1a)
.maxstack 3
.locals init (class '<>f__AnonymousType2`2'<int32,int32> V_0)
IL_0000: ldloca.s V_0
IL_0002: ldc.i4.1
IL_0003: ldc.i4.2
IL_0004: newobj instance void class '<>f__AnonymousType2`2'<int32,int32>::.ctor(!0,
!1)
IL_0009: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.AnonymousTypes::InlineVarDecl<class '<>f__AnonymousType2`2'<int32,int32>>(!!0&,
!!0)
IL_000e: ldloc.0
IL_000f: callvirt instance !0 class '<>f__AnonymousType2`2'<int32,int32>::get_X()
IL_0014: call void [mscorlib]System.Console::WriteLine(int32)
IL_0019: ret
} // end of method AnonymousTypes::AnonymousTypeOutVar
.method private hidebysig static void InlineVarDecl<T>([out] !!T& v,
!!T 'init') cil managed
{
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: stobj !!T
IL_0007: ret
} // end of method AnonymousTypes::InlineVarDecl
.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 AnonymousTypes::.ctor
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.AnonymousTypes
// =============================================================
// *********** DISASSEMBLY COMPLETE ***********************

857
ICSharpCode.Decompiler.Tests/TestCases/Pretty/AnonymousTypes.roslyn.il

@ -0,0 +1,857 @@ @@ -0,0 +1,857 @@
// 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 AnonymousTypes
{
.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 AnonymousTypes.dll
// MVID: {2A63FF34-C81B-4BF5-936B-388A7D9A8D41}
.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: 0x04B80000
// =============== CLASS MEMBERS DECLARATION ===================
.class private auto ansi sealed beforefieldinit '<>f__AnonymousType0'
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [mscorlib]System.Diagnostics.DebuggerDisplayAttribute::.ctor(string) = ( 01 00 04 5C 7B 20 7D 01 00 54 0E 04 54 79 70 65 // ...\{ }..T..Type
10 3C 41 6E 6F 6E 79 6D 6F 75 73 20 54 79 70 65 // .<Anonymous Type
3E ) // >
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// 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 '<>f__AnonymousType0'::.ctor
.method public hidebysig virtual instance bool
Equals(object 'value') cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 10 (0xa)
.maxstack 8
IL_0000: ldarg.1
IL_0001: isinst '<>f__AnonymousType0'
IL_0006: ldnull
IL_0007: cgt.un
IL_0009: ret
} // end of method '<>f__AnonymousType0'::Equals
.method public hidebysig virtual instance int32
GetHashCode() cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 2 (0x2)
.maxstack 8
IL_0000: ldc.i4.0
IL_0001: ret
} // end of method '<>f__AnonymousType0'::GetHashCode
.method public hidebysig virtual instance string
ToString() cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 6 (0x6)
.maxstack 8
IL_0000: ldstr "{ }"
IL_0005: ret
} // end of method '<>f__AnonymousType0'::ToString
} // end of class '<>f__AnonymousType0'
.class private auto ansi sealed beforefieldinit '<>f__AnonymousType1`1'<'<X>j__TPar'>
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [mscorlib]System.Diagnostics.DebuggerDisplayAttribute::.ctor(string) = ( 01 00 0C 5C 7B 20 58 20 3D 20 7B 58 7D 20 7D 01 // ...\{ X = {X} }.
00 54 0E 04 54 79 70 65 10 3C 41 6E 6F 6E 79 6D // .T..Type.<Anonym
6F 75 73 20 54 79 70 65 3E ) // ous Type>
.field private initonly !'<X>j__TPar' '<X>i__Field'
.custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.method public hidebysig specialname instance !'<X>j__TPar'
get_X() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld !0 class '<>f__AnonymousType1`1'<!'<X>j__TPar'>::'<X>i__Field'
IL_0006: ret
} // end of method '<>f__AnonymousType1`1'::get_X
.method public hidebysig specialname rtspecialname
instance void .ctor(!'<X>j__TPar' X) cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 14 (0xe)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ldarg.0
IL_0007: ldarg.1
IL_0008: stfld !0 class '<>f__AnonymousType1`1'<!'<X>j__TPar'>::'<X>i__Field'
IL_000d: ret
} // end of method '<>f__AnonymousType1`1'::.ctor
.method public hidebysig virtual instance bool
Equals(object 'value') cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 36 (0x24)
.maxstack 3
.locals init (class '<>f__AnonymousType1`1'<!'<X>j__TPar'> V_0)
IL_0000: ldarg.1
IL_0001: isinst class '<>f__AnonymousType1`1'<!'<X>j__TPar'>
IL_0006: stloc.0
IL_0007: ldloc.0
IL_0008: brfalse.s IL_0022
IL_000a: call class [mscorlib]System.Collections.Generic.EqualityComparer`1<!0> class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<X>j__TPar'>::get_Default()
IL_000f: ldarg.0
IL_0010: ldfld !0 class '<>f__AnonymousType1`1'<!'<X>j__TPar'>::'<X>i__Field'
IL_0015: ldloc.0
IL_0016: ldfld !0 class '<>f__AnonymousType1`1'<!'<X>j__TPar'>::'<X>i__Field'
IL_001b: callvirt instance bool class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<X>j__TPar'>::Equals(!0,
!0)
IL_0020: br.s IL_0023
IL_0022: ldc.i4.0
IL_0023: ret
} // end of method '<>f__AnonymousType1`1'::Equals
.method public hidebysig virtual instance int32
GetHashCode() cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 29 (0x1d)
.maxstack 8
IL_0000: ldc.i4 0xf83c6f13
IL_0005: ldc.i4 0xa5555529
IL_000a: mul
IL_000b: call class [mscorlib]System.Collections.Generic.EqualityComparer`1<!0> class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<X>j__TPar'>::get_Default()
IL_0010: ldarg.0
IL_0011: ldfld !0 class '<>f__AnonymousType1`1'<!'<X>j__TPar'>::'<X>i__Field'
IL_0016: callvirt instance int32 class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<X>j__TPar'>::GetHashCode(!0)
IL_001b: add
IL_001c: ret
} // end of method '<>f__AnonymousType1`1'::GetHashCode
.method public hidebysig virtual instance string
ToString() cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 77 (0x4d)
.maxstack 7
.locals init (!'<X>j__TPar' V_0,
!'<X>j__TPar' V_1)
IL_0000: ldnull
IL_0001: ldstr "{{ X = {0} }}"
IL_0006: ldc.i4.1
IL_0007: newarr [mscorlib]System.Object
IL_000c: dup
IL_000d: ldc.i4.0
IL_000e: ldarg.0
IL_000f: ldfld !0 class '<>f__AnonymousType1`1'<!'<X>j__TPar'>::'<X>i__Field'
IL_0014: stloc.0
IL_0015: ldloca.s V_0
IL_0017: ldloca.s V_1
IL_0019: initobj !'<X>j__TPar'
IL_001f: ldloc.1
IL_0020: box !'<X>j__TPar'
IL_0025: brtrue.s IL_003b
IL_0027: ldobj !'<X>j__TPar'
IL_002c: stloc.1
IL_002d: ldloca.s V_1
IL_002f: ldloc.1
IL_0030: box !'<X>j__TPar'
IL_0035: brtrue.s IL_003b
IL_0037: pop
IL_0038: ldnull
IL_0039: br.s IL_0046
IL_003b: constrained. !'<X>j__TPar'
IL_0041: callvirt instance string [mscorlib]System.Object::ToString()
IL_0046: stelem.ref
IL_0047: call string [mscorlib]System.String::Format(class [mscorlib]System.IFormatProvider,
string,
object[])
IL_004c: ret
} // end of method '<>f__AnonymousType1`1'::ToString
.property instance !'<X>j__TPar' X()
{
.get instance !'<X>j__TPar' '<>f__AnonymousType1`1'::get_X()
} // end of property '<>f__AnonymousType1`1'::X
} // end of class '<>f__AnonymousType1`1'
.class private auto ansi sealed beforefieldinit '<>f__AnonymousType2`2'<'<X>j__TPar','<Y>j__TPar'>
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [mscorlib]System.Diagnostics.DebuggerDisplayAttribute::.ctor(string) = ( 01 00 15 5C 7B 20 58 20 3D 20 7B 58 7D 2C 20 59 // ...\{ X = {X}, Y
20 3D 20 7B 59 7D 20 7D 01 00 54 0E 04 54 79 70 // = {Y} }..T..Typ
65 10 3C 41 6E 6F 6E 79 6D 6F 75 73 20 54 79 70 // e.<Anonymous Typ
65 3E ) // e>
.field private initonly !'<X>j__TPar' '<X>i__Field'
.custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.field private initonly !'<Y>j__TPar' '<Y>i__Field'
.custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.method public hidebysig specialname instance !'<X>j__TPar'
get_X() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld !0 class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'>::'<X>i__Field'
IL_0006: ret
} // end of method '<>f__AnonymousType2`2'::get_X
.method public hidebysig specialname instance !'<Y>j__TPar'
get_Y() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld !1 class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'>::'<Y>i__Field'
IL_0006: ret
} // end of method '<>f__AnonymousType2`2'::get_Y
.method public hidebysig specialname rtspecialname
instance void .ctor(!'<X>j__TPar' X,
!'<Y>j__TPar' Y) cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 21 (0x15)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ldarg.0
IL_0007: ldarg.1
IL_0008: stfld !0 class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'>::'<X>i__Field'
IL_000d: ldarg.0
IL_000e: ldarg.2
IL_000f: stfld !1 class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'>::'<Y>i__Field'
IL_0014: ret
} // end of method '<>f__AnonymousType2`2'::.ctor
.method public hidebysig virtual instance bool
Equals(object 'value') cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 60 (0x3c)
.maxstack 3
.locals init (class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'> V_0)
IL_0000: ldarg.1
IL_0001: isinst class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'>
IL_0006: stloc.0
IL_0007: ldloc.0
IL_0008: brfalse.s IL_003a
IL_000a: call class [mscorlib]System.Collections.Generic.EqualityComparer`1<!0> class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<X>j__TPar'>::get_Default()
IL_000f: ldarg.0
IL_0010: ldfld !0 class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'>::'<X>i__Field'
IL_0015: ldloc.0
IL_0016: ldfld !0 class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'>::'<X>i__Field'
IL_001b: callvirt instance bool class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<X>j__TPar'>::Equals(!0,
!0)
IL_0020: brfalse.s IL_003a
IL_0022: call class [mscorlib]System.Collections.Generic.EqualityComparer`1<!0> class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<Y>j__TPar'>::get_Default()
IL_0027: ldarg.0
IL_0028: ldfld !1 class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'>::'<Y>i__Field'
IL_002d: ldloc.0
IL_002e: ldfld !1 class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'>::'<Y>i__Field'
IL_0033: callvirt instance bool class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<Y>j__TPar'>::Equals(!0,
!0)
IL_0038: br.s IL_003b
IL_003a: ldc.i4.0
IL_003b: ret
} // end of method '<>f__AnonymousType2`2'::Equals
.method public hidebysig virtual instance int32
GetHashCode() cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 52 (0x34)
.maxstack 8
IL_0000: ldc.i4 0xe71b881e
IL_0005: ldc.i4 0xa5555529
IL_000a: mul
IL_000b: call class [mscorlib]System.Collections.Generic.EqualityComparer`1<!0> class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<X>j__TPar'>::get_Default()
IL_0010: ldarg.0
IL_0011: ldfld !0 class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'>::'<X>i__Field'
IL_0016: callvirt instance int32 class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<X>j__TPar'>::GetHashCode(!0)
IL_001b: add
IL_001c: ldc.i4 0xa5555529
IL_0021: mul
IL_0022: call class [mscorlib]System.Collections.Generic.EqualityComparer`1<!0> class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<Y>j__TPar'>::get_Default()
IL_0027: ldarg.0
IL_0028: ldfld !1 class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'>::'<Y>i__Field'
IL_002d: callvirt instance int32 class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<Y>j__TPar'>::GetHashCode(!0)
IL_0032: add
IL_0033: ret
} // end of method '<>f__AnonymousType2`2'::GetHashCode
.method public hidebysig virtual instance string
ToString() cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 136 (0x88)
.maxstack 7
.locals init (!'<X>j__TPar' V_0,
!'<X>j__TPar' V_1,
!'<Y>j__TPar' V_2,
!'<Y>j__TPar' V_3)
IL_0000: ldnull
IL_0001: ldstr "{{ X = {0}, Y = {1} }}"
IL_0006: ldc.i4.2
IL_0007: newarr [mscorlib]System.Object
IL_000c: dup
IL_000d: ldc.i4.0
IL_000e: ldarg.0
IL_000f: ldfld !0 class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'>::'<X>i__Field'
IL_0014: stloc.0
IL_0015: ldloca.s V_0
IL_0017: ldloca.s V_1
IL_0019: initobj !'<X>j__TPar'
IL_001f: ldloc.1
IL_0020: box !'<X>j__TPar'
IL_0025: brtrue.s IL_003b
IL_0027: ldobj !'<X>j__TPar'
IL_002c: stloc.1
IL_002d: ldloca.s V_1
IL_002f: ldloc.1
IL_0030: box !'<X>j__TPar'
IL_0035: brtrue.s IL_003b
IL_0037: pop
IL_0038: ldnull
IL_0039: br.s IL_0046
IL_003b: constrained. !'<X>j__TPar'
IL_0041: callvirt instance string [mscorlib]System.Object::ToString()
IL_0046: stelem.ref
IL_0047: dup
IL_0048: ldc.i4.1
IL_0049: ldarg.0
IL_004a: ldfld !1 class '<>f__AnonymousType2`2'<!'<X>j__TPar',!'<Y>j__TPar'>::'<Y>i__Field'
IL_004f: stloc.2
IL_0050: ldloca.s V_2
IL_0052: ldloca.s V_3
IL_0054: initobj !'<Y>j__TPar'
IL_005a: ldloc.3
IL_005b: box !'<Y>j__TPar'
IL_0060: brtrue.s IL_0076
IL_0062: ldobj !'<Y>j__TPar'
IL_0067: stloc.3
IL_0068: ldloca.s V_3
IL_006a: ldloc.3
IL_006b: box !'<Y>j__TPar'
IL_0070: brtrue.s IL_0076
IL_0072: pop
IL_0073: ldnull
IL_0074: br.s IL_0081
IL_0076: constrained. !'<Y>j__TPar'
IL_007c: callvirt instance string [mscorlib]System.Object::ToString()
IL_0081: stelem.ref
IL_0082: call string [mscorlib]System.String::Format(class [mscorlib]System.IFormatProvider,
string,
object[])
IL_0087: ret
} // end of method '<>f__AnonymousType2`2'::ToString
.property instance !'<X>j__TPar' X()
{
.get instance !'<X>j__TPar' '<>f__AnonymousType2`2'::get_X()
} // end of property '<>f__AnonymousType2`2'::X
.property instance !'<Y>j__TPar' Y()
{
.get instance !'<Y>j__TPar' '<>f__AnonymousType2`2'::get_Y()
} // end of property '<>f__AnonymousType2`2'::Y
} // end of class '<>f__AnonymousType2`2'
.class private auto ansi sealed beforefieldinit '<>f__AnonymousType3`3'<'<X>j__TPar','<Y>j__TPar','<Z>j__TPar'>
extends [mscorlib]System.Object
{
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [mscorlib]System.Diagnostics.DebuggerDisplayAttribute::.ctor(string) = ( 01 00 1E 5C 7B 20 58 20 3D 20 7B 58 7D 2C 20 59 // ...\{ X = {X}, Y
20 3D 20 7B 59 7D 2C 20 5A 20 3D 20 7B 5A 7D 20 // = {Y}, Z = {Z}
7D 01 00 54 0E 04 54 79 70 65 10 3C 41 6E 6F 6E // }..T..Type.<Anon
79 6D 6F 75 73 20 54 79 70 65 3E ) // ymous Type>
.field private initonly !'<X>j__TPar' '<X>i__Field'
.custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.field private initonly !'<Y>j__TPar' '<Y>i__Field'
.custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.field private initonly !'<Z>j__TPar' '<Z>i__Field'
.custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.method public hidebysig specialname instance !'<X>j__TPar'
get_X() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld !0 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<X>i__Field'
IL_0006: ret
} // end of method '<>f__AnonymousType3`3'::get_X
.method public hidebysig specialname instance !'<Y>j__TPar'
get_Y() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld !1 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<Y>i__Field'
IL_0006: ret
} // end of method '<>f__AnonymousType3`3'::get_Y
.method public hidebysig specialname instance !'<Z>j__TPar'
get_Z() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld !2 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<Z>i__Field'
IL_0006: ret
} // end of method '<>f__AnonymousType3`3'::get_Z
.method public hidebysig specialname rtspecialname
instance void .ctor(!'<X>j__TPar' X,
!'<Y>j__TPar' Y,
!'<Z>j__TPar' Z) cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 28 (0x1c)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ldarg.0
IL_0007: ldarg.1
IL_0008: stfld !0 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<X>i__Field'
IL_000d: ldarg.0
IL_000e: ldarg.2
IL_000f: stfld !1 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<Y>i__Field'
IL_0014: ldarg.0
IL_0015: ldarg.3
IL_0016: stfld !2 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<Z>i__Field'
IL_001b: ret
} // end of method '<>f__AnonymousType3`3'::.ctor
.method public hidebysig virtual instance bool
Equals(object 'value') cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 84 (0x54)
.maxstack 3
.locals init (class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'> V_0)
IL_0000: ldarg.1
IL_0001: isinst class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>
IL_0006: stloc.0
IL_0007: ldloc.0
IL_0008: brfalse.s IL_0052
IL_000a: call class [mscorlib]System.Collections.Generic.EqualityComparer`1<!0> class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<X>j__TPar'>::get_Default()
IL_000f: ldarg.0
IL_0010: ldfld !0 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<X>i__Field'
IL_0015: ldloc.0
IL_0016: ldfld !0 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<X>i__Field'
IL_001b: callvirt instance bool class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<X>j__TPar'>::Equals(!0,
!0)
IL_0020: brfalse.s IL_0052
IL_0022: call class [mscorlib]System.Collections.Generic.EqualityComparer`1<!0> class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<Y>j__TPar'>::get_Default()
IL_0027: ldarg.0
IL_0028: ldfld !1 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<Y>i__Field'
IL_002d: ldloc.0
IL_002e: ldfld !1 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<Y>i__Field'
IL_0033: callvirt instance bool class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<Y>j__TPar'>::Equals(!0,
!0)
IL_0038: brfalse.s IL_0052
IL_003a: call class [mscorlib]System.Collections.Generic.EqualityComparer`1<!0> class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<Z>j__TPar'>::get_Default()
IL_003f: ldarg.0
IL_0040: ldfld !2 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<Z>i__Field'
IL_0045: ldloc.0
IL_0046: ldfld !2 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<Z>i__Field'
IL_004b: callvirt instance bool class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<Z>j__TPar'>::Equals(!0,
!0)
IL_0050: br.s IL_0053
IL_0052: ldc.i4.0
IL_0053: ret
} // end of method '<>f__AnonymousType3`3'::Equals
.method public hidebysig virtual instance int32
GetHashCode() cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 75 (0x4b)
.maxstack 3
IL_0000: ldc.i4 0xb04731e1
IL_0005: ldc.i4 0xa5555529
IL_000a: mul
IL_000b: call class [mscorlib]System.Collections.Generic.EqualityComparer`1<!0> class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<X>j__TPar'>::get_Default()
IL_0010: ldarg.0
IL_0011: ldfld !0 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<X>i__Field'
IL_0016: callvirt instance int32 class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<X>j__TPar'>::GetHashCode(!0)
IL_001b: add
IL_001c: ldc.i4 0xa5555529
IL_0021: mul
IL_0022: call class [mscorlib]System.Collections.Generic.EqualityComparer`1<!0> class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<Y>j__TPar'>::get_Default()
IL_0027: ldarg.0
IL_0028: ldfld !1 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<Y>i__Field'
IL_002d: callvirt instance int32 class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<Y>j__TPar'>::GetHashCode(!0)
IL_0032: add
IL_0033: ldc.i4 0xa5555529
IL_0038: mul
IL_0039: call class [mscorlib]System.Collections.Generic.EqualityComparer`1<!0> class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<Z>j__TPar'>::get_Default()
IL_003e: ldarg.0
IL_003f: ldfld !2 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<Z>i__Field'
IL_0044: callvirt instance int32 class [mscorlib]System.Collections.Generic.EqualityComparer`1<!'<Z>j__TPar'>::GetHashCode(!0)
IL_0049: add
IL_004a: ret
} // end of method '<>f__AnonymousType3`3'::GetHashCode
.method public hidebysig virtual instance string
ToString() cil managed
{
.custom instance void [mscorlib]System.Diagnostics.DebuggerHiddenAttribute::.ctor() = ( 01 00 00 00 )
// Code size 199 (0xc7)
.maxstack 7
.locals init (!'<X>j__TPar' V_0,
!'<X>j__TPar' V_1,
!'<Y>j__TPar' V_2,
!'<Y>j__TPar' V_3,
!'<Z>j__TPar' V_4,
!'<Z>j__TPar' V_5)
IL_0000: ldnull
IL_0001: ldstr "{{ X = {0}, Y = {1}, Z = {2} }}"
IL_0006: ldc.i4.3
IL_0007: newarr [mscorlib]System.Object
IL_000c: dup
IL_000d: ldc.i4.0
IL_000e: ldarg.0
IL_000f: ldfld !0 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<X>i__Field'
IL_0014: stloc.0
IL_0015: ldloca.s V_0
IL_0017: ldloca.s V_1
IL_0019: initobj !'<X>j__TPar'
IL_001f: ldloc.1
IL_0020: box !'<X>j__TPar'
IL_0025: brtrue.s IL_003b
IL_0027: ldobj !'<X>j__TPar'
IL_002c: stloc.1
IL_002d: ldloca.s V_1
IL_002f: ldloc.1
IL_0030: box !'<X>j__TPar'
IL_0035: brtrue.s IL_003b
IL_0037: pop
IL_0038: ldnull
IL_0039: br.s IL_0046
IL_003b: constrained. !'<X>j__TPar'
IL_0041: callvirt instance string [mscorlib]System.Object::ToString()
IL_0046: stelem.ref
IL_0047: dup
IL_0048: ldc.i4.1
IL_0049: ldarg.0
IL_004a: ldfld !1 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<Y>i__Field'
IL_004f: stloc.2
IL_0050: ldloca.s V_2
IL_0052: ldloca.s V_3
IL_0054: initobj !'<Y>j__TPar'
IL_005a: ldloc.3
IL_005b: box !'<Y>j__TPar'
IL_0060: brtrue.s IL_0076
IL_0062: ldobj !'<Y>j__TPar'
IL_0067: stloc.3
IL_0068: ldloca.s V_3
IL_006a: ldloc.3
IL_006b: box !'<Y>j__TPar'
IL_0070: brtrue.s IL_0076
IL_0072: pop
IL_0073: ldnull
IL_0074: br.s IL_0081
IL_0076: constrained. !'<Y>j__TPar'
IL_007c: callvirt instance string [mscorlib]System.Object::ToString()
IL_0081: stelem.ref
IL_0082: dup
IL_0083: ldc.i4.2
IL_0084: ldarg.0
IL_0085: ldfld !2 class '<>f__AnonymousType3`3'<!'<X>j__TPar',!'<Y>j__TPar',!'<Z>j__TPar'>::'<Z>i__Field'
IL_008a: stloc.s V_4
IL_008c: ldloca.s V_4
IL_008e: ldloca.s V_5
IL_0090: initobj !'<Z>j__TPar'
IL_0096: ldloc.s V_5
IL_0098: box !'<Z>j__TPar'
IL_009d: brtrue.s IL_00b5
IL_009f: ldobj !'<Z>j__TPar'
IL_00a4: stloc.s V_5
IL_00a6: ldloca.s V_5
IL_00a8: ldloc.s V_5
IL_00aa: box !'<Z>j__TPar'
IL_00af: brtrue.s IL_00b5
IL_00b1: pop
IL_00b2: ldnull
IL_00b3: br.s IL_00c0
IL_00b5: constrained. !'<Z>j__TPar'
IL_00bb: callvirt instance string [mscorlib]System.Object::ToString()
IL_00c0: stelem.ref
IL_00c1: call string [mscorlib]System.String::Format(class [mscorlib]System.IFormatProvider,
string,
object[])
IL_00c6: ret
} // end of method '<>f__AnonymousType3`3'::ToString
.property instance !'<X>j__TPar' X()
{
.get instance !'<X>j__TPar' '<>f__AnonymousType3`3'::get_X()
} // end of property '<>f__AnonymousType3`3'::X
.property instance !'<Y>j__TPar' Y()
{
.get instance !'<Y>j__TPar' '<>f__AnonymousType3`3'::get_Y()
} // end of property '<>f__AnonymousType3`3'::Y
.property instance !'<Z>j__TPar' Z()
{
.get instance !'<Z>j__TPar' '<>f__AnonymousType3`3'::get_Z()
} // end of property '<>f__AnonymousType3`3'::Z
} // end of class '<>f__AnonymousType3`3'
.class public auto ansi beforefieldinit ICSharpCode.Decompiler.Tests.TestCases.Pretty.AnonymousTypes
extends [mscorlib]System.Object
{
.method private hidebysig instance void
SimpleTypes() cil managed
{
// Code size 62 (0x3e)
.maxstack 2
.locals init (class '<>f__AnonymousType0' V_0,
class '<>f__AnonymousType1`1'<int32> V_1,
class '<>f__AnonymousType2`2'<int32,int32> V_2)
IL_0000: nop
IL_0001: newobj instance void '<>f__AnonymousType0'::.ctor()
IL_0006: stloc.0
IL_0007: ldc.i4.5
IL_0008: newobj instance void class '<>f__AnonymousType1`1'<int32>::.ctor(!0)
IL_000d: stloc.1
IL_000e: ldc.i4.5
IL_000f: ldc.i4.s 10
IL_0011: newobj instance void class '<>f__AnonymousType2`2'<int32,int32>::.ctor(!0,
!1)
IL_0016: stloc.2
IL_0017: ldloc.0
IL_0018: call void [mscorlib]System.Console::WriteLine(object)
IL_001d: nop
IL_001e: ldloc.1
IL_001f: callvirt instance !0 class '<>f__AnonymousType1`1'<int32>::get_X()
IL_0024: call void [mscorlib]System.Console::WriteLine(int32)
IL_0029: nop
IL_002a: ldloc.2
IL_002b: callvirt instance !1 class '<>f__AnonymousType2`2'<int32,int32>::get_Y()
IL_0030: ldloc.2
IL_0031: callvirt instance !0 class '<>f__AnonymousType2`2'<int32,int32>::get_X()
IL_0036: add
IL_0037: call void [mscorlib]System.Console::WriteLine(int32)
IL_003c: nop
IL_003d: ret
} // end of method AnonymousTypes::SimpleTypes
.method private hidebysig instance void
SimpleArray() cil managed
{
// Code size 60 (0x3c)
.maxstack 6
.locals init (class '<>f__AnonymousType3`3'<int32,int32,int32>[] V_0)
IL_0000: nop
IL_0001: ldc.i4.2
IL_0002: newarr class '<>f__AnonymousType3`3'<int32,int32,int32>
IL_0007: dup
IL_0008: ldc.i4.0
IL_0009: ldc.i4.5
IL_000a: ldc.i4.2
IL_000b: ldc.i4.m1
IL_000c: newobj instance void class '<>f__AnonymousType3`3'<int32,int32,int32>::.ctor(!0,
!1,
!2)
IL_0011: stelem.ref
IL_0012: dup
IL_0013: ldc.i4.1
IL_0014: ldc.i4.3
IL_0015: ldc.i4.6
IL_0016: ldc.i4.s -6
IL_0018: newobj instance void class '<>f__AnonymousType3`3'<int32,int32,int32>::.ctor(!0,
!1,
!2)
IL_001d: stelem.ref
IL_001e: stloc.0
IL_001f: ldloc.0
IL_0020: ldc.i4.0
IL_0021: ldelem.ref
IL_0022: callvirt instance !0 class '<>f__AnonymousType3`3'<int32,int32,int32>::get_X()
IL_0027: call void [mscorlib]System.Console::WriteLine(int32)
IL_002c: nop
IL_002d: ldloc.0
IL_002e: ldc.i4.1
IL_002f: ldelem.ref
IL_0030: callvirt instance !0 class '<>f__AnonymousType3`3'<int32,int32,int32>::get_X()
IL_0035: call void [mscorlib]System.Console::WriteLine(int32)
IL_003a: nop
IL_003b: ret
} // end of method AnonymousTypes::SimpleArray
.method private hidebysig instance void
JaggedArray() cil managed
{
// Code size 84 (0x54)
.maxstack 6
.locals init (class '<>f__AnonymousType3`3'<int32,int32,int32>[] V_0,
class '<>f__AnonymousType3`3'<int32,int32,int32>[][] V_1)
IL_0000: nop
IL_0001: ldc.i4.2
IL_0002: newarr class '<>f__AnonymousType3`3'<int32,int32,int32>
IL_0007: dup
IL_0008: ldc.i4.0
IL_0009: ldc.i4.5
IL_000a: ldc.i4.2
IL_000b: ldc.i4.m1
IL_000c: newobj instance void class '<>f__AnonymousType3`3'<int32,int32,int32>::.ctor(!0,
!1,
!2)
IL_0011: stelem.ref
IL_0012: dup
IL_0013: ldc.i4.1
IL_0014: ldc.i4.3
IL_0015: ldc.i4.6
IL_0016: ldc.i4.s -6
IL_0018: newobj instance void class '<>f__AnonymousType3`3'<int32,int32,int32>::.ctor(!0,
!1,
!2)
IL_001d: stelem.ref
IL_001e: stloc.0
IL_001f: ldc.i4.2
IL_0020: newarr class '<>f__AnonymousType3`3'<int32,int32,int32>[]
IL_0025: dup
IL_0026: ldc.i4.0
IL_0027: ldloc.0
IL_0028: stelem.ref
IL_0029: dup
IL_002a: ldc.i4.1
IL_002b: ldloc.0
IL_002c: stelem.ref
IL_002d: stloc.1
IL_002e: ldloc.0
IL_002f: ldc.i4.0
IL_0030: ldelem.ref
IL_0031: callvirt instance !0 class '<>f__AnonymousType3`3'<int32,int32,int32>::get_X()
IL_0036: call void [mscorlib]System.Console::WriteLine(int32)
IL_003b: nop
IL_003c: ldloc.0
IL_003d: ldc.i4.1
IL_003e: ldelem.ref
IL_003f: callvirt instance !0 class '<>f__AnonymousType3`3'<int32,int32,int32>::get_X()
IL_0044: call void [mscorlib]System.Console::WriteLine(int32)
IL_0049: nop
IL_004a: ldloc.1
IL_004b: ldlen
IL_004c: conv.i4
IL_004d: call void [mscorlib]System.Console::WriteLine(int32)
IL_0052: nop
IL_0053: ret
} // end of method AnonymousTypes::JaggedArray
.method private hidebysig instance void
AnonymousTypeOutVar() cil managed
{
// Code size 29 (0x1d)
.maxstack 3
.locals init (class '<>f__AnonymousType2`2'<int32,int32> V_0)
IL_0000: nop
IL_0001: ldloca.s V_0
IL_0003: ldc.i4.1
IL_0004: ldc.i4.2
IL_0005: newobj instance void class '<>f__AnonymousType2`2'<int32,int32>::.ctor(!0,
!1)
IL_000a: call void ICSharpCode.Decompiler.Tests.TestCases.Pretty.AnonymousTypes::InlineVarDecl<class '<>f__AnonymousType2`2'<int32,int32>>(!!0&,
!!0)
IL_000f: nop
IL_0010: ldloc.0
IL_0011: callvirt instance !0 class '<>f__AnonymousType2`2'<int32,int32>::get_X()
IL_0016: call void [mscorlib]System.Console::WriteLine(int32)
IL_001b: nop
IL_001c: ret
} // end of method AnonymousTypes::AnonymousTypeOutVar
.method private hidebysig static void InlineVarDecl<T>([out] !!T& v,
!!T 'init') cil managed
{
// Code size 9 (0x9)
.maxstack 8
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldarg.1
IL_0003: stobj !!T
IL_0008: ret
} // end of method AnonymousTypes::InlineVarDecl
.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 AnonymousTypes::.ctor
} // end of class ICSharpCode.Decompiler.Tests.TestCases.Pretty.AnonymousTypes
// =============================================================
// *********** DISASSEMBLY COMPLETE ***********************

10
ICSharpCode.Decompiler/CSharp/Annotations.cs

@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using ICSharpCode.Decompiler.CSharp.Syntax;
using ICSharpCode.Decompiler.IL;
@ -158,11 +159,16 @@ namespace ICSharpCode.Decompiler.CSharp @@ -158,11 +159,16 @@ namespace ICSharpCode.Decompiler.CSharp
public class ILVariableResolveResult : ResolveResult
{
public readonly ILVariable Variable;
public ILVariableResolveResult(ILVariable v, IType type) : base(type)
public ILVariableResolveResult(ILVariable v) : base(v.Type)
{
this.Variable = v;
}
public ILVariableResolveResult(ILVariable v, IType type) : base(type)
{
this.Variable = v ?? throw new ArgumentNullException("v");
}
}
public class ForeachAnnotation

2
ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs

@ -806,7 +806,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -806,7 +806,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
Space();
outVarDeclarationExpression.Type.AcceptVisitor(this);
Space();
outVarDeclarationExpression.Expression.AcceptVisitor(this);
outVarDeclarationExpression.Variable.AcceptVisitor(this);
EndNode(outVarDeclarationExpression);
}

10
ICSharpCode.Decompiler/CSharp/Syntax/Expressions/OutVarDeclarationExpression.cs

@ -34,9 +34,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -34,9 +34,9 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
set { SetChildByRole(Roles.Type, value); }
}
public Expression Expression {
get { return GetChildByRole(Roles.Expression); }
set { SetChildByRole(Roles.Expression, value); }
public VariableInitializer Variable {
get { return GetChildByRole(Roles.Variable); }
set { SetChildByRole(Roles.Variable, value); }
}
public OutVarDeclarationExpression()
@ -46,7 +46,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -46,7 +46,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public OutVarDeclarationExpression(AstType type, string name)
{
this.Type = type;
this.Expression = new IdentifierExpression(name);
this.Variable = new VariableInitializer(name);
}
public override void AcceptVisitor(IAstVisitor visitor)
@ -67,7 +67,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -67,7 +67,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
var o = other as OutVarDeclarationExpression;
return o != null && this.Type.DoMatch(o.Type, match) && this.Expression.DoMatch(o.Expression, match);
return o != null && this.Type.DoMatch(o.Type, match) && this.Variable.DoMatch(o.Variable, match);
}
}
}

98
ICSharpCode.Decompiler/CSharp/Transforms/DeclareVariables.cs

@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
@ -84,31 +85,43 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -84,31 +85,43 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
/// Integer value that can be used to compare to VariableToDeclare instances
/// to determine which variable was used first in the source code.
///
/// Assuming both insertion points are on the same level, the variable
/// with the lower SourceOrder value has the insertion point that comes
/// first in the source code.
/// The variable with the lower SourceOrder value has the insertion point
/// that comes first in the source code.
/// </summary>
public int SourceOrder;
/// <summary>
/// The insertion point, i.e. the node before which the variable declaration should be inserted.
/// </summary>
public InsertionPoint InsertionPoint;
/// <summary>
/// The first use of the variable.
/// </summary>
public IdentifierExpression FirstUse;
public VariableToDeclare ReplacementDueToCollision;
public bool RemovedDueToCollision => ReplacementDueToCollision != null;
public VariableToDeclare(ILVariable variable, bool defaultInitialization, InsertionPoint insertionPoint, int sourceOrder)
public VariableToDeclare(ILVariable variable, bool defaultInitialization, InsertionPoint insertionPoint, IdentifierExpression firstUse, int sourceOrder)
{
this.ILVariable = variable;
this.DefaultInitialization = defaultInitialization;
this.InsertionPoint = insertionPoint;
this.FirstUse = firstUse;
this.SourceOrder = sourceOrder;
}
}
readonly Dictionary<ILVariable, VariableToDeclare> variableDict = new Dictionary<ILVariable, VariableToDeclare>();
TransformContext context;
public void Run(AstNode rootNode, TransformContext context)
{
try {
if (this.context != null)
throw new InvalidOperationException("Reentrancy in DeclareVariables?");
this.context = context;
variableDict.Clear();
EnsureExpressionStatementsAreValid(rootNode);
FindInsertionPoints(rootNode, 0);
@ -116,6 +129,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -116,6 +129,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
InsertVariableDeclarations(context);
UpdateAnnotations(rootNode);
} finally {
this.context = null;
variableDict.Clear();
}
}
@ -241,7 +255,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -241,7 +255,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
v.InsertionPoint = FindCommonParent(v.InsertionPoint, newPoint);
} else {
v = new VariableToDeclare(rr.Variable, rr.Variable.HasInitialValue,
newPoint, sourceOrder: variableDict.Count);
newPoint, identExpr, sourceOrder: variableDict.Count);
variableDict.Add(rr.Variable, v);
}
}
@ -323,11 +337,17 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -323,11 +337,17 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
// guarantee that it finds only blocks.
// Fix that up now.
while (!(v.InsertionPoint.nextNode.Parent is BlockStatement)) {
if (v.InsertionPoint.nextNode.Parent is ForStatement f && v.InsertionPoint.nextNode == f.Initializers.FirstOrDefault() && IsMatchingAssignment(v, out _))
if (v.InsertionPoint.nextNode.Parent is ForStatement f && v.InsertionPoint.nextNode == f.Initializers.FirstOrDefault() && IsMatchingAssignment(v, out _)) {
// Special case: the initializer of a ForStatement can also declare a variable (with scope local to the for loop).
break;
}
v.InsertionPoint = v.InsertionPoint.Up();
}
// Note: 'out var', pattern matching etc. is not considered a valid insertion point here, because the scope of the
// resulting variable is not restricted to the parent node of the insertion point, but extends to the whole BlockStatement.
// We moved up the insertion point to the whole BlockStatement so that we can resolve collisions,
// later we might decide to declare the variable more locally (as 'out var') instead if still possible.
// Go through all potentially colliding variables:
foreach (var prev in multiDict[v.Name]) {
if (prev.RemovedDueToCollision)
@ -341,11 +361,16 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -341,11 +361,16 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
prev.ReplacementDueToCollision = v;
// Continue checking other entries in multiDict against the new position of `v`.
if (prev.SourceOrder < v.SourceOrder) {
// If we switch v's insertion point to prev's insertion point,
// we also need to copy prev's SourceOrder value.
// Switch v's insertion point to prev's insertion point:
v.InsertionPoint = point1;
// Since prev was first, it has the correct SourceOrder/FirstUse values
// for the new combined variable:
v.SourceOrder = prev.SourceOrder;
v.FirstUse = prev.FirstUse;
} else {
// v is first in source order, so it keeps its old insertion point
// (and other properties), except that the insertion point is
// moved up to prev's level.
v.InsertionPoint = point2;
}
v.DefaultInitialization |= prev.DefaultInitialization;
@ -373,13 +398,13 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -373,13 +398,13 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
void InsertVariableDeclarations(TransformContext context)
{
var replacements = new List<KeyValuePair<AstNode, AstNode>>();
foreach (var p in variableDict) {
var v = p.Value;
var replacements = new List<(AstNode, AstNode)>();
foreach (var (ilVariable, v) in variableDict) {
if (v.RemovedDueToCollision)
continue;
if (IsMatchingAssignment(v, out AssignmentExpression assignment)) {
// 'int v; v = expr;' can be combined to 'int v = expr;'
AstType type;
if (context.Settings.AnonymousTypes && v.Type.ContainsAnonymousType()) {
type = new SimpleType("var");
@ -394,15 +419,28 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -394,15 +419,28 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
init.AddAnnotation(annotation);
}
}
replacements.Add(new KeyValuePair<AstNode, AstNode>(v.InsertionPoint.nextNode, vds));
replacements.Add((v.InsertionPoint.nextNode, vds));
} else if (CanBeDeclaredAsOutVariable(v, out var dirExpr)) {
// 'T v; SomeCall(out v);' can be combined to 'SomeCall(out var v);'
AstType type;
if (context.Settings.AnonymousTypes && v.Type.ContainsAnonymousType()) {
type = new SimpleType("var");
} else {
type = context.TypeSystemAstBuilder.ConvertType(v.Type);
}
var ovd = new OutVarDeclarationExpression(type, v.Name);
ovd.Variable.AddAnnotation(new ILVariableResolveResult(ilVariable));
ovd.CopyAnnotationsFrom(dirExpr);
replacements.Add((dirExpr, ovd));
} else {
// Insert a separate declaration statement.
Expression initializer = null;
AstType type = context.TypeSystemAstBuilder.ConvertType(v.Type);
if (v.DefaultInitialization) {
initializer = new DefaultValueExpression(type.Clone());
}
var vds = new VariableDeclarationStatement(type, v.Name, initializer);
vds.Variables.Single().AddAnnotation(new ILVariableResolveResult(p.Key, p.Key.Type));
vds.Variables.Single().AddAnnotation(new ILVariableResolveResult(ilVariable));
Debug.Assert(v.InsertionPoint.nextNode.Role == BlockStatement.StatementRole);
v.InsertionPoint.nextNode.Parent.InsertChildBefore(
v.InsertionPoint.nextNode,
@ -411,11 +449,35 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -411,11 +449,35 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
}
}
// perform replacements at end, so that we don't replace a node while it is still referenced by a VariableToDeclare
foreach (var pair in replacements) {
pair.Key.ReplaceWith(pair.Value);
foreach (var (oldNode, newNode) in replacements) {
oldNode.ReplaceWith(newNode);
}
}
private bool CanBeDeclaredAsOutVariable(VariableToDeclare v, out DirectionExpression dirExpr)
{
dirExpr = v.FirstUse.Parent as DirectionExpression;
if (dirExpr == null || dirExpr.FieldDirection != FieldDirection.Out)
return false;
if (!context.Settings.OutVariables)
return false;
if (v.DefaultInitialization)
return false;
for (AstNode node = v.FirstUse; node != null; node = node.Parent) {
if (node.Role == Roles.EmbeddedStatement) {
return false;
}
switch (node) {
case IfElseStatement _: // variable declared in if condition appears in parent scope
case ExpressionStatement _:
return node == v.InsertionPoint.nextNode;
case Statement _:
return false; // other statements (e.g. while) don't allow variables to be promoted to parent scope
}
}
return false;
}
/// <summary>
/// Update ILVariableResolveResult annotations of all ILVariables that have been replaced by ResolveCollisions.
/// </summary>

18
ICSharpCode.Decompiler/DecompilerSettings.cs

@ -72,6 +72,9 @@ namespace ICSharpCode.Decompiler @@ -72,6 +72,9 @@ namespace ICSharpCode.Decompiler
stringInterpolation = false;
dictionaryInitializers = false;
}
if (languageVersion < CSharp.LanguageVersion.CSharp7) {
outVariables = false;
}
}
bool anonymousMethods = true;
@ -514,6 +517,21 @@ namespace ICSharpCode.Decompiler @@ -514,6 +517,21 @@ namespace ICSharpCode.Decompiler
}
}
bool outVariables = true;
/// <summary>
/// Gets/Sets whether simple calculated getter-only property declarations should use expression body syntax.
/// </summary>
public bool OutVariables {
get { return outVariables; }
set {
if (outVariables != value) {
outVariables = value;
OnPropertyChanged();
}
}
}
#region Options to aid VB decompilation
bool introduceIncrementAndDecrement = true;

Loading…
Cancel
Save