Reputation: 2918
In the following example code (which is not supposed to do anything other than illustrate my question):
public class Example
{
private void ExampleMethod()
{
this[new string[0]] = "something";
}
public string this[params string[] stuff]
{
get { return null; }
set { stuff[0] = ""; }
}
}
ReSharper prompts me with the warning:
Redundant Explicit Array Creation in argument of 'params' parameter.
This would be correct in the case of a method that had params, but in the case of an indexer the array creation is not redundant. Resharper’s ‘fix’ changes this to the following, which won’t compile:
this[] = "something"; // Won't compile
It makes sense to me that an indexer requires a parameter, so is this a bug in ReSharper, or am I missing something?
Upvotes: 3
Views: 1762
Reputation: 2918
It seems that this is a bug, and I have raised it as such with JetBrains. The particular request is here, although annoyingly, it seems that you have to log in to be able to view it.
I will therefore post any updates here.
(EDIT: I've found that you can also raise it here and this is publicly visible.)
The general feeling seems to be that having params in an indexer is unwise. I would tend to agree. Personally, I've never come across a need to do so, and it does feel odd to me, but that doesn't mean that there's no use case for it.
In my case, I didn't write the code, and changing it is not currently an option. If you find yourself in the same situation, the easiest thing to do, as already mentioned, is to select "Disable once with comment" on the warning. It will then be ignored by future cleanups.
Upvotes: 1