SonarSource / sonar-dotnet

Code analyzer for C# and VB.NET projects
https://redirect.sonarsource.com/plugins/csharp.html
GNU Lesser General Public License v3.0
781 stars 226 forks source link

Fix S3247 FN: When cast expression contains parentheses #9491

Closed sebastien-marichal closed 2 months ago

sebastien-marichal commented 3 months ago

9486 Introduce an FN when casting an object to access an inner property with parenthesis:

if (arg.Property is Fruit)                  // Compliant - FN
{
    _ = ((Fruit)(arg.Property)).Property;
}

if (arg.Property is Fruit)                  // Noncompliant
{
    _ = ((Fruit)arg.Property).Property;     // Secondary
}

When not using parenthesis, the rule raises as expected.