Skip to content

Commit 0454bbf

Browse files
committed
DeclaredAccessibility
1 parent 2a2e623 commit 0454bbf

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

WpfAnalyzers/Helpers/BackingFieldOrProperty.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace WpfAnalyzers;
22

3+
using System;
34
using System.Diagnostics;
45
using System.Diagnostics.CodeAnalysis;
56
using System.Linq;
@@ -27,6 +28,13 @@ private BackingFieldOrProperty(FieldOrProperty fieldOrProperty)
2728

2829
internal INamedTypeSymbol ContainingType => this.FieldOrProperty.ContainingType;
2930

31+
internal Accessibility DeclaredAccessibility => this.FieldOrProperty.Symbol switch
32+
{
33+
IFieldSymbol field => field.DeclaredAccessibility,
34+
IPropertySymbol property => property.DeclaredAccessibility,
35+
_ => throw new NotSupportedException("Neither field nor property."),
36+
};
37+
3038
internal string Name => this.FieldOrProperty.Name;
3139

3240
internal static BackingFieldOrProperty? Match(ISymbol? symbol)
@@ -167,7 +175,7 @@ IPropertySymbol property
167175
if (this.Value(cancellationToken) is { } value &&
168176
value is InvocationExpressionSyntax { Expression: MemberAccessExpressionSyntax { Expression: { } addOwner } } invocation &&
169177
semanticModel.TryGetSymbol(invocation, KnownSymbols.DependencyProperty.AddOwner, cancellationToken, out _) &&
170-
semanticModel.TryGetSymbol(addOwner, cancellationToken, out var addOwnerSymbol))
178+
semanticModel.TryGetSymbol(addOwner, cancellationToken, out var addOwnerSymbol))
171179
{
172180
return Match(addOwnerSymbol);
173181
}

WpfAnalyzers/WPF0041SetMutableUsingSetCurrentValue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ private static void HandleAssignment(SyntaxNodeAnalysisContext context)
3232
!IsInConstructor(assignment) &&
3333
context.SemanticModel.TryGetSymbol(left, context.CancellationToken, out IPropertySymbol? property) &&
3434
!IsIgnored(property) &&
35-
ClrProperty.Match(property, context.SemanticModel, context.CancellationToken) is { BackingSet: { } backingSet } &&
35+
ClrProperty.Match(property, context.SemanticModel, context.CancellationToken) is { BackingSet: { DeclaredAccessibility: not Accessibility.Private } backingSet } &&
3636
backingSet.FieldOrProperty.Type == KnownSymbols.DependencyProperty &&
3737
!IsAssignedCreatedInScope(left, context.SemanticModel, context.CancellationToken))
3838
{

0 commit comments

Comments
 (0)