Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 { }
}
}
");
}
}