Example #1
0
        /// <summary>
        /// Notifier for subordinate dictionaries
        /// indicating that an item has been removed.
        /// </summary>
        /// <typeparam name="TSKey">The kind of key within the subordinate
        /// dictionary.</typeparam>
        /// <typeparam name="TSValue">
        /// The specific type of value used in the
        /// subordinate dictionary, derives from the
        /// master dictionary's <typeparamref name="TValue"/>.
        /// </typeparam>
        /// <param name="subordinate">
        /// The <see cref="ISubordinateDictionary{TSKey, TMKey, TSValue, TMValue}"/>
        /// which is a subordinate of the current
        /// <see cref="MasterDictionaryBase{TKey, TValue}"/>.
        /// </param>
        /// <param name="key">
        /// The <typeparamref name="TSKey"/> of the item removed.
        /// </param>
        protected internal virtual void Subordinate_ItemRemoved <TSKey, TSValue>(ISubordinateDictionary <TSKey, TKey, TSValue, TValue> subordinate, TSKey key)
            where TSKey :
        TKey
            where TSValue :
        TValue
        {
            int index = this.Keys.IndexOf(key);

            /* *
             * The cause behind this is a caching issue.  Since the CLI types
             * are singletons, clearing the cache causes the signatures associated
             * to the members to become invalid since they referenced a type whose
             * underlying system type is now null.
             * */
            if (index == -1)
            {
                return;
            }
            MasterDictionaryEntry <TValue> entry = this.Values[index];

            if (entry.Subordinate != subordinate)
            {
                throw ThrowHelper.ObtainArgumentException(ArgumentWithException.subordinate, ExceptionMessageId.SubordinateMismatch);
            }
            base._Remove(index);
        }
Example #2
0
 /// <summary>
 /// Notifier for subordinate dictionaries
 /// indicating that an item has been changed.
 /// </summary>
 /// <typeparam name="TSKey">The kind of key within the subordinate
 /// dictionary.</typeparam>
 /// <typeparam name="TSValue">
 /// The specific type of value used in the
 /// subordinate dictionary, derives from the
 /// master dictionary's <typeparamref name="TValue"/>.
 /// </typeparam>
 /// <param name="subordinate">
 /// The <see cref="ISubordinateDictionary{TSKey, TMKey, TSValue, TMValue}"/>
 /// which is a subordinate of the current
 /// <see cref="MasterDictionaryBase{TKey, TValue}"/>.
 /// </param>
 /// <param name="key">
 /// The <typeparamref name="TKey"/> of the item changed.
 /// </param>
 /// <param name="value">
 /// The <typeparamref name="TSValue"/> of the item
 /// changed.
 /// </param>
 protected internal virtual void Subordinate_ItemChanged <TSKey, TSValue>(ISubordinateDictionary <TSKey, TKey, TSValue, TValue> subordinate, TSKey key, TSValue value)
     where TSKey :
 TKey
     where TSValue :
 TValue
 {
     base[key] = new MasterDictionaryEntry <TValue>((ISubordinateDictionary)subordinate, value);
 }
Example #3
0
 public bool Equals(MasterDictionaryEntry <TEntry> other)
 {
     if (other.Subordinate == this.Subordinate)
     {
         return(other.Entry == this.Entry);
     }
     return(false);
 }
Example #4
0
        /// <summary>
        /// Adds an element of the provided <paramref name="key"/>
        /// and <paramref name="value"/> to the
        /// <see cref="MasterDictionaryBase{TKey, TValue}"/>.
        /// </summary>
        /// <param name="key">The <typeparamref name="TKey"/> of the
        /// current <paramref name="value"/> inserted.</param>
        /// <param name="value">The <typeparamref name="TValue"/>
        /// to insert.</param>
        /// <exception cref="System.ArgumentException">thrown when the
        /// <see cref="MasterDictionaryEntry{TEntry}.Subordinate"/> in
        /// <paramref name="value"/> is: null or not a subordinate
        /// of the <see cref="MasterDictionaryBase{TKey, TValue}"/>.
        /// </exception>
        protected internal override void _Add(TKey key, MasterDictionaryEntry <TValue> value)
        {
            if (value.Subordinate == null)
            {
                throw ThrowHelper.ObtainArgumentException(ArgumentWithException.value, ExceptionMessageId.SubordinateNull);
            }
            if (!this.subordinates.Contains(value.Subordinate))
            {
                throw ThrowHelper.ObtainArgumentException(ArgumentWithException.value, ExceptionMessageId.SubordinateDoesNotExist);
            }

            /* *
             * Don't call base class' add, the subordinate will
             * invoke Subordinate_ItemAdded<TSValue> which will
             * invoke the base add
             * */
            ((_ISubordinateDictionaryMasterPass)(value.Subordinate)).Add(key, value.Entry);
        }
Example #5
0
        /// <summary>
        /// Sets the value associated with the specified
        /// <paramref name="key"/>.</summary>
        /// <param name="key">The <typeparamref name="TKey"/>
        /// to look for.</param>
        /// <param name="value">The value to set the element,
        /// at the <paramref name="key"/> provided, to.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <see cref="MasterDictionaryEntry{TEntry}.Subordinate"/> in
        /// value is: null, or not a subordinate
        /// of the <see cref="MasterDictionaryBase{TKey, TValue}"/>,
        /// or tries to alter which subordinate the
        /// <paramref name="key"/> points to.
        /// </exception>
        protected override void OnSetThis(TKey key, MasterDictionaryEntry <TValue> value)
        {
            if (value.Subordinate == null)
            {
                throw ThrowHelper.ObtainArgumentException(ArgumentWithException.value, ExceptionMessageId.SubordinateNull);
            }
            if (!this.subordinates.Contains(value.Subordinate))
            {
                throw ThrowHelper.ObtainArgumentException(ArgumentWithException.value, ExceptionMessageId.SubordinateDoesNotExist);
            }
            if (base[key].Subordinate != value.Subordinate)
            {
                throw ThrowHelper.ObtainArgumentException(ArgumentWithException.value, ExceptionMessageId.SubordinateCannotChange);
            }

            /* *
             * This is the primary reason that
             * MasterDictionaryEntry<TEntry> contains
             * a 'value'.
             * */
            ((_ISubordinateDictionaryMasterPass)(this[key].Subordinate))[key] = value.Entry;
        }