Skip to content

Commit

Permalink
Fix RCS1159 (#1390)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt authored Feb 8, 2024
1 parent 83a2d7c commit 2af15db
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Fix analyzer [RCS0049](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS0049) ([PR](https://github.com/dotnet/roslynator/pull/1386))
- Fix analyzer [RCS1159](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1159) ([PR](https://github.com/dotnet/roslynator/pull/1390))

## [4.10.0] - 2024-01-24

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace Roslynator.CSharp.Analysis;
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public sealed class UseGenericEventHandlerAnalyzer : BaseDiagnosticAnalyzer
{
private static readonly MetadataName System_Windows_RoutedEventHandler = MetadataName.Parse("System.Windows.RoutedEventHandler");

private static ImmutableArray<DiagnosticDescriptor> _supportedDiagnostics;

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
Expand Down Expand Up @@ -51,6 +53,9 @@ private static void AnalyzeEvent(SymbolAnalysisContext context)
if (namedType.HasMetadataName(MetadataNames.System_EventHandler))
return;

if (namedType.HasMetadataName(System_Windows_RoutedEventHandler))
return;

IMethodSymbol delegateInvokeMethod = namedType.DelegateInvokeMethod;

if (delegateInvokeMethod is null)
Expand Down
24 changes: 24 additions & 0 deletions src/Tests/Analyzers.Tests/RCS1159UseGenericEventHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,30 @@ public interface IEventTest
{
event CustomEventHandler CustomEvent;
}
");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UseGenericEventHandler)]
public async Task TestNoDiagnostic_Wpf_RoutedEventHandler()
{
await VerifyNoDiagnosticAsync(@"
using System.Windows;
namespace System.Windows
{
public delegate void RoutedEventHandler(object sender, RoutedEventArgs e);
public class RoutedEventArgs : EventArgs;
}
class C
{
public event RoutedEventHandler Foo
{
add { }
remove { }
}
}
");
}
}

0 comments on commit 2af15db

Please sign in to comment.