Skip to content

Commit 2a2e623

Browse files
committed
WPF0041 don't warn when private
Fix #376
1 parent e349484 commit 2a2e623

3 files changed

Lines changed: 57 additions & 1 deletion

File tree

ValidCode/Issues/Issue376.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace ValidCode.Issues;
2+
3+
using System.Windows;
4+
5+
public class Issue376 : FrameworkElement
6+
{
7+
private static readonly DependencyProperty TextProperty = DependencyProperty.Register(
8+
nameof(Text),
9+
typeof(string),
10+
typeof(Issue376),
11+
new PropertyMetadata(default(string)));
12+
13+
private string? Text
14+
{
15+
get => (string?)this.GetValue(TextProperty);
16+
set => this.SetValue(TextProperty, value);
17+
}
18+
19+
public void M(string text)
20+
{
21+
this.Text = text;
22+
}
23+
}

WpfAnalyzers.Test/WPF0041SetMutableUsingSetCurrentValueTests/Valid.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,4 +776,36 @@ public bool IsTrue
776776

777777
RoslynAssert.Valid(Analyzer, boxes, code);
778778
}
779+
780+
[Test]
781+
public static void WhenPrivate()
782+
{
783+
var code = @"
784+
namespace ValidCode.Issues;
785+
786+
using System.Windows;
787+
788+
public class Issue376 : FrameworkElement
789+
{
790+
private static readonly DependencyProperty TextProperty = DependencyProperty.Register(
791+
nameof(Text),
792+
typeof(string),
793+
typeof(Issue376),
794+
new PropertyMetadata(default(string)));
795+
796+
private string? Text
797+
{
798+
get => (string?)this.GetValue(TextProperty);
799+
set => this.SetValue(TextProperty, value);
800+
}
801+
802+
public void M(string text)
803+
{
804+
this.Text = text;
805+
}
806+
}
807+
";
808+
809+
RoslynAssert.Valid(Analyzer, code);
810+
}
779811
}

WpfAnalyzers/WPF0041SetMutableUsingSetCurrentValue.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ private static void HandleAssignment(SyntaxNodeAnalysisContext context)
4949
static bool IsIgnored(IPropertySymbol property)
5050
{
5151
return property == KnownSymbols.FrameworkElement.DataContext ||
52-
property == KnownSymbols.FrameworkElement.Style;
52+
property == KnownSymbols.FrameworkElement.Style ||
53+
property.DeclaredAccessibility == Accessibility.Private;
5354
}
5455
}
5556

0 commit comments

Comments
 (0)