Skip to content

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

@Tragetaschen

Description

@Tragetaschen

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
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-IDEFeature Requesthelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

    Type

    No type

    Projects

    Status

    Completed

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions