rspec/rules/S2094/csharp/rule.adoc
Zsolt Kolbay d68bafc932
Improve S2094: Add exceptions (#1575)
* Update VB description

* Add Exceptions section
2023-02-27 19:02:57 +01:00

50 lines
1.2 KiB
Plaintext

include::../description.adoc[]
== Noncompliant Code Example
[source,csharp]
----
public class Empty // Noncompliant
{
}
----
== Compliant Solution
[source,csharp]
----
public interface IEmpty
{
}
----
== Exceptions
Partial classes are ignored entirely, as they are often used with Source Generators.
Subclasses of System.Exception are ignored, as even an empty Exception class can provide useful information by its type name alone.
Subclasses of System.Attribute are ignored, as well as classes which are annotated with attributes.
Subclasses of generic classes are ignored, as even when empty they can be used for type specialization.
Subclasses of certain framework types - like the PageModel class used in ASP.NET Core Razor Pages - are also ignored.
----
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
{
}
----
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[]