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); } }
public object GetFieldValue(Field field) { PropertyInfo pi = null; object currentValue = null; // get the current field value. // the value can either be in a strongly-typed property on the item (e.g. Name), // or in one of the FieldValues try { // get the strongly typed property pi = this.GetType().GetProperty(field.Name); if (pi != null) { currentValue = pi.GetValue(this, null); } } catch (Exception) { // an exception indicates this isn't a strongly typed property on the Item // this is NOT an error condition } // if couldn't find a strongly typed property, this property could be stored as a // FieldValue on the item if (pi == null) { // get current item's value for this field FieldValue fieldValue = this.FieldValues.FirstOrDefault(fv => fv.FieldName == field.Name); if (fieldValue != null) { currentValue = fieldValue.Value; } } return(currentValue); }
public FieldValue(FieldValue fieldValue) { Copy(fieldValue); }
private FieldValue GetGroceryCategoryFieldValue(Item item, bool create = false) { // get or create the list for Grocery item types in the UserFolder var knownGroceryItems = storage.UserFolder.GetListForItemType(user, SystemItemTypes.Grocery); if (knownGroceryItems == null) return null; Item groceryItem = null; FieldValue groceryCategoryFV = null; // get the normalized name for the grocery (stored in Intent) or resort to lowercased item name var intentFV = item.GetFieldValue(ExtendedFieldNames.Intent); var itemName = intentFV != null && intentFV.Value != null ? intentFV.Value : item.Name.ToLower(); if (storage.Items.Any(i => i.Name == itemName && i.ParentID == knownGroceryItems.ID)) { groceryItem = storage.Items.Include("FieldValues").Single(i => i.Name == itemName && i.ParentID == knownGroceryItems.ID); groceryCategoryFV = groceryItem.GetFieldValue(FieldNames.Category, true); } else if (create) { // create grocery item category item DateTime now = DateTime.UtcNow; var groceryCategoryItemID = Guid.NewGuid(); groceryCategoryFV = new FieldValue() { ItemID = groceryCategoryItemID, FieldName = FieldNames.Category, Value = null, }; groceryItem = new Item() { ID = groceryCategoryItemID, Name = itemName, FolderID = knownGroceryItems.FolderID, UserID = user.ID, ItemTypeID = SystemItemTypes.NameValue, ParentID = knownGroceryItems.ID, Created = now, LastModified = now, FieldValues = new List<FieldValue>() { groceryCategoryFV } }; storage.Items.Add(groceryItem); } return groceryCategoryFV; }
public FieldValue GetFieldValue(string fieldName, bool create = false) { if (this.FieldValues != null) { foreach (var fv in this.FieldValues) { if (fv.FieldName.Equals(fieldName)) { return fv; } } } if (create == true) { FieldValue fv = new FieldValue() { FieldName = fieldName, ItemID = this.ID }; if (this.FieldValues == null) { this.FieldValues = new List<FieldValue>(); } this.FieldValues.Add(fv); return fv; } return null; }