Put*_*aKg 0 c# clone copy object windows-phone-8
我想将对象复制到另一个对象但删除某些属性.例如
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; }
}
Run Code Online (Sandbox Code Playgroud)
将对象A复制到对象B,但删除CurrentWidth和CurrentHeight属性
public class B
{
public bool IsResizeCancel { get; set; }
public double MaxSliderValue { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
如何用最少的代码有效地完成这项工作?
public class B
{
public B(A a)
{
IsResizeCancel = a.IsResizeCancel;
MaxSliderValue = a.MaxSliderValue;
}
public bool IsResizeCancel { get; set; }
public double MaxSliderValue { get; set; }
}
Run Code Online (Sandbox Code Playgroud)