public void RemoveFieldValue(FieldValue fv) { fieldValues.Remove(fv); fieldValueDict.Remove(fv.FieldName); }
// get FieldValue of this Item for the given Field // if create == true, a new FieldValue with for this Field will be created if none exists public FieldValue GetFieldValue(Field field, bool create = false) { FieldValue fieldValue = null; // initialize the dictionary if necessary if (fieldValueDict == null) fieldValueDict = new Dictionary<string, FieldValue>(); // try to get the FieldValue out of the dictionary (if it was already retrieved) if (fieldValueDict.TryGetValue(field.Name, out fieldValue) == true) return fieldValue; // get the fieldvalue associated with this field // this may fail if this item doesn't have this field set yet fieldValue = fieldValues.FirstOrDefault(fv => fv.FieldName == field.Name); if (fieldValue != null) { // store the new FieldValue in the dictionary fieldValueDict[field.Name] = fieldValue; } else { // if the caller wishes to create a new FieldValue, do so now if (create) { fieldValue = new FieldValue() { FieldName = field.Name, ItemID = this.ID, Value = FieldTypes.DefaultValue(field.FieldType) }; // store the new FieldValue in the dictionary fieldValueDict[field.Name] = fieldValue; if (fieldValues == null) fieldValues = new ObservableCollection<FieldValue>(); // add the new FieldValue in the FieldValues collection fieldValues.Add(fieldValue); } } return fieldValue; }
public FieldValue(FieldValue fieldValue) { Copy(fieldValue); }
public void Copy(FieldValue obj) { if (obj == null) return; // copy all of the properties foreach (PropertyInfo pi in obj.GetType().GetProperties()) { // get the value of the property var val = pi.GetValue(obj, null); pi.SetValue(this, val, null); } }