@@ -761,7 +761,7 @@ Identifier ReplaceEventFieldAnnotation(Identifier identifier)
761761 var parent = identifier . Parent ;
762762 var mrr = parent . Annotation < MemberResolveResult > ( ) ;
763763 var field = mrr ? . Member as IField ;
764- if ( field == null )
764+ if ( field == null || field . Accessibility != Accessibility . Private )
765765 return null ;
766766 foreach ( var ev in field . DeclaringType . GetEvents ( null , GetMemberOptions . IgnoreInheritedMembers ) )
767767 {
@@ -999,7 +999,9 @@ EventDeclaration TransformAutomaticEvents(CustomEventDeclaration ev)
999999 if ( ! ev . PrivateImplementationType . IsNull )
10001000 return null ;
10011001 const Modifiers withoutBody = Modifiers . Abstract | Modifiers . Extern ;
1002- if ( ( ev . Modifiers & withoutBody ) == 0 && ev . GetSymbol ( ) is IEvent symbol )
1002+ if ( ev . GetSymbol ( ) is not IEvent symbol )
1003+ return null ;
1004+ if ( ( ev . Modifiers & withoutBody ) == 0 )
10031005 {
10041006 if ( ! CheckAutomaticEventV4AggressivelyInlined ( ev ) && ! CheckAutomaticEventV4 ( ev ) && ! CheckAutomaticEventV2 ( ev ) && ! CheckAutomaticEventV4MCS ( ev ) )
10051007 return null ;
@@ -1018,7 +1020,7 @@ EventDeclaration TransformAutomaticEvents(CustomEventDeclaration ev)
10181020 ed . CopyAnnotationsFrom ( ev ) ;
10191021
10201022 var fieldDecl = ev . Parent ? . Children . OfType < FieldDeclaration > ( )
1021- . FirstOrDefault ( fd => CSharpDecompiler . IsEventBackingFieldName ( fd . Variables . Single ( ) . Name , ev . Name , out _ ) ) ;
1023+ . FirstOrDefault ( IsEventBackingField ) ;
10221024 if ( fieldDecl != null )
10231025 {
10241026 fieldDecl . Remove ( ) ;
@@ -1033,6 +1035,17 @@ EventDeclaration TransformAutomaticEvents(CustomEventDeclaration ev)
10331035
10341036 ev . ReplaceWith ( ed ) ;
10351037 return ed ;
1038+
1039+ bool IsEventBackingField ( FieldDeclaration fd )
1040+ {
1041+ if ( fd . Variables . Count > 1 )
1042+ return false ;
1043+ if ( fd . GetSymbol ( ) is not IField f )
1044+ return false ;
1045+ return f . Accessibility == Accessibility . Private
1046+ && symbol . ReturnType . Equals ( f . ReturnType )
1047+ && CSharpDecompiler . IsEventBackingFieldName ( f . Name , ev . Name , out _ ) ;
1048+ }
10361049 }
10371050 #endregion
10381051
0 commit comments