Skip to content

Latest commit

 

History

History
73 lines (56 loc) · 1.59 KB

SA1409.md

File metadata and controls

73 lines (56 loc) · 1.59 KB

SA1409

TypeName SA1409RemoveUnnecessaryCode
CheckId SA1409
Category Maintainability Rules

⚠️ This rule has been intentionally omitted from StyleCop Analyzers. See KnownChanges.md for additional information.

Cause

A C# file contains code which is unnecessary and can be removed without changing the overall logic of the code.

Rule description

A violation of this rule occurs when the file contains code which can be removed without changing the overall logic of the code.

For example, the following try-catch statement could be removed completely since the try and catch blocks are both empty.

try
{
}
catch (Exception ex)
{
}

The try-finally statement below does contain code within the try block, but it does not contain any catch blocks, and the finally block is empty. Thus, the try-finally is not performing any useful function and can be removed.

try
{
    this.Method();
}
finally
{
}

As a final example, the unsafe statement below is empty, and thus provides no value.

unsafe
{
}

How to fix violations

The fix a violation of this rule, remove the unnecessary code, or fill in the code with additional statements.

How to suppress violations

[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1409:RemoveUnnecessaryCode", Justification = "Reviewed.")]
#pragma warning disable SA1409 // RemoveUnnecessaryCode
#pragma warning restore SA1409 // RemoveUnnecessaryCode