Skip to content

Commit

Permalink
Ignore explicit implementations of properties
Browse files Browse the repository at this point in the history
This to cope with cases where a field and an explicit property have the same name.
  • Loading branch information
manfred-brands committed Dec 4, 2023
1 parent 8d28475 commit 9899714
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1013,5 +1013,43 @@ public void SomeTest()

RoslynAssert.Valid(analyzer, testCodePart1, testCodePart2);
}

[Test]
public void DoesNotThrowExceptionsWhenUsingExplicitProperties()
{
var testCode = TestUtility.WrapClassInNamespaceAndAddUsing(@"
[TestFixture]
public abstract class Test : IDataProvider
{
private DataReader DataReader;
DataReader IDataProvider.DataReader
{
get => DataReader;
set => DataReader = value;
}
protected Test() => DataReader = new DataReader(this);
[OneTimeSetUp]
public void SetListener() => throw new NotImplementedException();
}
public interface IDataProvider
{
DataReader DataReader
{
get;
set;
}
}
public sealed class DataReader
{
public DataReader(IDataProvider provider) => throw new NotImplementedException();
}");

RoslynAssert.Valid(analyzer, testCode);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ private static void AnalyzeDisposableFields(SyntaxNodeAnalysisContext context)

foreach (var property in propertyDeclarations)
{
if (property.ExplicitInterfaceSpecifier is not null)
continue;

if (property.Initializer is not null)
{
if (NeedsDisposal(model, property.Initializer.Value))
Expand Down

0 comments on commit 9899714

Please sign in to comment.