From c92174e6c9bcce414ab395de4169a36aad8f653d Mon Sep 17 00:00:00 2001 From: Josef Pihrt Date: Sun, 9 Apr 2023 09:58:53 +0200 Subject: [PATCH] Handle DependencyPropertyChangedEventArgs (RCS1163) (#1068) --- ChangeLog.md | 2 +- src/Core/MetadataNames.cs | 1 + src/Core/SymbolUtility.cs | 3 +- .../RCS1163UnusedParameterTests.cs | 33 +++++++++++++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index ed6c4c1a51..c187b27a9d 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -31,7 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [CLI] Analyze command does not create the XML output file and returns incorrect exit code when only compiler diagnostics are reported ([#1056](https://github.com/JosefPihrt/Roslynator/pull/1056) by @PeterKaszab). - [CLI] Fix exit code when multiple projects are processed ([#1061](https://github.com/JosefPihrt/Roslynator/pull/1061) by @PeterKaszab). - Fix code fix for CS0164 ([#1031](https://github.com/JosefPihrt/Roslynator/pull/1031)). - +- Do not report `System.Windows.DependencyPropertyChangedEventArgs` as unused parameter ([RCS1163](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1163.md)) ([#1068](https://github.com/JosefPihrt/Roslynator/pull/1068)). ## [4.2.0] - 2022-11-27 diff --git a/src/Core/MetadataNames.cs b/src/Core/MetadataNames.cs index 87af341efa..d5d49a311b 100644 --- a/src/Core/MetadataNames.cs +++ b/src/Core/MetadataNames.cs @@ -66,6 +66,7 @@ internal static class MetadataNames public static readonly MetadataName System_Threading_Tasks_ValueTask_T = MetadataName.Parse("System.Threading.Tasks.ValueTask`1"); public static readonly MetadataName System_TimeSpan = MetadataName.Parse("System.TimeSpan"); public static readonly MetadataName System_ValueType = MetadataName.Parse("System.ValueType"); + public static readonly MetadataName System_Windows_DependencyPropertyChangedEventArgs = MetadataName.Parse("System.Windows.DependencyPropertyChangedEventArgs"); public static class WinRT { diff --git a/src/Core/SymbolUtility.cs b/src/Core/SymbolUtility.cs index 5aab127a95..ffb097f0d2 100644 --- a/src/Core/SymbolUtility.cs +++ b/src/Core/SymbolUtility.cs @@ -82,7 +82,8 @@ public static bool IsEventHandlerMethod(IMethodSymbol methodSymbol) if (type.Kind == SymbolKind.TypeParameter) return type.Name.EndsWith("EventArgs", StringComparison.Ordinal); - return type.EqualsOrInheritsFrom(MetadataNames.System_EventArgs); + return type.EqualsOrInheritsFrom(MetadataNames.System_EventArgs) + || type.HasMetadataName(MetadataNames.System_Windows_DependencyPropertyChangedEventArgs); } } diff --git a/src/Tests/Analyzers.Tests/RCS1163UnusedParameterTests.cs b/src/Tests/Analyzers.Tests/RCS1163UnusedParameterTests.cs index 3142e46f53..2869c7a851 100644 --- a/src/Tests/Analyzers.Tests/RCS1163UnusedParameterTests.cs +++ b/src/Tests/Analyzers.Tests/RCS1163UnusedParameterTests.cs @@ -204,4 +204,37 @@ public static int GetCount(__arglist) } "); } + + [Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UnusedParameter)] + public async Task TestNoDiagnostic_DependencyPropertyEventArgs() + { + await VerifyNoDiagnosticAsync(@" +using System; +using System.Windows; + +static class C +{ + public static void M(this Foo foo) + { + foo.Changed += Foo_Changed; + + void Foo_Changed(object sender, DependencyPropertyChangedEventArgs e) + { + } + } +} + +public class Foo +{ + public event EventHandler Changed; +} + +namespace System.Windows +{ + public class DependencyPropertyChangedEventArgs + { + } +} + "); + } }