Skip to content
Open
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
5 changes: 5 additions & 0 deletions src/Analyzers/CSharp/Analysis/UseAutoPropertyAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ private static void AnalyzePropertyDeclaration(SyntaxNodeAnalysisContext context
return;
}

#if ROSLYN_4_4
if (fieldSymbol.RefKind is RefKind.Ref or RefKind.RefReadOnly)
return;
#endif

if (!CheckPreprocessorDirectives(property))
return;

Expand Down
26 changes: 26 additions & 0 deletions src/Tests/Analyzers.Tests/RCS1085UseAutoPropertyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -981,4 +981,30 @@ private static void Write2(ref readonly ReadOnlySequence<byte> data, IBufferWrit
}
}");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UseAutoProperty)]
public async Task TestNoDiagnostic_BackingFieldRef()
{
await VerifyNoDiagnosticAsync(
@"
public ref struct Example(ref int value1, ref int value2)
{
private ref int _value1 = ref value1;
private readonly ref int _value2 = ref value2;

public int Value1
{
get => _value1;
set => _value1 = value;
}

public int Value2
{
get => _value2;
set => _value2 = value;
}
}
"
);
}
}
Loading