rspec/rules/S3253/csharp/rule.adoc

63 lines
1.1 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
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
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,csharp]
2021-04-28 16:49:39 +02:00
----
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
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,csharp]
2021-04-28 16:49:39 +02:00
----
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)
include::message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]