Ejemplo n.º 1
0
            private readonly bool _reversed;   // is the view reversed?

            /// <summary>
            /// Initialize the View.
            /// </summary>
            /// <param name="myDictionary">Associated OrderedMultiDictionary to be viewed.</param>
            /// <param name="rangeTester">Range tester that defines the range being used.</param>
            /// <param name="entireTree">If true, then rangeTester defines the entire tree.</param>
            /// <param name="reversed">Is the view enuemerated in reverse order?</param>
            internal View(OrderedMultiDictionary <TKey, TValue> myDictionary,
                          RedBlackTree <KeyValuePair <TKey, TValue> > .RangeTester rangeTester, bool entireTree, bool reversed)
            {
                _myDictionary = myDictionary;
                _rangeTester  = rangeTester;
                _entireTree   = entireTree;
                _reversed     = reversed;
            }
Ejemplo n.º 2
0
        /// <summary>
        /// Makes a deep clone of this dictionary. A new dictionary is created with a clone of
        /// each entry of this dictionary, by calling ICloneable.Clone on each element. If TKey or TValue is
        /// a value type, then each element is copied as if by simple assignment.
        /// </summary>
        /// <remarks><para>If TKey or TValue is a reference type, it must implement
        /// ICloneable. Otherwise, an InvalidOperationException is thrown.</para>
        /// <para>Cloning the dictionary takes time O(N log N), where N is the number of key-value pairs in the dictionary.</para></remarks>
        /// <returns>The cloned dictionary.</returns>
        /// <exception cref="InvalidOperationException">TKey or TValue is a reference type that does not implement ICloneable.</exception>
        public OrderedMultiDictionary <TKey, TValue> CloneContents()
        {
            bool keyIsValueType, valueIsValueType;

            // Make sure that TKey and TValue can be cloned.
            if (!Util.IsCloneableType(typeof(TKey), out keyIsValueType))
            {
                NonCloneableType(typeof(TKey));
            }

            if (!Util.IsCloneableType(typeof(TValue), out valueIsValueType))
            {
                NonCloneableType(typeof(TValue));
            }

            var newDict = new OrderedMultiDictionary <TKey, TValue>(_allowDuplicateValues, _keyComparer, _valueComparer);

            foreach (var pair in _tree)
            {
                // Clone the key and value parts of the pair. Value types can be cloned
                // by just copying them, otherwise, ICloneable is used.

                TKey keyClone = keyIsValueType
                                    ? pair.Key
                                    : (Equals(pair.Key, null)
                                           ? default(TKey)
                                           : (TKey)pair.Key); //(TKey) (((ICloneable) pair.Key).Clone()));

                TValue valueClone = valueIsValueType
                                        ? pair.Value
                                        : (Equals(pair.Value, null)
                                               ? default(TValue)
                                               : (TValue)pair.Value); //(TValue) (((ICloneable) pair.Value).Clone()));

                newDict.Add(keyClone, valueClone);
            }

            return(newDict);
        }
Ejemplo n.º 3
0
 public KeyValuePairsCollection(OrderedMultiDictionary <TKey, TValue> myDictionary)
 {
     _myDictionary = myDictionary;
 }