rspec/rules/S2933/csharp/rule.adoc

58 lines
987 B
Plaintext

== Why is this an issue?
include::../description.adoc[]
=== Noncompliant code example
[source,csharp]
----
public class Person
{
private int _birthYear; // Noncompliant
Person(int birthYear)
{
_birthYear = birthYear;
}
}
----
=== Compliant solution
[source,csharp]
----
public class Person
{
private readonly int _birthYear;
Person(int birthYear)
{
_birthYear = birthYear;
}
}
----
=== Exceptions
* Fields with attributes are ignored.
* Fields of type ``++struct++`` that are not primitive or pointer types are also ignored because of possible unwanted behavior.
== Resources
* https://ericlippert.com/2008/05/14/mutating-readonly-structs/[Mutating readonly structs]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]