rspec/rules/S3877/csharp/rule.adoc

43 lines
1.1 KiB
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
It is expected that some methods should be called with caution, but others, such as ``++ToString++``, are expected to "just work". Throwing an exception from such a method is likely to break callers' code unexpectedly.
An issue is raised when an exception is thrown from any of the following:
* Event accessors
* ``++Object.Equals++``
* ``++IEquatable.Equals++``
* ``++GetHashCode++``
* ``++ToString++``
* ``++static++`` constructors
* ``++IDisposable.Dispose++``
* ``++operator ==, !=, <, >, <=, >=++``
* ``++implicit++`` cast operators
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
public override string ToString()
{
if (string.IsNullOrEmpty(Name))
{
throw new ArgumentException("..."); // Noncompliant
}
//...
----
2021-04-28 16:49:39 +02:00
== Exceptions
``++System.NotImplementedException++`` and its derivatives are ignored.
``++System.InvalidOperationException++``, ``++System.NotSupportedException++``, and ``++System.ArgumentException++`` and their derivatives are ignored in event accessors.
ifdef::rspecator-view[]
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::rspecator-view[]