Skip to content

Commit

Permalink
Handle DependencyPropertyChangedEventArgs (RCS1163) (#1068)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt authored Apr 9, 2023
1 parent 78e385f commit c92174e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/Core/MetadataNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion src/Core/SymbolUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
33 changes: 33 additions & 0 deletions src/Tests/Analyzers.Tests/RCS1163UnusedParameterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DependencyPropertyChangedEventArgs> Changed;
}
namespace System.Windows
{
public class DependencyPropertyChangedEventArgs
{
}
}
");
}
}

0 comments on commit c92174e

Please sign in to comment.