0

我想将一个对象复制到另一个对象,但删除某些属性。例如

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; }
}

如何用最少的代码有效地做到这一点?

4

1 回答 1

7
public class B
{
    public B(A a)
    {
        IsResizeCancel = a.IsResizeCancel;
        MaxSliderValue = a.MaxSliderValue;
    }
    public bool IsResizeCancel { get; set; }
    public double MaxSliderValue { get; set; }
}
于 2013-03-28T12:28:05.580 回答