示例#1
0
 public void RemoveFieldValue(FieldValue fv)
 {
     fieldValues.Remove(fv);
     fieldValueDict.Remove(fv.FieldName);
 }
示例#2
0
文件: Item.cs 项目: ogazitt/zaplify
 public void RemoveFieldValue(FieldValue fv)
 {
     fieldValues.Remove(fv);
     fieldValueDict.Remove(fv.FieldName);
 }
示例#3
0
文件: Item.cs 项目: ogazitt/zaplify
        // 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;
        }
示例#4
0
 public FieldValue(FieldValue fieldValue)
 {
     Copy(fieldValue);
 }
示例#5
0
 public FieldValue(FieldValue fieldValue)
 {
     Copy(fieldValue);
 }
示例#6
0
        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);
            }
        }