public static SettingModel GetSettingModel(List <Setting> setting) { SettingModel model = new SettingModel { }; setting.ForEach(p => { PropertyInfo propertyInfo = model.GetType().GetProperty(p.Name); propertyInfo.SetValue(model, Convert.ChangeType(p.Value, propertyInfo.PropertyType), null); }); return(model); }
public string Execute(SettingModel dto) { var setting = unit.Setting.GetAll(); for (int i = 0; i < setting.Count; i++) { var field = dto.GetType().GetProperties().FirstOrDefault(p => p.Name == setting[i].Name); setting[i].Value = field.GetValue(dto).ToString(); } unit.Complete(); return(Messages.ErenOK); }
private static void Reload(SettingModel model) { if (File.Exists(SettingsPath)) { var tmp = JsonConvert.DeserializeObject <SettingModel>(File.ReadAllText(SettingsPath)); var mt = model.GetType(); foreach (var p in tmp.GetType().GetProperties()) { var dp = mt.GetProperty(p.Name); if (dp?.CanWrite ?? false) { var d = p.GetValue(tmp); dp.SetValue(model, d, null); } } } else { model.DefaultSettings(); } }