所以基本上我有这个

public class Ticket{
    public TicketNumber {get; set;}
    ..a bunch more properties...
}


我想使用像这样的子类添加一些属性,而不是使用合成。

public class TicketViewModel(Ticket ticket){
    //set each property from value of Ticket passed in
    this.TicketNumber = ticket.TicketNumber;
    ...a bunch more lines of code..

    //additional VM properties
    public SelectList TicketTypes {get; private set;}
}


如何实例化属性,而不必像这样写所有行

this.TicketNumber = ticket.TicketNumber;


有某种捷径吗?在子类构造函数中是什么样的?

this = ticket;


显然,这是行不通的,但是是它们的某种方式,因此,如果向父类添加/删除属性,则不必修改子类?或者其他的东西?

最佳答案

看看Automapper

09-06 19:05