Stylecopanalyzers: Usage of _ in methods arguments raises SA1313

Created on 22 Jan 2018  路  4Comments  路  Source: DotNetAnalyzers/StyleCopAnalyzers

Usage of _ in method arguments raises SA1313.

Example:
C# public override void Foo( int arg, int _ ) { ... }

Can you please make an exception to SA1313, to support '_' in method arguments?

enhancement wontfix

All 4 comments

I agree. As is, an exception is made for lambda expressions...

In fact, I would request that any number of ignored parameters be supported in this way. This supports the cases where multiple parameters are to be ignored.

e.g. MyProperty.PropertyChanged += (_, __) => ...

I'm not sure I agree with this one. Plus, it's going to conflict with #1949.

@brinko99 Your case is a duplicate of #1606.

Why are you not sure you agree?
The purpose of the _ is to acknowledge the arg is not in use.
Without this enhancement, users can use this feature ONLY in lambda handlers.

About the conflict with #1949 I agree. Implementing this should include an exception to #1949.

Closing this one as won't fix. The recommended solution for method signatures when a parameter is intentionally not used is:

  1. Give the parameter a meaningful name. This should match the original definition when applicable (see #1949).
  2. Assign the parameter to a discard at the start of the method to clearly indicate to the reader that the parameter is intentionally unused.

For example:

public void Method(T value)
{
  _ = value;
}
Was this page helpful?
0 / 5 - 0 ratings