我想将对象复制到另一个对象但删除某些属性。例如
public class A
{
public bool IsResizeCancel { get; set; }
public double MaxSliderValue { get; set; }
public double CurrentWidth { get; private set; }
public double CurrentHeight { get; private set; }
}
将对象A复制到对象B,但删除CurrentWidth和CurrentHeight属性
public class B
{
public bool IsResizeCancel { get; set; }
public double MaxSliderValue { get; set; }
}
如何使用最少量的代码有效地完成此操作?
答案 0 :(得分:7)
public class B
{
public B(A a)
{
IsResizeCancel = a.IsResizeCancel;
MaxSliderValue = a.MaxSliderValue;
}
public bool IsResizeCancel { get; set; }
public double MaxSliderValue { get; set; }
}