Roslyn: New refactoring: Make local function static

Created on 19 Apr 2019  路  4Comments  路  Source: dotnet/roslyn

This refactoring would add the static modifier to a local function, and automatically add parameters to the local function for each item previously captured by the function.

Area-IDE Feature Request IDE-CodeStyle

Most helpful comment

Assigned to @lavanyaguru

All 4 comments

Assigned to @lavanyaguru

Feature is in the works

Current Situation

As of now, local functions using local variables are not suggested to use static, but the refactoring would be triggered when the use of a local function is detected.

With the addition of the static modifier being suggested, the refactoring would also capture the use of any local variables and pass them as parameters and arguments for the method declaration and method call respectively.

Old

Current Situation: using the static modifier isn't suggested since it would cause an error and hinder the use of the variables of firstName and lastName in this scenario

Refactoring Plan

The user is given a suggestion of adding static and the suggestion would include the parameters being passed. The preview would show the parameters being passed in

  1. Capture1 (2)

  2. Capture2 (2)

After Refactoring

NewRefactoring
After the Refactoring: The static modifier is added while the local variables are passed in as arguments and parameters

Note: we should detect and give a warning/error annotation in the code if this would break things (i.e. because the local function is now passed to something and the signature is no longer compatible).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

codingonHP picture codingonHP  路  3Comments

NikChao picture NikChao  路  3Comments

nlwolf picture nlwolf  路  3Comments

OndrejPetrzilka picture OndrejPetrzilka  路  3Comments

marler8997 picture marler8997  路  3Comments