From 028cbe69a4ac752a4f67e34aadd120e617477488 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 4 Jun 2018 17:34:54 +0200 Subject: [PATCH] Fix decompilation of auto properties with explicit implementation --- .../TestCases/Pretty/PropertiesAndEvents.cs | 10 ++---- .../TestCases/Pretty/PropertiesAndEvents.il | 33 ++++++++++--------- .../Pretty/PropertiesAndEvents.opt.il | 11 ++++--- .../Pretty/PropertiesAndEvents.opt.roslyn.il | 9 +++-- .../Pretty/PropertiesAndEvents.roslyn.il | 33 +++++++++---------- .../Transforms/PatternStatementTransform.cs | 2 -- 6 files changed, 47 insertions(+), 51 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.cs index 9228714fe..82da3eb28 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.cs @@ -56,15 +56,9 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { private EventHandler Changed; - private int backingField; - int IChange.Property { - get { - return backingField; - } - set { - backingField = value; - } + get; + set; } event EventHandler IChange.Changed { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.il index 60b605354..e3051215a 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.il @@ -10,9 +10,9 @@ } .assembly PropertiesAndEvents { + .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. - .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) .permissionset reqmin = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} .hash algorithm 0x00008004 @@ -303,35 +303,36 @@ implements ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/IChange { .field private class [mscorlib]System.EventHandler Changed - .field private int32 backingField + .field private int32 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .method private hidebysig newslot specialname virtual final instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IChange.get_Property() cil managed { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .override ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/IChange::get_Property - // Code size 12 (0xc) + // Code size 11 (0xb) .maxstack 1 .locals init (int32 V_0) - IL_0000: nop - IL_0001: ldarg.0 - IL_0002: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/Change::backingField - IL_0007: stloc.0 - IL_0008: br.s IL_000a + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/Change::'k__BackingField' + IL_0006: stloc.0 + IL_0007: br.s IL_0009 - IL_000a: ldloc.0 - IL_000b: ret + IL_0009: ldloc.0 + IL_000a: ret } // end of method Change::ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IChange.get_Property .method private hidebysig newslot specialname virtual final instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IChange.set_Property(int32 'value') cil managed { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .override ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/IChange::set_Property - // Code size 9 (0x9) + // Code size 8 (0x8) .maxstack 8 - IL_0000: nop - IL_0001: ldarg.0 - IL_0002: ldarg.1 - IL_0003: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/Change::backingField - IL_0008: ret + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/Change::'k__BackingField' + IL_0007: ret } // end of method Change::ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IChange.set_Property .method private hidebysig newslot specialname virtual final diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.opt.il index ffaed5396..33a84b3ae 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.opt.il @@ -10,9 +10,9 @@ } .assembly PropertiesAndEvents.opt { + .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. - .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) .permissionset reqmin = {[mscorlib]System.Security.Permissions.SecurityPermissionAttribute = {property bool 'SkipVerification' = bool(true)}} .hash algorithm 0x00008004 @@ -287,27 +287,30 @@ implements ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/IChange { .field private class [mscorlib]System.EventHandler Changed - .field private int32 backingField + .field private int32 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .method private hidebysig newslot specialname virtual final instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IChange.get_Property() cil managed { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .override ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/IChange::get_Property // Code size 7 (0x7) .maxstack 8 IL_0000: ldarg.0 - IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/Change::backingField + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/Change::'k__BackingField' IL_0006: ret } // end of method Change::ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IChange.get_Property .method private hidebysig newslot specialname virtual final instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IChange.set_Property(int32 'value') cil managed { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .override ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/IChange::set_Property // Code size 8 (0x8) .maxstack 8 IL_0000: ldarg.0 IL_0001: ldarg.1 - IL_0002: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/Change::backingField + IL_0002: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/Change::'k__BackingField' IL_0007: ret } // end of method Change::ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IChange.set_Property diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.opt.roslyn.il index 1b6a55281..10bcc140c 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.opt.roslyn.il @@ -300,27 +300,30 @@ implements ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/IChange { .field private class [mscorlib]System.EventHandler Changed - .field private int32 backingField + .field private int32 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .method private hidebysig newslot specialname virtual final instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IChange.get_Property() cil managed { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .override ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/IChange::get_Property // Code size 7 (0x7) .maxstack 8 IL_0000: ldarg.0 - IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/Change::backingField + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/Change::'k__BackingField' IL_0006: ret } // end of method Change::ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IChange.get_Property .method private hidebysig newslot specialname virtual final instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IChange.set_Property(int32 'value') cil managed { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .override ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/IChange::set_Property // Code size 8 (0x8) .maxstack 8 IL_0000: ldarg.0 IL_0001: ldarg.1 - IL_0002: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/Change::backingField + IL_0002: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/Change::'k__BackingField' IL_0007: ret } // end of method Change::ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IChange.set_Property diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.roslyn.il index 568262f67..9797b652d 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.roslyn.il @@ -308,35 +308,32 @@ implements ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/IChange { .field private class [mscorlib]System.EventHandler Changed - .field private int32 backingField + .field private int32 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) .method private hidebysig newslot specialname virtual final instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IChange.get_Property() cil managed { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .override ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/IChange::get_Property - // Code size 12 (0xc) - .maxstack 1 - .locals init (int32 V_0) - IL_0000: nop - IL_0001: ldarg.0 - IL_0002: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/Change::backingField - IL_0007: stloc.0 - IL_0008: br.s IL_000a - - IL_000a: ldloc.0 - IL_000b: ret + // Code size 7 (0x7) + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/Change::'k__BackingField' + IL_0006: ret } // end of method Change::ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IChange.get_Property .method private hidebysig newslot specialname virtual final instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IChange.set_Property(int32 'value') cil managed { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .override ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/IChange::set_Property - // Code size 9 (0x9) + // Code size 8 (0x8) .maxstack 8 - IL_0000: nop - IL_0001: ldarg.0 - IL_0002: ldarg.1 - IL_0003: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/Change::backingField - IL_0008: ret + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/Change::'k__BackingField' + IL_0007: ret } // end of method Change::ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IChange.set_Property .method private hidebysig newslot specialname virtual final diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs b/ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs index e403481b4..5aa7e90f2 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs @@ -488,8 +488,6 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms PropertyDeclaration TransformAutomaticProperties(PropertyDeclaration property) { - if (!property.PrivateImplementationType.IsNull) - return null; PropertyDefinition cecilProperty = context.TypeSystem.GetCecil(property.GetSymbol() as IProperty) as PropertyDefinition; if (cecilProperty == null || cecilProperty.GetMethod == null) return null;