Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReSharper always asks to change System.Action to System.Action<T>

Tags:

c#

resharper

Using VS2010 and ReSharper 5

I have a method which returns a System.Action

private Action ExtractFile()
{
    return delegate
    {
        MessageBox.Show("Test");
    };
}

ReSharper, for some reason, tends to show me a correction that the return type of the method should be mapped to System.Action<T> or one of its variants. It seems that it won't recognize the non-generic version! VS complies and doesn't complain about this!

When I mouse over the red curly line, the tooltip shown says

Incorrect number of type parameters.
Candidates are: void System.Action(T)
void System.Action(T1, T2) ...
... and the list continues until T1-T16

Any ideas?See the return type highlighted by ReSharper

like image 562
Numan Avatar asked Mar 11 '11 12:03

Numan


1 Answers

Seems to me that you need to update ReSharper to the latest version, which is version 5.1. If you have items that are not loaded by ReSharper (i.e., check your excluded items list), then it will mark them as unknown, even if your code is legal and references the items.

You may try Clear Cache, or reset default settings.

Your screenshot did not show a curly line under "delegate", but with default settings it should suggest you to rewrite the code as follows (but this is not necessarily better):

private Action ExtractFile()
{
    return () => MessageBox.Show("Test");
}

If all fails, click the little lightbulb on the left (or hit Alt+Enter). Select "Inspection options for ..." and change the severity or select ignore.

like image 108
Abel Avatar answered Nov 15 '22 00:11

Abel