我正在类中添加一个新的数据成员,该类是共享nuget包的一部分。在Server应用程序上,我需要同时支持这两个nuget软件包,以前的nuget软件包成员没有新添加的成员。我如何映射此成员,以便我的代码不会中断。请查看以下代码。
Nuget软件包1.0
Class Employee
{
public int Id {get; set;}
public string Address { get; set;}
}
Nuget软件包1.1
Class Employee
{
public int Id {get; set;}
public string Address { get; set;}
public string Department { get; set;}
}
从客户端,如果未通过Department成员,我想将服务器Department设置为Null,否则将设置客户端传递的值。
答案 0 :(得分:1)
尽管我不确定我是否完全理解该问题,但我相信您所寻找的可能是自动属性初始化器:
class Employee
{
public int Id {get; set;}
public string Address { get; set;}
public string Department { get; set;} = null;
}
有关更多信息,请点击此处:https://msdn.microsoft.com/en-us/magazine/dn802602.aspx