diff --git a/analyzers/rspec/cs/S1144.html b/analyzers/rspec/cs/S1144.html index 9284f1debd9..206e9a052a7 100644 --- a/analyzers/rspec/cs/S1144.html +++ b/analyzers/rspec/cs/S1144.html @@ -3,6 +3,23 @@
A type or member that is never called is dead code, and should be removed. Cleaning out dead code decreases the size of the maintained codebase, making it easier to understand the program and preventing bugs from being introduced.
This rule detects type or members that are never referenced from inside a translation unit, and cannot be referenced from the outside.
+This rule doesn’t raise issues on:
+Main
method of the application void
methods with two parameters when the second parameter type derives from EventArgs DynamicallyAccessedMembersAttribute
. @@ -30,22 +47,6 @@-Compliant solution
private class UsedClass {...} }
This rule doesn’t raise issues on:
-Main
method of the application void Foo(object, EventArgs)
that are declared in partial class DynamicallyAccessedMembersAttribute
. FluentAssertions
(4.x and 5.x) NFluent
NSubstitute
Moq
Shoudly
By enforcing the presence of assertions, this rule aims to enhance the reliability and comprehensiveness of tests by ensuring that they provide @@ -26,7 +27,8 @@
Test methods that include a call to a custom assertion method will not raise any issues.
To address this issue, you should include assertions to validate the expected behavior. Choose an appropriate assertion method provided by your -testing framework (such as MSTest, NUnit, xUnit) or select a suitable assertion library like FluentAssertions, NFluent, NSubstitute, or Shouldly.
+testing framework (such as MSTest, NUnit, xUnit) or select a suitable assertion library like FluentAssertions, NFluent, NSubstitute, Moq, or +Shouldly.In addition to using built-in assertion methods, you also have the option to create custom assertion methods. To do this, declare an attribute
named [AssertionMethodAttribute]
and apply it to the respective method. This allows you to encapsulate specific validation logic within
your custom assertion methods without raising the issue. Here’s an example:
Because the is
operator performs a cast if the object is not null, using is
to check type and then casting the same
-argument to that type, necessarily performs two casts. The same result can be achieved more efficiently with a single cast using as
,
-followed by a null-check.
+In C#, the
+is
+type testing operator can be used to check if the run-time type of an object is compatible with a given type. If the object is not null, then the +is
operator performs a cast, and so performing another cast following the check result is redundant.This can impact:
+
Use pattern macthing to perform the check +and retrieve the cast result.
+if (x is Fruit) // Noncompliant { var f = (Fruit)x; // or x as Fruit // ... }-
-// C# 6 -var f = x as Fruit; -if (f != null) -{ - // ... -} -// C# 7 +Compliant solution
+if (x is Fruit fruit) { // ... }+Resources
+Documentation
+
is
, as
, typeof
and casts