示例#1
0
        public void Add(DataMappingEntry item)
        {
            CheckItem(item);

            if (Exists(item))
            {
                throw new Exception(string.Format(
                    "DataMappingEntry already exists: {0}\nUse Update(...) or AddOrUpdate(...) to set a new value.",
                    item.NameFrom));
            }

            dataMappingEntries.Add(item);
        }
示例#2
0
        public void AddOrUpdate(DataMappingEntry item)
        {
            CheckItem(item);

            int index = FindIndexByNameFrom(item.NameFrom);

            if (index < 0)
            {
                // Add
                dataMappingEntries.Add(item);
            }
            else
            {
                // Update
                dataMappingEntries[index] = item;
            }
        }
示例#3
0
        public void Update(DataMappingEntry item)
        {
            CheckItem(item);

            int index = FindIndexByNameFrom(item.NameFrom);

            if (index < 0)
            {
                throw new Exception(string.Format(
                    "DataMappingEntry doesn't exist to be updated: {0}\nUse Add(...) or AddOrUpdate(...) to insert a new entry.",
                    item.NameFrom));
            }

            dataMappingEntries[index] = item;
        }
示例#4
0
        /// <summary>
        /// Throws if the item has invalid data to be added or updated, does nothing if everything is ok.
        /// </summary>
        /// <param name="item"></param>
        protected void CheckItem(DataMappingEntry item)
        {
            if (item == null)
            {
                throw new Exception("DataMappingEntry object cannot be null.");
            }

            if (string.IsNullOrEmpty(item.NameFrom))
            {
                throw new Exception("NameFrom needs to be specified in the DataMappingEntry object when adding to the list of entries.");
            }
        }
示例#5
0
 /// <summary>
 /// Returns true if the item already exists.
 /// Only NameFrom is checked, not the rest of the properties.
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public bool Exists(DataMappingEntry item)
 {
     return dataMappingEntries.Exists(delegate(DataMappingEntry entry)
         {
             return entry.NameFrom.Equals(item.NameFrom);
         });
 }