Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tool for extracting base class?

If I have a C# code like this:

public class A {
    public string PropA { get; set; }
    public string PropB { get; set; }

    public string PropZ { get; set; }

}

public class B {
    public string PropA { get; set; }
    public string PropB { get; set; }

    public string PropX { get; set; }
    public string PropY { get; set; }

}

As PropA and PropB exist in both class, and have the same meaning, I'd like to refactor like this :

public abstract class Base {
    public string PropA { get; set; }
    public string PropB { get; set; }
}

public class A : Base {
    public string PropZ { get; set; }

}
public class B : Base {

    public string PropX { get; set; }
    public string PropY { get; set; }

}

Using VS 2010, is there any tool/extension that allows me to quickly do that ? In fact, my actual code contains dozens of property in several classes, not in the same order. This is can be a bit of pain to properly factorize the code... that's why I'm looking for a lazy way to do this

like image 781
Steve B Avatar asked Aug 29 '11 09:08

Steve B


People also ask

How do you extract a base class?

Place your caret on either the class name or a highlighted member. Press Ctrl+. to trigger the Quick Actions and Refactorings menu. Select Pull member(s) up to new base class.

What is an Extract Class in Java?

In software engineering, the Extract Class refactoring is applied when a class becomes overweight with too many methods and its purpose becomes unclear. Extract Class refactoring involves creating a new class and moving methods and/or data to the new class.

What is extract method in C#?

Extract Method helps you reorganize your code for better reuse and readability. By analyzing the selected code, Telerik® JustCode™ creates a new method that contains the extracted code and replaces it in the existing member with a call to the new method. Note. Language Support. Supported: C#, VB.NET.

What is extract interface?

The Extract Interface refactoring allows you to define a new interface from selected class or interface members. It also allows you to select already inherited interfaces and effectively make the new interface inherit from them.


1 Answers

You can use Resharper with "Extract Superclass".

like image 96
Daniel Hilgarth Avatar answered Nov 14 '22 23:11

Daniel Hilgarth