2020-06-30 12:48:07 +02:00
|
|
|
include::../description.adoc[]
|
|
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
|
|
|
|
----
|
|
|
|
public class Person
|
|
|
|
{
|
|
|
|
private int _birthYear; // Noncompliant
|
|
|
|
|
|
|
|
Person(int birthYear)
|
|
|
|
{
|
|
|
|
_birthYear = birthYear;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
|
|
|
|
----
|
|
|
|
public class Person
|
|
|
|
{
|
|
|
|
private readonly int _birthYear;
|
|
|
|
|
|
|
|
Person(int birthYear)
|
|
|
|
{
|
|
|
|
_birthYear = birthYear;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
== Exceptions
|
|
|
|
|
2020-06-30 14:49:38 +02:00
|
|
|
* Fields with attributes are ignored.
|
2021-01-27 13:42:22 +01:00
|
|
|
* Fields of type ``++struct++`` that are not primitive or pointer types are also ignored because of possible unwanted behavior.
|
2020-06-30 12:48:07 +02:00
|
|
|
|
|
|
|
== See
|
|
|
|
|
2020-06-30 14:49:38 +02:00
|
|
|
* https://ericlippert.com/2008/05/14/mutating-readonly-structs/[Mutating readonly structs]
|
2021-06-02 20:44:38 +02:00
|
|
|
|
|
|
|
ifdef::rspecator-view[]
|
|
|
|
== Comments And Links
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::../comments-and-links.adoc[]
|
|
|
|
endif::rspecator-view[]
|