-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modify S3247: Improve description and update example #4019
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - minor polishing
rules/S3247/csharp/rule.adoc
Outdated
@@ -1,11 +1,21 @@ | |||
== Why is this an issue? | |||
|
|||
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 https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/type-testing-and-cast#is-operator[`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 check is successful, it means the code performed a cast. Performing another cast following the check result into a duplicate cast. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In C#, the https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/type-testing-and-cast#is-operator[`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 check is successful, it means the code performed a cast. Performing another cast following the check result into a duplicate cast. | |
In C#, the https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/type-testing-and-cast#is-operator[`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. |
rules/S3247/rspecator.adoc
Outdated
|
||
=== Message | ||
|
||
Primary: Replace this type-check-and-cast sequence with an "as" and a null check. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Primary: Replace this type-check-and-cast sequence with an "as" and a null check. | |
Primary: "Replace this type-check-and-cast sequence to use pattern matching." |
|
|
RSPEC update for SonarSource/sonar-dotnet#2120