View on GitHub

Arnolyzer

Clean-code Roslyn-based analyzer for C# 6

Arnolyzer on nuget

AA1101 - Class Properties Should Be Publicly Read-Only

Report code: AA1101-ClassPropertiesShouldBePubliclyReadOnly

Summary

Status Implemented
Description Public classes should not provide publicly accessible setters for properties
Category Encapsulation Analyzers
Enabled by default: Yes
Severity: Error

Cause

Class properties should not have public setters. Properties with public setters become mutable from any other point in the code that has access to the object instance, making it much harder to track changes to the object’s state.

How to fix violations

There currently aren’t any implemented code-fixes for this rule.

How to suppress violations

This rule can be suppressed using the following attributes:

[MutableProperty]
A public setter may sometimes be required. It is therefore allowed if decorated with the MutableProperty attribute as it explicitly asserts the need for the property to be mutable.