diff --git a/RefactoringEssentials/CSharp/Diagnostics/Synced/CodeQuality/DoNotCallOverridableMethodsInConstructorAnalyzer.cs b/RefactoringEssentials/CSharp/Diagnostics/Synced/CodeQuality/DoNotCallOverridableMethodsInConstructorAnalyzer.cs index 26b9c61c..cbd0a56d 100644 --- a/RefactoringEssentials/CSharp/Diagnostics/Synced/CodeQuality/DoNotCallOverridableMethodsInConstructorAnalyzer.cs +++ b/RefactoringEssentials/CSharp/Diagnostics/Synced/CodeQuality/DoNotCallOverridableMethodsInConstructorAnalyzer.cs @@ -90,7 +90,9 @@ void Check(SyntaxNode n, bool skipMethods) if (n.Ancestors().Any(a => a is AssignmentExpressionSyntax)) { var setterMethodSymbol = propertySymbol.SetMethod; - if ((setterMethodSymbol != null) && (setterMethodSymbol.DeclaredAccessibility == Accessibility.Private)) + if (setterMethodSymbol == null) + return; + if (setterMethodSymbol.DeclaredAccessibility == Accessibility.Private) return; } else diff --git a/Tests/CSharp/Diagnostics/DoNotCallOverridableMethodsInConstructorTests.cs b/Tests/CSharp/Diagnostics/DoNotCallOverridableMethodsInConstructorTests.cs index c65ebc1c..8543f45d 100644 --- a/Tests/CSharp/Diagnostics/DoNotCallOverridableMethodsInConstructorTests.cs +++ b/Tests/CSharp/Diagnostics/DoNotCallOverridableMethodsInConstructorTests.cs @@ -316,6 +316,20 @@ public Test () { } }"); } - + + [Fact] + public void DoNotWarnOnReadOnlyProperties() + { + Analyze(@" class Foo +{ + Foo() + { + AutoProperty = 42; + } + + public virtual int AutoProperty { get; } +"); + } + } }