S2094 — Classes should not be empty

Language
C#
Type
Code smell
Severity
Minor
Tags
clumsy

Why is this an issue?

There is no good excuse for an empty class. If it’s being used simply as a common extension point, it should be replaced with an interface. If it was stubbed in as a placeholder for future development it should be fleshed-out. In any other case, it should be eliminated.

Noncompliant code example


public class Empty // Noncompliant
{
}

Compliant solution


public interface IEmpty
{
}

Exceptions


using Microsoft.AspNetCore.Mvc.RazorPages;

public class EmptyPageModel: PageModel // Compliant - an empty PageModel can be fully functional, the C# code can be in the cshtml file
{
}

↑ Back to top