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
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.
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.
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.
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.
You can use Resharper with "Extract Superclass".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With