Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

The "Extract method" refactoring should recognize primary constructor parameters #73044

Closed
Tragetaschen opened this issue Apr 16, 2024 · 0 comments · Fixed by #76179
Closed
Labels
Area-IDE Feature Request help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Milestone

Comments

@Tragetaschen
Copy link

Version Used:
17.10.0 Preview 3.0

Steps to Reproduce:
Run "Extract method" on the return statement:

public class Test(int value) {
  public int M() {
    return value + 1; // <-- here
  }
}

Expected Behavior:
The primary constructor parameter should be used in the generated method, so the method should have no parameters:

public class Test(int value) {
  public int M() {
    return NewMethod();
  }

  private int NewMethod() {
    return value + 1; // <-- here
  }
}

Actual Behavior:
The primary constructor parameter is converted to a method parameter and either shadows the primary constructor parameter if it needs to be an instance method or the method becomes static.

public class Test(int value) {
  public int M() {
    return NewMethod(value);
  }

  private static int NewMethod(int value) {
    return value + 1; // <-- here
  }
}
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 16, 2024
@CyrusNajmabadi CyrusNajmabadi added help wanted The issue is "up for grabs" - add a comment if you are interested in working on it Feature Request and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 16, 2024
@CyrusNajmabadi CyrusNajmabadi added this to the Backlog milestone Apr 16, 2024
@github-project-automation github-project-automation bot moved this to InQueue in Small Fixes Aug 28, 2024
@github-project-automation github-project-automation bot moved this from InQueue to Completed in Small Fixes Dec 3, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Area-IDE Feature Request help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Projects
Status: Completed
Development

Successfully merging a pull request may close this issue.

2 participants