Skip to content

Commit

Permalink
Exclude events for MA0147
Browse files Browse the repository at this point in the history
  • Loading branch information
meziantou committed Jan 13, 2024
1 parent 2807d2e commit 1ddf530
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public override void Initialize(AnalysisContext context)
private static void AnalyzerDelegateCreationOperation(OperationAnalysisContext context)
{
var operation = (IDelegateCreationOperation)context.Operation;
if (operation.Parent is IEventAssignmentOperation)
return;

if (operation.Type is INamedTypeSymbol { DelegateInvokeMethod: IMethodSymbol delegateInvokeMethod })
{
if (!delegateInvokeMethod.ReturnsVoid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,20 @@ await CreateProjectBuilder()
""")
.ValidateAsync();
}

[Fact]
public async Task Event_AsyncVoid()
{
await CreateProjectBuilder()
.WithSourceCode("""
Sample.A += async (sender, e) => { };
Sample.A -= async (sender, e) => { };
class Sample
{
public static event System.EventHandler A;
}
""")
.ValidateAsync();
}
}

0 comments on commit 1ddf530

Please sign in to comment.