protected void Remove(OptionItem item) { if (item == null) { return; } string name = item.GetStoreKey(); if (string.IsNullOrEmpty(name)) { return; } Type type = item.GetType(); PersistentNameLookup names = GetExisting(type); if (names == null) { return; } PersistentOption option = names.Get(name); if (option != null) { mOptions.Remove(option); names.Remove(name, option); } }
public bool Restore(OptionItem item) { if (item == null) { return(false); } try { string name = item.GetStoreKey(); OptionLogger.AddTrace(" Option: " + name); PersistentNameLookup names = GetExisting(item.GetType()); if (names == null) { OptionLogger.AddError(" No Name"); return(false); } PersistentOption option = names.Get(name); if (option == null) { OptionLogger.AddError(" No Option"); return(false); } try { if (option.mValue != null) { item.PersistValue = option.mValue; } return(true); } catch (InvalidCastException e) { Common.DebugException(item.GetStoreKey() + ": " + option.mValue + " (" + option.mValue.GetType() + ")", e); OptionLogger.AddError(" Casting Fail"); return(false); } } catch (Exception e) { Common.Exception(item.GetStoreKey(), e); OptionLogger.AddError(" Exception"); return(false); } }
public bool Store(OptionItem item) { if (item is INotPersistableOption) { return(false); } string name = item.GetStoreKey(); if (string.IsNullOrEmpty(name)) { return(false); } Type type = item.GetType(); PersistentNameLookup names = Get(type); object value = item.PersistValue; PersistentOption option = names.Get(name); if (option == null) { option = new PersistentOption(type, name, value); mOptions.Add(option); names.Add(name, option); } else { option.mName = name; option.mValue = value; } return(true); }