rspec/rules/S2933/csharp/rule.adoc

46 lines
800 B
Plaintext
Raw Normal View History

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
* 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
* https://ericlippert.com/2008/05/14/mutating-readonly-structs/[Mutating readonly structs]
ifdef::rspecator-view[]
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::rspecator-view[]