
org.sonar.l10n.csharp.rules.csharpsquid.S1186.html Maven / Gradle / Ivy
There are four reasons for a method not to have a method body:
- It is an unintentional omission, and should be fixed.
- It is not yet, or never will be, supported. In this case an
NotSupportedException
should be thrown.
- The method is an intentionally-blank override. In this case a nested comment should explain the reason for the blank override.
Noncompliant Code Example
public override void DoSomething()
{
}
public override void doSomethingElse()
{
}
Compliant Solution
public override void DoSomething()
{
// Do nothing because of X and Y.
}
public override void doSomethingElse() {
throw new NotSupportedException();
}
Exceptions
An abstract class' may have empty methods, in order to provide default implementations for child classes.
abstract class Animal {
public void speak() {
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy