Skip to content

"Extract Base Class" does not extract generic type parameters, causing errors in the extracted class #55871

@Soreloser2

Description

@Soreloser2

Steps to Reproduce:

  1. Create a class with at least one generic type parameter that is used in a member:
public class C<T>
{
    public T M()
    {
        return default;
    }

    public T testField;
}
  1. Trigger the quick actions menu on the class declaration or a member declaration and select Extract Base Class
  2. Select any or all members and perform the refactoring
    Expected Behavior:
    The generated class will have type parameters that were necessary for the members that are moved:
public class CBase<T>
{
    public T M()
    {
        return default;
    }

    public T testField;
}

Actual Behavior:
The generated class has no type parameters, causing "T" to produce an error as it is unqualified:

public class CBase
{
    public T M() // There is no T here
    {
        return default;
    }

    public T testField;
}

While the generated type name produces a generic preview when there are type parameters used as members, and will fill in the required type parameters when certain members are selected, it does not update with the correct type parameters when a type parameter is used within a method (not in the return value or argument list), and does not update when it is used in a field.

There is an ExtractTypeHelpers class that is used for the preview, but not for the actual refactoring. It seems designed for extracting interfaces, and doesn't work on fields, so maybe there are two separate issues. One for Extract Base Class not doing anything generic, and one for Extract Type Helpers only working on interface-like members (i.e. not fields, not looking inside member bodies).

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions