private static void setCustomizationValue(string _name, string _value, Customization _customization) { foreach (PropertyInfo property in _customization.GetType().GetProperties()) { try { if (property.Name == _name) { if (property.PropertyType == typeof(bool)) { if (_value == "False") { property.SetValue(_customization, false, null); break; } property.SetValue(_customization, true, null); break; } else if (property.PropertyType == typeof(string)) { if (property.Name.Equals("MainWindowTitle") && _value.Length > 60) { _value = _value.Substring(0, 60); } property.SetValue(_customization, _value, null); break; } else if (property.PropertyType == typeof(int)) { property.SetValue(_customization, Convert.ToInt32(_value), null); break; } else if (property.PropertyType == typeof(byte)) { property.SetValue(_customization, Convert.ToByte(_value), null); break; } else if (property.PropertyType == typeof(double)) { property.SetValue(_customization, Convert.ToDouble(_value), null); break; } property.SetValue(_customization, Convert.ToInt32(_value), null); break; } } catch {} } }
public static void WriteCustomParameters(Customization _customization) { if (_customization == null) { return; } using (StreamWriter text = File.CreateText(Consts.CustomConfigFile)) { foreach (PropertyInfo property in _customization.GetType().GetProperties()) { text.WriteLine(property.Name + "=" + property.GetValue(_customization, null)); } } //megvárjuk, hogy kiíródjon a fájl System.Threading.Thread.Sleep(300); }
public async Task <int> DeleteCustomizationAsync(int id) { bool exists = await CustomizationExistsAsync(id); if (exists) { var entityToDelete = new Customization(); Type type = entityToDelete.GetType(); PropertyInfo prop = type.GetProperty("Id"); prop.SetValue(entityToDelete, id, null); _coditoContext.Customizations.Attach(entityToDelete); _coditoContext.Customizations.Remove(entityToDelete); // return number of changes return(await _coditoContext.SaveChangesAsync()); } else { return(0); } }