Show hint/warning for unused variables of using declarations like for using statements

Look at the following code snipped

public void Method ()
{
 using var someUsingDeclarationVariable = new SomeDisposable();

 using var _ = new SomeDisposable();

 using (var someUsingStatementVariable = new SomeDisposable())
 {
   using (var __ = new SomeDisposable())
   {
   }
 }
}

class SomeDisposable : IDisposable
{
 public void Dispose ()
 {
   // cleanup
 }
}

The variable someUsingDeclarationVariable is not recognized as unused. This could be true. There could be some kind of side effects of the using declaration that should happen at the end of the Method.
Though, as the variable is not directly used, it would be good to suggest, that it's name should express this. like with _.

For the variable someUsingStatementVariable there is actually a warning, that the variable is unused. So there exists an inconsistency already. R# removes var someUsingStatementVariable =  if you follow the suggestion.  The using statement declared as __ behaves as expected and does not show a warning.

Could this be improved for the using declaration, to match the using statement closer?

Best regards,
   David

0
1 comment

Hello David Flamme, thank you for your message. I've submitted a new feature request to our bug tracker: RSRP-499621 Show hint/warning for unused variables of using declarations like for using statements. Please comment or vote for it to get notifications about status changes. Thank you!

0

Please sign in to leave a comment.