内联类重构
此重构允许您将一个类合并到另一个类中。 被合并的类将被移除,其成员将被移动到使用该类的类中,并且所有对被合并类的使用都会相应更新。
在下面的示例中,我们将 绘图器 类(即其字段 myColor 和其方法 InitPainter )合并到 圆形 类中。
class Painter
{
private Color myColor;
public Painter(Color c)
{
myColor = c;
InitPainter(myColor);
}
private void InitPainter(Color color)
{
//init painter
}
}
class Circle
{
private Painter myPainter;
public Circle(Color c)
{
myPainter = new Painter(c);
}
}
class Circle
{
private Color myColor;
public Circle(Color c)
{
myColor = c;
InitPainter(myColor);
}
private void InitPainter(Color color)
{
//init painter
}
}
内联一个类
应用重构后,属性或字段将被其类型的成员替换。 所有对该属性或字段的使用都会相应更新。
此功能在以下语言和技术中 受支持:
此处提供的说明和示例针对在 C# 中使用该功能。 有关其他语言的更多信息,请参阅 语言和框架 部分中的相应主题。
最后修改日期: 2025年 9月 27日