我有一个模型和一个只包含我需要在JSON中公开的属性的部分模型。模型和部分模型,如何避免冗余代码?
但模型和他的部分模型之间的属性是多余的。
我该如何避免这种情况或改进我的方法?
namespace Dashboard.Models.UserModels
{
public class UserModel
{
public int id { get; set; }
public string dbName { get; set; }
public string firstname { get; set; }
public string lastname { get; set; }
public int idExternal { get; set; }
public int idInstance { get; set; }
public string login { get; set; }
public string password { get; set; }
public DateTime? dtContractStart { get; set; }
public DateTime? dtContractEnd { get; set; }
public string emailPro { get; set; }
public string emailPerso { get; set; }
public LuccaUserModel()
{
idInstance = -1;
}
// partial model for json result
// not sure is the best way or have to be here
public class PartialUserModel
{
public int id { get; set; }
public string firstname { get; set; }
public string lastname { get; set; }
public string emailPro { get; set; }
public string emailPerso { get; set; }
public DateTime? dtContractStart { get; set; }
public DateTime? dtContractEnd { get; set; }
public string url { get; set; }
}
// UserModel Methods
}
}
这不是'[JsonIgnore]'是为了什么? – paul
@paul:Darin Dimitrov建议避免它([源](http://stackoverflow.com/a/12110508/652669)),所以我不知道。 :■ –