2020-06-30 12:48:07 +02:00
|
|
|
include::../description.adoc[]
|
|
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
|
|
|
|
----
|
|
|
|
public class Foo
|
|
|
|
{
|
|
|
|
public int MagicNumber = 42;
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
|
|
|
|
----
|
|
|
|
public class Foo
|
|
|
|
{
|
|
|
|
public int MagicNumber
|
|
|
|
{
|
|
|
|
get { return 42; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
----
|
|
|
|
or
|
2020-06-30 14:49:38 +02:00
|
|
|
|
2020-06-30 12:48:07 +02:00
|
|
|
----
|
|
|
|
public class Foo
|
|
|
|
{
|
|
|
|
private int MagicNumber = 42;
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
== Exceptions
|
|
|
|
|
2021-01-27 16:55:38 +01:00
|
|
|
``++struct++``s are ignored, as are ``++static++`` and ``++const++`` fields in classes.
|
2021-02-02 15:02:10 +01:00
|
|
|
|
2021-01-27 16:55:38 +01:00
|
|
|
Further, an issue is only raised when the real accessibility is ``++public++``, taking into account the class accessibility.
|