Skip to content

Commit

Permalink
Do not suggest to use generic event handler (RCS1159) (#1022)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt authored Dec 30, 2022
1 parent b88ad90 commit 5180806
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add/remove blank line after file scoped namespace declaration ([RCS0060](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS0060.md)) ([#1014](https://github.com/josefpihrt/roslynator/pull/1014)).
- Do not remove overriding member in record ([RCS1132](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1132.md)) ([#1015](https://github.com/josefpihrt/roslynator/pull/1015)).
- Do not remove parameterless empty constructor in a struct with field initializers ([RCS1074](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1074.md)) ([#1020](https://github.com/josefpihrt/roslynator/pull/1020)).
- Do not suggest to use generic event handler ([RCS1159](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1159.md)) ([#1019](https://github.com/josefpihrt/roslynator/pull/1019)).

## [4.2.0] - 2022-11-27

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ private static void AnalyzeEvent(SymbolAnalysisContext context)
if (!parameters[0].Type.IsObject())
return;

if (parameters[1].Type.IsRefLikeType)
return;

if (eventSymbol.ImplementsInterfaceMember<IEventSymbol>(allInterfaces: true))
return;

Expand Down
17 changes: 17 additions & 0 deletions src/Tests/Analyzers.Tests/RCS1159UseGenericEventHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,23 @@ void M()
class FooEventArgs
{
}
");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UseGenericEventHandler)]
public async Task TestNoDiagnostic_EventArgsIsRefStruct()
{
await VerifyNoDiagnosticAsync(@"
public delegate void CustomEventHandler(object sender, RefStructEventArgs e);
public readonly ref struct RefStructEventArgs
{
}
public interface IEventTest
{
event CustomEventHandler CustomEvent;
}
");
}
}

0 comments on commit 5180806

Please sign in to comment.