Exemplo n.º 1
0
        /// <summary>
        /// Removes mapping by the provided source or destination member name.
        /// </summary>
        /// <param name="memberName">A name of the source or destination member to remove.</param>
        /// <returns>A changed <see cref="Map"/> instance.</returns>
        public ISimpleMapper Remove(string memberName)
        {
            if (string.IsNullOrWhiteSpace(memberName))
            {
                throw new ArgumentNullException(nameof(memberName));
            }

            for (int i = items.Count - 1; i >= 0; i--)
            {
                MappedItem m = items[i];

                if (m.Source.Name == memberName ||
                    m.Destination.Name == memberName)
                {
                    //// if item is complex, remove the sub map
                    if (m.IsComplex)
                    {
                        subMaps.Remove(m.Key);
                    }

                    items.RemoveAt(i);
                    m.Remove();
                }
            }

            return(this);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Removes provided item from the map.
        /// </summary>
        /// <param name="item">A mapping to remove.</param>
        /// <returns>A changed <see cref="Map"/> instance.</returns>
        public ISimpleMapper Remove(MappedItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            if (item.Map != this)
            {
                throw new ArgumentException("MappedItem is not from this setup.", "item");
            }

            int index = this.items.IndexOf(item);

            if (index >= 0)
            {
                this.items.RemoveAt(index);
                item.Remove();
            }

            return(this);
        }