
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
77 lines
1.6 KiB
Plaintext
77 lines
1.6 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Since the compiler will automatically invoke the base type's no-argument constructor, there's no need to specify its invocation explicitly. Also, when only a single ``++public++`` parameterless constructor is defined in a class, then that constructor can be removed because the compiler would generate it automatically. Similarly, empty ``++static++`` constructors and empty destructors are also wasted keystrokes.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,csharp]
|
|
----
|
|
class X
|
|
{
|
|
public X() { } // Noncompliant
|
|
static X() { } // Noncompliant
|
|
~X() { } // Noncompliant
|
|
|
|
...
|
|
}
|
|
|
|
class Y : X
|
|
{
|
|
public Y(int parameter) : base() // Noncompliant
|
|
{
|
|
/* does something with the parameter */
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,csharp]
|
|
----
|
|
class X
|
|
{
|
|
...
|
|
}
|
|
|
|
class Y : X
|
|
{
|
|
public Y(int parameter)
|
|
{
|
|
/* does something with the parameter */
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
* Remove this redundant "base()" call.
|
|
* Remove this redundant [constructor|destructor].
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== supercedes: S3575
|
|
|
|
=== on 20 Jul 2015, 11:35:50 Tamas Vajk wrote:
|
|
\[~ann.campbell.2] I adjusted the description a bit.
|
|
|
|
=== on 20 Jul 2015, 14:12:01 Ann Campbell wrote:
|
|
looks good [~tamas.vajk]
|
|
|
|
=== on 20 May 2021, 10:24:19 Costin Zaharia wrote:
|
|
We might need to reconsider the recommendation for static constructors since even if empty they do change the generated IL and the runtime behavior. See: https://csharpindepth.com/articles/BeforeFieldInit[C# and beforefieldinit]
|
|
|
|
endif::env-github,rspecator-view[]
|