public bool Contains(DBItem obj) { if (obj == null || cache[obj.GetType()] == null) return false; return cache[obj.GetType()].ContainsValue(obj); }
// Adds the given element to the cacheing system public DBItem Add(DBItem obj) { if (obj == null || obj.Id == null) return obj; if (!cache.ContainsKey(obj.GetType())) cache[obj.GetType()] = new Dictionary<int, DBItem>(); if (!cache[obj.GetType()].ContainsKey((int)obj.Id)) cache[obj.GetType()][(int)obj.Id] = obj; return cache[obj.GetType()][(int)obj.Id]; }
public void BindData(DBItem dataSource, DBColumn column, DBTable refer = null) { if (Column != column && dataSource?.GetType() != DataSource.GetType()) { Binding?.Dispose(); if (column != null) { CellEditor = TableLayoutList.InitCellEditor(column); if (CellEditor is CellEditorTable && refer != null) { ((CellEditorTable)CellEditor).Table = refer; } Binding = new InvokeBinder <DBItem, FieldEditor>(dataSource, column, this, EmitInvoker.Initialize <FieldEditor>(nameof(Value))); } } DataSource = dataSource; }
// remove the existing object with the same ID from the cache and store this one instead. public void Replace(DBItem obj) { if (obj == null || obj.Id == null) return; if (!cache.ContainsKey(obj.GetType())) cache[obj.GetType()] = new Dictionary<int, DBItem>(); cache[obj.GetType()][(int)obj.Id] = obj; }
// Shoudl really only be called if an item has been deleted from the database public void Remove(DBItem obj) { if (obj == null || obj.Id == null) return; cache[obj.GetType()].Remove((int)obj.Id); }
// Sets the value of this field for the given object. public void SetValue(DBItem owner, object value) { try { // if we were passed a null value, try to set that. if (value == null) { propertyInfo.GetSetMethod().Invoke(owner, new object[] { null }); return; } // if we were passed a matching object, just set it if (value.GetType() == propertyInfo.PropertyType) { string strVal = value as string; if (strVal != null) value = strVal.Trim(); propertyInfo.GetSetMethod().Invoke(owner, new object[] { value }); return; } if (value is string) propertyInfo.GetSetMethod().Invoke(owner, new object[] { ConvertString((string)value) }); } catch (Exception e) { Logger.LogError("Error writing to {0}.{1} Property: {2}", owner.GetType().Name, this.Name, e.Message); } }