private void internLoad(string PropertyName) { PropertyInfo PropInfo = null; PropInfo = Settings.GetType().GetProperty(PropertyName); object[] atts = PropInfo.GetCustomAttributes(false); ProfileSettingStoreAttribute attrb = null; foreach (object Attribut in atts) { if (!(Attribut is ProfileSettingStoreAttribute)) { continue; } attrb = Attribut as ProfileSettingStoreAttribute; break; } if (attrb == null) { return; } object val = ProfileRegistryKey.GetValue(attrb.SaveName, attrb.DefaultValue); try { PropInfo.SetValue(Settings, Convert.ChangeType(ProfileRegistryKey.GetValue(attrb.SaveName, attrb.DefaultValue), PropInfo.PropertyType), null); } catch { try { PropInfo.SetValue(Settings, attrb.DefaultValue, null); } catch (Exception ex) { MessageBox.Show(ex.Message, "Fehler"); } } }
private void Save(string PropertyName) { PropertyInfo PropInfo = null; PropInfo = Settings.GetType().GetProperty(PropertyName); if (PropInfo == null) { throw new Exception(PropertyName + " konnte nicht geladen werden."); } object[] atts = PropInfo.GetCustomAttributes(false); ProfileSettingStoreAttribute attrb = null; foreach (object Attribut in atts) { if (!(Attribut is ProfileSettingStoreAttribute)) { continue; } attrb = Attribut as ProfileSettingStoreAttribute; break; } if (attrb == null) { return; } //speichere Attribut //ermittle RegistryKey für Speicherung ermitteln object val = PropInfo.GetValue(Settings, null); ProfileRegistryKey.SetValue(attrb.SaveName, val); Settings.GetType(); PropInfo.SetValue(Settings, Convert.ChangeType(ProfileRegistryKey.GetValue(attrb.SaveName, attrb.DefaultValue), PropInfo.PropertyType), null); }