diff --git a/ChangeLog.md b/ChangeLog.md index 551a24ec22..472c375eb9 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -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 diff --git a/src/Analyzers/CSharp/Analysis/UseGenericEventHandlerAnalyzer.cs b/src/Analyzers/CSharp/Analysis/UseGenericEventHandlerAnalyzer.cs index 888315495d..3a67732256 100644 --- a/src/Analyzers/CSharp/Analysis/UseGenericEventHandlerAnalyzer.cs +++ b/src/Analyzers/CSharp/Analysis/UseGenericEventHandlerAnalyzer.cs @@ -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 _supportedDiagnostics; public override ImmutableArray SupportedDiagnostics @@ -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) diff --git a/src/Tests/Analyzers.Tests/RCS1159UseGenericEventHandlerTests.cs b/src/Tests/Analyzers.Tests/RCS1159UseGenericEventHandlerTests.cs index 0afb5a7076..6393be1b32 100644 --- a/src/Tests/Analyzers.Tests/RCS1159UseGenericEventHandlerTests.cs +++ b/src/Tests/Analyzers.Tests/RCS1159UseGenericEventHandlerTests.cs @@ -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 { } + } +} "); } }