Ejemplo n.º 1
0
        /// <summary>
        /// Creates a read-only view of the <see cref="MultiKeyedList{TKey, TValue}"/>.</summary>
        /// <returns>
        /// A read-only wrapper around the <see cref="MultiKeyedList{TKey, TValue}"/>.</returns>
        /// <remarks><para>
        /// Attempting to modify the read-only wrapper returned by <b>AsReadOnly</b> will raise a
        /// <see cref="NotSupportedException"/>. Note that the original collection may still change,
        /// and any such changes will be reflected in the read-only view.
        /// </para><para>
        /// <b>AsReadOnly</b> buffers the newly created read-only wrapper when the method is first
        /// called, and returns the buffered value on subsequent calls.</para></remarks>

        public new MultiKeyedList <TKey, TValue> AsReadOnly()
        {
            if (ReadOnlyWrapper == null)
            {
                ReadOnlyWrapper = new MultiKeyedList <TKey, TValue>(this, true);
            }

            return((MultiKeyedList <TKey, TValue>)ReadOnlyWrapper);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a deep copy of the <see cref="MultiKeyedList{TKey, TValue}"/>.</summary>
        /// <returns>
        /// A deep copy of the <see cref="MultiKeyedList{TKey, TValue}"/>.</returns>
        /// <exception cref="InvalidCastException">
        /// <typeparamref name="TValue"/> does not implement <see cref="ICloneable"/>.</exception>
        /// <remarks><para>
        /// <b>Copy</b> is similar to <see cref="Clone"/> but creates a deep copy the <see
        /// cref="MultiKeyedList{TKey, TValue}"/> by invoking <see cref="ICloneable.Clone"/> on all
        /// <typeparamref name="TValue"/> elements.
        /// </para><para>
        /// <b>Copy</b> preserves the values of the <see cref="ListEx{T}.IsUnique"/> and <see
        /// cref="KeyConverter"/> properties, but not the values of the <see
        /// cref="ListEx{T}.IsFixedSize"/> and <see cref="ListEx{T}.IsReadOnly"/> properties.
        /// </para></remarks>

        public new MultiKeyedList <TKey, TValue> Copy()
        {
            int count = InnerList.Count;
            var copy  = new MultiKeyedList <TKey, TValue>(count, _keyConverter, UniqueFlag);

            for (int i = 0; i < count; i++)
            {
                TValue value = InnerList[i];

                ICloneable cloneable = (ICloneable)value;
                if (cloneable != null)
                {
                    value = (TValue)cloneable.Clone();
                }

                copy.InnerList.Add(value);
            }

            return(copy);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MultiKeyedList{TKey, TValue}"/> class that
        /// is a read-only view of the specified instance.</summary>
        /// <param name="list">
        /// The <see cref="MultiKeyedList{TKey, TValue}"/> collection that provides the initial
        /// values for the <see cref="ListEx{T}.InnerList"/> and <see cref="ListEx{T}.IsUnique"/>
        /// fields and for the <see cref="KeyConverter"/> property.</param>
        /// <param name="readOnly">
        /// The initial value for the <see cref="ListEx{T}.IsReadOnly"/> property. This argument
        /// must be <c>true</c>.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="list"/> is a null reference.</exception>
        /// <exception cref="InvalidOperationException">
        /// <paramref name="readOnly"/> is <c>false</c>.</exception>
        /// <remarks>
        /// This constructor is used to create a read-only wrapper around an existing collection.
        /// The new instance shares the data of the specified <paramref name="list"/>.</remarks>

        protected MultiKeyedList(MultiKeyedList <TKey, TValue> list, bool readOnly) :
            base(list, readOnly)
        {
            _keyConverter = list._keyConverter;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MultiKeyedList{TKey, TValue}"/> class that
        /// contains elements copied from the specified instance and has sufficient capacity to
        /// accommodate the number of elements copied.</summary>
        /// <param name="list">
        /// The <see cref="MultiKeyedList{TKey, TValue}"/> collection whose elements are copied to
        /// the new collection.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="list"/> is a null reference.</exception>
        /// <remarks>
        /// Please refer to <see cref="List{T}(IEnumerable{T})"/> for details. This constructor also
        /// copies the values of the <see cref="ListEx{T}.IsUnique"/> and <see cref="KeyConverter"/>
        /// properties.</remarks>

        public MultiKeyedList(MultiKeyedList <TKey, TValue> list) : base(list)
        {
            _keyConverter = list._keyConverter;
        }