通过父类创建子类
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ZZX.Model.ViewModel { /// <summary> /// 用户所申请的工作 /// </summary> public class UserJob:Job { /// <summary> /// 子类构造函数 /// </summary> /// <param name="parent">父类对象</param> public UserJob(Job parent) { var parentProperties = parent.GetType().GetProperties(); foreach (var parentProperty in parentProperties) { var thisProperty = this.GetType().GetProperty(parentProperty.Name, parentProperty.PropertyType); var value = parentProperty.GetValue(parent); if (thisProperty != null && value != null && thisProperty.CanWrite) { thisProperty.SetValue(this, value); } } } /// <summary> /// 申请状态 /// </summary> public int ApplyStatus { set; get; } /// <summary> /// 申请状态描述 /// </summary> public string ApplyStatusText { set; get; } /// <summary> /// 申请领薪资的方式 /// </summary> public int ApplySalaryWay { set; get; } /// <summary> /// 申请领薪资的方式描述 /// </summary> public string ApplySalaryWayText { set; get; } } }
标签:set,子类,System,parentProperty,创建,using,父类,public From: https://www.cnblogs.com/niunan/p/17663685.html