diff --git a/ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs b/ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs index 73b843890..4dca2f114 100644 --- a/ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs @@ -112,6 +112,12 @@ namespace ICSharpCode.Decompiler.Tests Run(); } + [Test] + public void Issue1157() + { + Run(); + } + [Test, Ignore("?")] public void FSharpLoops_Debug() { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1157.cs b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1157.cs new file mode 100644 index 000000000..87254c0e9 --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1157.cs @@ -0,0 +1,14 @@ +using System; + +namespace Issue1157 +{ + internal abstract class BaseClass + { + public abstract event EventHandler IDontKnowMeHereOut; + } + + internal class OtherClass : BaseClass + { + public override event EventHandler IDontKnowMeHereOut; + } +} \ No newline at end of file diff --git a/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1157.il b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1157.il new file mode 100644 index 000000000..e8652e08c --- /dev/null +++ b/ICSharpCode.Decompiler.Tests/TestCases/ILPretty/Issue1157.il @@ -0,0 +1,173 @@ +.assembly Issue1157 +{ + .hash algorithm 0x00008004 // SHA1 + .ver 1:0:0:0 +} + +.module Issue1157.exe +// MVID: {4C6C7F98-AEB2-4A19-BE6F-43171E6113F1} +.corflags 0x00020003 // ILOnly, Required32Bit, Preferred32Bit + +.class private auto ansi abstract beforefieldinit Issue1157.BaseClass + extends [mscorlib]System.Object +{ + // Methods + .method public hidebysig specialname newslot abstract virtual + instance void add_IDontKnowMeHereOut ( + class [mscorlib]System.EventHandler 'value' + ) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( + 01 00 00 00 + ) + } // end of method BaseClass::add_IDontKnowMeHereOut + + .method public hidebysig specialname newslot abstract virtual + instance void remove_IDontKnowMeHereOut ( + class [mscorlib]System.EventHandler 'value' + ) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( + 01 00 00 00 + ) + } // end of method BaseClass::remove_IDontKnowMeHereOut + + .method family hidebysig specialname rtspecialname + instance void .ctor () cil managed + { + // Method begins at RVA 0x2063 + // 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 BaseClass::.ctor + + // Events + .event [mscorlib]System.EventHandler IDontKnowMeHereOut + { + .addon instance void Issue1157.BaseClass::add_IDontKnowMeHereOut(class [mscorlib]System.EventHandler) + .removeon instance void Issue1157.BaseClass::remove_IDontKnowMeHereOut(class [mscorlib]System.EventHandler) + } + + +} // end of class Issue1157.BaseClass + +.class private auto ansi beforefieldinit Issue1157.OtherClass + extends Issue1157.BaseClass +{ + // Fields + .field private class [mscorlib]System.EventHandler IDontKnowMeHereOut + .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 + ) + + // Methods + .method public hidebysig specialname virtual + instance void add_IDontKnowMeHereOut ( + class [mscorlib]System.EventHandler 'value' + ) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( + 01 00 00 00 + ) + // Method begins at RVA 0x206c + // Code size 41 (0x29) + .maxstack 3 + .locals init ( + [0] class [mscorlib]System.EventHandler, + [1] class [mscorlib]System.EventHandler, + [2] class [mscorlib]System.EventHandler + ) + + IL_0000: ldarg.0 + IL_0001: ldfld class [mscorlib]System.EventHandler Issue1157.OtherClass::IDontKnowMeHereOut + IL_0006: stloc.0 + // loop start (head: IL_0007) + IL_0007: ldloc.0 + IL_0008: stloc.1 + IL_0009: ldloc.1 + IL_000a: ldarg.1 + IL_000b: call class [mscorlib]System.Delegate [mscorlib]System.Delegate::Combine(class [mscorlib]System.Delegate, class [mscorlib]System.Delegate) + IL_0010: castclass [mscorlib]System.EventHandler + IL_0015: stloc.2 + IL_0016: ldarg.0 + IL_0017: ldflda class [mscorlib]System.EventHandler Issue1157.OtherClass::IDontKnowMeHereOut + IL_001c: ldloc.2 + IL_001d: ldloc.1 + IL_001e: call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange(!!0&, !!0, !!0) + IL_0023: stloc.0 + IL_0024: ldloc.0 + IL_0025: ldloc.1 + IL_0026: bne.un.s IL_0007 + // end loop + IL_0028: ret + } // end of method OtherClass::add_IDontKnowMeHereOut + + .method public hidebysig specialname virtual + instance void remove_IDontKnowMeHereOut ( + class [mscorlib]System.EventHandler 'value' + ) cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( + 01 00 00 00 + ) + // Method begins at RVA 0x20a4 + // Code size 41 (0x29) + .maxstack 3 + .locals init ( + [0] class [mscorlib]System.EventHandler, + [1] class [mscorlib]System.EventHandler, + [2] class [mscorlib]System.EventHandler + ) + + IL_0000: ldarg.0 + IL_0001: ldfld class [mscorlib]System.EventHandler Issue1157.OtherClass::IDontKnowMeHereOut + IL_0006: stloc.0 + // loop start (head: IL_0007) + IL_0007: ldloc.0 + IL_0008: stloc.1 + IL_0009: ldloc.1 + IL_000a: ldarg.1 + IL_000b: call class [mscorlib]System.Delegate [mscorlib]System.Delegate::Remove(class [mscorlib]System.Delegate, class [mscorlib]System.Delegate) + IL_0010: castclass [mscorlib]System.EventHandler + IL_0015: stloc.2 + IL_0016: ldarg.0 + IL_0017: ldflda class [mscorlib]System.EventHandler Issue1157.OtherClass::IDontKnowMeHereOut + IL_001c: ldloc.2 + IL_001d: ldloc.1 + IL_001e: call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange(!!0&, !!0, !!0) + IL_0023: stloc.0 + IL_0024: ldloc.0 + IL_0025: ldloc.1 + IL_0026: bne.un.s IL_0007 + // end loop + IL_0028: ret + } // end of method OtherClass::remove_IDontKnowMeHereOut + + .method public hidebysig specialname rtspecialname + instance void .ctor () cil managed + { + // Method begins at RVA 0x20d9 + // Code size 8 (0x8) + .maxstack 8 + + IL_0000: ldarg.0 + IL_0001: call instance void Issue1157.BaseClass::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method OtherClass::.ctor + + // Events + .event [mscorlib]System.EventHandler IDontKnowMeHereOut + { + .addon instance void Issue1157.OtherClass::add_IDontKnowMeHereOut(class [mscorlib]System.EventHandler) + .removeon instance void Issue1157.OtherClass::remove_IDontKnowMeHereOut(class [mscorlib]System.EventHandler) + } + +} // end of class Issue1157.OtherClass \ No newline at end of file diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.cs index 3f8d59d1f..bcfdbaa70 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.cs @@ -14,6 +14,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty event Action Event; } + private abstract class BaseClass + { + public abstract event EventHandler ThisIsAnAbstractEvent; + } + + private class OtherClass : BaseClass + { + public override event EventHandler ThisIsAnAbstractEvent; + } + private class Impl : IBase { int IBase.Test { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.il index fd4be9f50..e9596891f 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.il @@ -61,11 +61,142 @@ } // end of event IBase::Event .property instance int32 Test() { - .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/IBase::get_Test() .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/IBase::set_Test(int32) + .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/IBase::get_Test() } // end of property IBase::Test } // end of class IBase + .class abstract auto ansi nested private beforefieldinit BaseClass + extends [mscorlib]System.Object + { + .method public hidebysig newslot specialname abstract virtual + instance void add_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler 'value') cil managed + { + } // end of method BaseClass::add_ThisIsAnAbstractEvent + + .method public hidebysig newslot specialname abstract virtual + instance void remove_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler 'value') cil managed + { + } // end of method BaseClass::remove_ThisIsAnAbstractEvent + + .method family 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 BaseClass::.ctor + + .event [mscorlib]System.EventHandler ThisIsAnAbstractEvent + { + .addon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/BaseClass::add_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler) + .removeon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/BaseClass::remove_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler) + } // end of event BaseClass::ThisIsAnAbstractEvent + } // end of class BaseClass + + .class auto ansi nested private beforefieldinit OtherClass + extends ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/BaseClass + { + .field private class [mscorlib]System.EventHandler ThisIsAnAbstractEvent + .method public hidebysig specialname virtual + instance void add_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler 'value') cil managed + { + // Code size 48 (0x30) + .maxstack 3 + .locals init (class [mscorlib]System.EventHandler V_0, + class [mscorlib]System.EventHandler V_1, + class [mscorlib]System.EventHandler V_2, + bool V_3) + IL_0000: ldarg.0 + IL_0001: ldfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/OtherClass::ThisIsAnAbstractEvent + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: stloc.1 + IL_0009: ldloc.1 + IL_000a: ldarg.1 + IL_000b: call class [mscorlib]System.Delegate [mscorlib]System.Delegate::Combine(class [mscorlib]System.Delegate, + class [mscorlib]System.Delegate) + IL_0010: castclass [mscorlib]System.EventHandler + IL_0015: stloc.2 + IL_0016: ldarg.0 + IL_0017: ldflda class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/OtherClass::ThisIsAnAbstractEvent + IL_001c: ldloc.2 + IL_001d: ldloc.1 + IL_001e: call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange(!!0&, + !!0, + !!0) + IL_0023: stloc.0 + IL_0024: ldloc.0 + IL_0025: ldloc.1 + IL_0026: ceq + IL_0028: ldc.i4.0 + IL_0029: ceq + IL_002b: stloc.3 + IL_002c: ldloc.3 + IL_002d: brtrue.s IL_0007 + + IL_002f: ret + } // end of method OtherClass::add_ThisIsAnAbstractEvent + + .method public hidebysig specialname virtual + instance void remove_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler 'value') cil managed + { + // Code size 48 (0x30) + .maxstack 3 + .locals init (class [mscorlib]System.EventHandler V_0, + class [mscorlib]System.EventHandler V_1, + class [mscorlib]System.EventHandler V_2, + bool V_3) + IL_0000: ldarg.0 + IL_0001: ldfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/OtherClass::ThisIsAnAbstractEvent + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: stloc.1 + IL_0009: ldloc.1 + IL_000a: ldarg.1 + IL_000b: call class [mscorlib]System.Delegate [mscorlib]System.Delegate::Remove(class [mscorlib]System.Delegate, + class [mscorlib]System.Delegate) + IL_0010: castclass [mscorlib]System.EventHandler + IL_0015: stloc.2 + IL_0016: ldarg.0 + IL_0017: ldflda class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/OtherClass::ThisIsAnAbstractEvent + IL_001c: ldloc.2 + IL_001d: ldloc.1 + IL_001e: call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange(!!0&, + !!0, + !!0) + IL_0023: stloc.0 + IL_0024: ldloc.0 + IL_0025: ldloc.1 + IL_0026: ceq + IL_0028: ldc.i4.0 + IL_0029: ceq + IL_002b: stloc.3 + IL_002c: ldloc.3 + IL_002d: brtrue.s IL_0007 + + IL_002f: ret + } // end of method OtherClass::remove_ThisIsAnAbstractEvent + + .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 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/BaseClass::.ctor() + IL_0006: ret + } // end of method OtherClass::.ctor + + .event [mscorlib]System.EventHandler ThisIsAnAbstractEvent + { + .addon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/OtherClass::add_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler) + .removeon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/OtherClass::remove_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler) + } // end of event OtherClass::ThisIsAnAbstractEvent + } // end of class OtherClass + .class auto ansi nested private beforefieldinit Impl extends [mscorlib]System.Object implements ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/IBase @@ -128,8 +259,8 @@ } // end of event Impl::ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IBase.Event .property instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IBase.Test() { - .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/Impl::ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IBase.set_Test(int32) .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/Impl::ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IBase.get_Test() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/Impl::ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IBase.set_Test(int32) } // end of property Impl::ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IBase.Test } // end of class Impl @@ -407,18 +538,18 @@ .event [mscorlib]System.EventHandler AutomaticEvent { - .addon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents::add_AutomaticEvent(class [mscorlib]System.EventHandler) .removeon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents::remove_AutomaticEvent(class [mscorlib]System.EventHandler) + .addon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents::add_AutomaticEvent(class [mscorlib]System.EventHandler) } // end of event PropertiesAndEvents::AutomaticEvent .event [mscorlib]System.EventHandler AutomaticEventWithInitializer { - .removeon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents::remove_AutomaticEventWithInitializer(class [mscorlib]System.EventHandler) .addon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents::add_AutomaticEventWithInitializer(class [mscorlib]System.EventHandler) + .removeon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents::remove_AutomaticEventWithInitializer(class [mscorlib]System.EventHandler) } // end of event PropertiesAndEvents::AutomaticEventWithInitializer .event [mscorlib]System.EventHandler CustomEvent { - .removeon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents::remove_CustomEvent(class [mscorlib]System.EventHandler) .addon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents::add_CustomEvent(class [mscorlib]System.EventHandler) + .removeon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents::remove_CustomEvent(class [mscorlib]System.EventHandler) } // end of event PropertiesAndEvents::CustomEvent .property instance int32 Value() { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.opt.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.opt.il index 8cf711c57..27326d24c 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.opt.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.opt.il @@ -61,11 +61,130 @@ } // end of event IBase::Event .property instance int32 Test() { - .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/IBase::get_Test() .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/IBase::set_Test(int32) + .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/IBase::get_Test() } // end of property IBase::Test } // end of class IBase + .class abstract auto ansi nested private beforefieldinit BaseClass + extends [mscorlib]System.Object + { + .method public hidebysig newslot specialname abstract virtual + instance void add_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler 'value') cil managed + { + } // end of method BaseClass::add_ThisIsAnAbstractEvent + + .method public hidebysig newslot specialname abstract virtual + instance void remove_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler 'value') cil managed + { + } // end of method BaseClass::remove_ThisIsAnAbstractEvent + + .method family 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 BaseClass::.ctor + + .event [mscorlib]System.EventHandler ThisIsAnAbstractEvent + { + .addon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/BaseClass::add_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler) + .removeon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/BaseClass::remove_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler) + } // end of event BaseClass::ThisIsAnAbstractEvent + } // end of class BaseClass + + .class auto ansi nested private beforefieldinit OtherClass + extends ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/BaseClass + { + .field private class [mscorlib]System.EventHandler ThisIsAnAbstractEvent + .method public hidebysig specialname virtual + instance void add_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler 'value') cil managed + { + // Code size 41 (0x29) + .maxstack 3 + .locals init (class [mscorlib]System.EventHandler V_0, + class [mscorlib]System.EventHandler V_1, + class [mscorlib]System.EventHandler V_2) + IL_0000: ldarg.0 + IL_0001: ldfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/OtherClass::ThisIsAnAbstractEvent + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: stloc.1 + IL_0009: ldloc.1 + IL_000a: ldarg.1 + IL_000b: call class [mscorlib]System.Delegate [mscorlib]System.Delegate::Combine(class [mscorlib]System.Delegate, + class [mscorlib]System.Delegate) + IL_0010: castclass [mscorlib]System.EventHandler + IL_0015: stloc.2 + IL_0016: ldarg.0 + IL_0017: ldflda class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/OtherClass::ThisIsAnAbstractEvent + IL_001c: ldloc.2 + IL_001d: ldloc.1 + IL_001e: call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange(!!0&, + !!0, + !!0) + IL_0023: stloc.0 + IL_0024: ldloc.0 + IL_0025: ldloc.1 + IL_0026: bne.un.s IL_0007 + + IL_0028: ret + } // end of method OtherClass::add_ThisIsAnAbstractEvent + + .method public hidebysig specialname virtual + instance void remove_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler 'value') cil managed + { + // Code size 41 (0x29) + .maxstack 3 + .locals init (class [mscorlib]System.EventHandler V_0, + class [mscorlib]System.EventHandler V_1, + class [mscorlib]System.EventHandler V_2) + IL_0000: ldarg.0 + IL_0001: ldfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/OtherClass::ThisIsAnAbstractEvent + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: stloc.1 + IL_0009: ldloc.1 + IL_000a: ldarg.1 + IL_000b: call class [mscorlib]System.Delegate [mscorlib]System.Delegate::Remove(class [mscorlib]System.Delegate, + class [mscorlib]System.Delegate) + IL_0010: castclass [mscorlib]System.EventHandler + IL_0015: stloc.2 + IL_0016: ldarg.0 + IL_0017: ldflda class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/OtherClass::ThisIsAnAbstractEvent + IL_001c: ldloc.2 + IL_001d: ldloc.1 + IL_001e: call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange(!!0&, + !!0, + !!0) + IL_0023: stloc.0 + IL_0024: ldloc.0 + IL_0025: ldloc.1 + IL_0026: bne.un.s IL_0007 + + IL_0028: ret + } // end of method OtherClass::remove_ThisIsAnAbstractEvent + + .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 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/BaseClass::.ctor() + IL_0006: ret + } // end of method OtherClass::.ctor + + .event [mscorlib]System.EventHandler ThisIsAnAbstractEvent + { + .addon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/OtherClass::add_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler) + .removeon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/OtherClass::remove_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler) + } // end of event OtherClass::ThisIsAnAbstractEvent + } // end of class OtherClass + .class auto ansi nested private beforefieldinit Impl extends [mscorlib]System.Object implements ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/IBase @@ -124,8 +243,8 @@ } // end of event Impl::ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IBase.Event .property instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IBase.Test() { - .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/Impl::ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IBase.set_Test(int32) .get instance int32 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/Impl::ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IBase.get_Test() + .set instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/Impl::ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IBase.set_Test(int32) } // end of property Impl::ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents.IBase.Test } // end of class Impl @@ -360,18 +479,18 @@ .event [mscorlib]System.EventHandler AutomaticEvent { - .addon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents::add_AutomaticEvent(class [mscorlib]System.EventHandler) .removeon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents::remove_AutomaticEvent(class [mscorlib]System.EventHandler) + .addon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents::add_AutomaticEvent(class [mscorlib]System.EventHandler) } // end of event PropertiesAndEvents::AutomaticEvent .event [mscorlib]System.EventHandler AutomaticEventWithInitializer { - .removeon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents::remove_AutomaticEventWithInitializer(class [mscorlib]System.EventHandler) .addon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents::add_AutomaticEventWithInitializer(class [mscorlib]System.EventHandler) + .removeon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents::remove_AutomaticEventWithInitializer(class [mscorlib]System.EventHandler) } // end of event PropertiesAndEvents::AutomaticEventWithInitializer .event [mscorlib]System.EventHandler CustomEvent { - .removeon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents::remove_CustomEvent(class [mscorlib]System.EventHandler) .addon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents::add_CustomEvent(class [mscorlib]System.EventHandler) + .removeon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents::remove_CustomEvent(class [mscorlib]System.EventHandler) } // end of event PropertiesAndEvents::CustomEvent .property instance int32 Value() { diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.opt.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.opt.roslyn.il index 76da51a5b..095c7f611 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.opt.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.opt.roslyn.il @@ -72,6 +72,130 @@ } // end of property IBase::Test } // end of class IBase + .class abstract auto ansi nested private beforefieldinit BaseClass + extends [mscorlib]System.Object + { + .method public hidebysig newslot specialname abstract virtual + instance void add_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler 'value') cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + } // end of method BaseClass::add_ThisIsAnAbstractEvent + + .method public hidebysig newslot specialname abstract virtual + instance void remove_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler 'value') cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + } // end of method BaseClass::remove_ThisIsAnAbstractEvent + + .method family 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 BaseClass::.ctor + + .event [mscorlib]System.EventHandler ThisIsAnAbstractEvent + { + .addon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/BaseClass::add_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler) + .removeon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/BaseClass::remove_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler) + } // end of event BaseClass::ThisIsAnAbstractEvent + } // end of class BaseClass + + .class auto ansi nested private beforefieldinit OtherClass + extends ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/BaseClass + { + .field private class [mscorlib]System.EventHandler ThisIsAnAbstractEvent + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .method public hidebysig specialname virtual + instance void add_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler 'value') cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 41 (0x29) + .maxstack 3 + .locals init (class [mscorlib]System.EventHandler V_0, + class [mscorlib]System.EventHandler V_1, + class [mscorlib]System.EventHandler V_2) + IL_0000: ldarg.0 + IL_0001: ldfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/OtherClass::ThisIsAnAbstractEvent + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: stloc.1 + IL_0009: ldloc.1 + IL_000a: ldarg.1 + IL_000b: call class [mscorlib]System.Delegate [mscorlib]System.Delegate::Combine(class [mscorlib]System.Delegate, + class [mscorlib]System.Delegate) + IL_0010: castclass [mscorlib]System.EventHandler + IL_0015: stloc.2 + IL_0016: ldarg.0 + IL_0017: ldflda class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/OtherClass::ThisIsAnAbstractEvent + IL_001c: ldloc.2 + IL_001d: ldloc.1 + IL_001e: call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange(!!0&, + !!0, + !!0) + IL_0023: stloc.0 + IL_0024: ldloc.0 + IL_0025: ldloc.1 + IL_0026: bne.un.s IL_0007 + + IL_0028: ret + } // end of method OtherClass::add_ThisIsAnAbstractEvent + + .method public hidebysig specialname virtual + instance void remove_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler 'value') cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 41 (0x29) + .maxstack 3 + .locals init (class [mscorlib]System.EventHandler V_0, + class [mscorlib]System.EventHandler V_1, + class [mscorlib]System.EventHandler V_2) + IL_0000: ldarg.0 + IL_0001: ldfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/OtherClass::ThisIsAnAbstractEvent + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: stloc.1 + IL_0009: ldloc.1 + IL_000a: ldarg.1 + IL_000b: call class [mscorlib]System.Delegate [mscorlib]System.Delegate::Remove(class [mscorlib]System.Delegate, + class [mscorlib]System.Delegate) + IL_0010: castclass [mscorlib]System.EventHandler + IL_0015: stloc.2 + IL_0016: ldarg.0 + IL_0017: ldflda class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/OtherClass::ThisIsAnAbstractEvent + IL_001c: ldloc.2 + IL_001d: ldloc.1 + IL_001e: call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange(!!0&, + !!0, + !!0) + IL_0023: stloc.0 + IL_0024: ldloc.0 + IL_0025: ldloc.1 + IL_0026: bne.un.s IL_0007 + + IL_0028: ret + } // end of method OtherClass::remove_ThisIsAnAbstractEvent + + .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 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/BaseClass::.ctor() + IL_0006: ret + } // end of method OtherClass::.ctor + + .event [mscorlib]System.EventHandler ThisIsAnAbstractEvent + { + .addon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/OtherClass::add_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler) + .removeon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/OtherClass::remove_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler) + } // end of event OtherClass::ThisIsAnAbstractEvent + } // end of class OtherClass + .class auto ansi nested private beforefieldinit Impl extends [mscorlib]System.Object implements ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/IBase @@ -140,7 +264,7 @@ { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field public static initonly class ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/'<>c' '<>9' - .field public static class [mscorlib]System.EventHandler '<>9__18_0' + .field public static class [mscorlib]System.EventHandler '<>9__20_0' .method private hidebysig specialname rtspecialname static void .cctor() cil managed { @@ -162,13 +286,13 @@ } // end of method '<>c'::.ctor .method assembly hidebysig instance void - '<.ctor>b__18_0'(object '', + '<.ctor>b__20_0'(object '', class [mscorlib]System.EventArgs '') cil managed { // Code size 1 (0x1) .maxstack 8 IL_0000: ret - } // end of method '<>c'::'<.ctor>b__18_0' + } // end of method '<>c'::'<.ctor>b__20_0' } // end of class '<>c' @@ -380,18 +504,18 @@ // Code size 44 (0x2c) .maxstack 8 IL_0000: ldarg.0 - IL_0001: ldsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/'<>c'::'<>9__18_0' + IL_0001: ldsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/'<>c'::'<>9__20_0' IL_0006: dup IL_0007: brtrue.s IL_0020 IL_0009: pop IL_000a: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/'<>c'::'<>9' - IL_000f: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/'<>c'::'<.ctor>b__18_0'(object, + IL_000f: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/'<>c'::'<.ctor>b__20_0'(object, class [mscorlib]System.EventArgs) IL_0015: newobj instance void [mscorlib]System.EventHandler::.ctor(object, native int) IL_001a: dup - IL_001b: stsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/'<>c'::'<>9__18_0' + IL_001b: stsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/'<>c'::'<>9__20_0' IL_0020: stfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents::AutomaticEventWithInitializer IL_0025: ldarg.0 IL_0026: call instance void [mscorlib]System.Object::.ctor() diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.roslyn.il b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.roslyn.il index d63dc5872..65da47082 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.roslyn.il +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PropertiesAndEvents.roslyn.il @@ -72,6 +72,133 @@ } // end of property IBase::Test } // end of class IBase + .class abstract auto ansi nested private beforefieldinit BaseClass + extends [mscorlib]System.Object + { + .method public hidebysig newslot specialname abstract virtual + instance void add_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler 'value') cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + } // end of method BaseClass::add_ThisIsAnAbstractEvent + + .method public hidebysig newslot specialname abstract virtual + instance void remove_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler 'value') cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + } // end of method BaseClass::remove_ThisIsAnAbstractEvent + + .method family 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 BaseClass::.ctor + + .event [mscorlib]System.EventHandler ThisIsAnAbstractEvent + { + .addon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/BaseClass::add_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler) + .removeon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/BaseClass::remove_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler) + } // end of event BaseClass::ThisIsAnAbstractEvent + } // end of class BaseClass + + .class auto ansi nested private beforefieldinit OtherClass + extends ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/BaseClass + { + .field private class [mscorlib]System.EventHandler ThisIsAnAbstractEvent + .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 public hidebysig specialname virtual + instance void add_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler 'value') cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 41 (0x29) + .maxstack 3 + .locals init (class [mscorlib]System.EventHandler V_0, + class [mscorlib]System.EventHandler V_1, + class [mscorlib]System.EventHandler V_2) + IL_0000: ldarg.0 + IL_0001: ldfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/OtherClass::ThisIsAnAbstractEvent + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: stloc.1 + IL_0009: ldloc.1 + IL_000a: ldarg.1 + IL_000b: call class [mscorlib]System.Delegate [mscorlib]System.Delegate::Combine(class [mscorlib]System.Delegate, + class [mscorlib]System.Delegate) + IL_0010: castclass [mscorlib]System.EventHandler + IL_0015: stloc.2 + IL_0016: ldarg.0 + IL_0017: ldflda class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/OtherClass::ThisIsAnAbstractEvent + IL_001c: ldloc.2 + IL_001d: ldloc.1 + IL_001e: call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange(!!0&, + !!0, + !!0) + IL_0023: stloc.0 + IL_0024: ldloc.0 + IL_0025: ldloc.1 + IL_0026: bne.un.s IL_0007 + + IL_0028: ret + } // end of method OtherClass::add_ThisIsAnAbstractEvent + + .method public hidebysig specialname virtual + instance void remove_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler 'value') cil managed + { + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + // Code size 41 (0x29) + .maxstack 3 + .locals init (class [mscorlib]System.EventHandler V_0, + class [mscorlib]System.EventHandler V_1, + class [mscorlib]System.EventHandler V_2) + IL_0000: ldarg.0 + IL_0001: ldfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/OtherClass::ThisIsAnAbstractEvent + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: stloc.1 + IL_0009: ldloc.1 + IL_000a: ldarg.1 + IL_000b: call class [mscorlib]System.Delegate [mscorlib]System.Delegate::Remove(class [mscorlib]System.Delegate, + class [mscorlib]System.Delegate) + IL_0010: castclass [mscorlib]System.EventHandler + IL_0015: stloc.2 + IL_0016: ldarg.0 + IL_0017: ldflda class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/OtherClass::ThisIsAnAbstractEvent + IL_001c: ldloc.2 + IL_001d: ldloc.1 + IL_001e: call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange(!!0&, + !!0, + !!0) + IL_0023: stloc.0 + IL_0024: ldloc.0 + IL_0025: ldloc.1 + IL_0026: bne.un.s IL_0007 + + IL_0028: ret + } // end of method OtherClass::remove_ThisIsAnAbstractEvent + + .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 ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/BaseClass::.ctor() + IL_0006: nop + IL_0007: ret + } // end of method OtherClass::.ctor + + .event [mscorlib]System.EventHandler ThisIsAnAbstractEvent + { + .addon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/OtherClass::add_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler) + .removeon instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/OtherClass::remove_ThisIsAnAbstractEvent(class [mscorlib]System.EventHandler) + } // end of event OtherClass::ThisIsAnAbstractEvent + } // end of class OtherClass + .class auto ansi nested private beforefieldinit Impl extends [mscorlib]System.Object implements ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/IBase @@ -145,7 +272,7 @@ { .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .field public static initonly class ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/'<>c' '<>9' - .field public static class [mscorlib]System.EventHandler '<>9__18_0' + .field public static class [mscorlib]System.EventHandler '<>9__20_0' .method private hidebysig specialname rtspecialname static void .cctor() cil managed { @@ -168,14 +295,14 @@ } // end of method '<>c'::.ctor .method assembly hidebysig instance void - '<.ctor>b__18_0'(object '', + '<.ctor>b__20_0'(object '', class [mscorlib]System.EventArgs '') cil managed { // Code size 2 (0x2) .maxstack 8 IL_0000: nop IL_0001: ret - } // end of method '<>c'::'<.ctor>b__18_0' + } // end of method '<>c'::'<.ctor>b__20_0' } // end of class '<>c' @@ -394,18 +521,18 @@ // Code size 45 (0x2d) .maxstack 8 IL_0000: ldarg.0 - IL_0001: ldsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/'<>c'::'<>9__18_0' + IL_0001: ldsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/'<>c'::'<>9__20_0' IL_0006: dup IL_0007: brtrue.s IL_0020 IL_0009: pop IL_000a: ldsfld class ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/'<>c' ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/'<>c'::'<>9' - IL_000f: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/'<>c'::'<.ctor>b__18_0'(object, + IL_000f: ldftn instance void ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/'<>c'::'<.ctor>b__20_0'(object, class [mscorlib]System.EventArgs) IL_0015: newobj instance void [mscorlib]System.EventHandler::.ctor(object, native int) IL_001a: dup - IL_001b: stsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/'<>c'::'<>9__18_0' + IL_001b: stsfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents/'<>c'::'<>9__20_0' IL_0020: stfld class [mscorlib]System.EventHandler ICSharpCode.Decompiler.Tests.TestCases.Pretty.PropertiesAndEvents::AutomaticEventWithInitializer IL_0025: ldarg.0 IL_0026: call instance void [mscorlib]System.Object::.ctor() diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs b/ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs index f4c0c61d9..e6a74555c 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs @@ -601,16 +601,19 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms } #region Automatic Events + static readonly Expression fieldReferencePattern = new Choice { + new IdentifierExpression(Pattern.AnyString), + new MemberReferenceExpression { + Target = new Choice { new ThisReferenceExpression(), new TypeReferenceExpression { Type = new AnyNode() } }, + MemberName = Pattern.AnyString + } + }; + static readonly Accessor automaticEventPatternV2 = new Accessor { Attributes = { new Repeat(new AnyNode()) }, Body = new BlockStatement { new AssignmentExpression { - Left = new NamedNode( - "field", - new MemberReferenceExpression { - Target = new Choice { new ThisReferenceExpression(), new TypeReferenceExpression { Type = new AnyNode() } }, - MemberName = Pattern.AnyString - }), + Left = new NamedNode("field", fieldReferencePattern), Operator = AssignmentOperatorType.Assign, Right = new CastExpression( new AnyNode("type"), @@ -626,12 +629,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms new AssignmentExpression { Left = new NamedNode("var1", new IdentifierExpression(Pattern.AnyString)), Operator = AssignmentOperatorType.Assign, - Right = new NamedNode( - "field", - new MemberReferenceExpression { - Target = new Choice { new ThisReferenceExpression(), new TypeReferenceExpression { Type = new AnyNode() } }, - MemberName = Pattern.AnyString - }) + Right = new NamedNode("field", fieldReferencePattern) }, new DoWhileStatement { EmbeddedStatement = new BlockStatement { @@ -704,7 +702,9 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms { if (!m.Success) return false; - if (m.Get("field").Single().MemberName != ev.Name) + Expression fieldExpression = m.Get("field").Single(); + if (fieldExpression is IdentifierExpression identifier && identifier.Identifier != ev.Name + && fieldExpression is MemberReferenceExpression memberRef && memberRef.MemberName != ev.Name) return false; // field name must match event name if (!ev.ReturnType.IsMatch(m.Get("type").Single())) return false; // variable types must match event type @@ -763,9 +763,11 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms EventDeclaration TransformAutomaticEvents(CustomEventDeclaration ev) { - Match m1, m2; - if (!CheckAutomaticEventV4(ev, out m1, out m2) && !CheckAutomaticEventV2(ev, out m1, out m2) && !CheckAutomaticEventV4MCS(ev, out m1, out m2)) - return null; + if (!ev.Modifiers.HasFlag(Modifiers.Abstract)) { + Match m1, m2; + if (!CheckAutomaticEventV4(ev, out m1, out m2) && !CheckAutomaticEventV2(ev, out m1, out m2) && !CheckAutomaticEventV4MCS(ev, out m1, out m2)) + return null; + } RemoveCompilerGeneratedAttribute(ev.AddAccessor.Attributes, attributeTypesToRemoveFromAutoEvents); EventDeclaration ed = new EventDeclaration(); ev.Attributes.MoveTo(ed.Attributes);