Exemplo n.º 1
0
        /// <summary>
        /// Returns a read-only view of the <see cref="Int32HashSet"/>.</summary>
        /// <returns>
        /// A read-only wrapper around the <see cref="Int32HashSet"/>.</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 Int32HashSet AsReadOnly()
        {
            if (ReadOnlyWrapper == null)
            {
                ReadOnlyWrapper = new Int32HashSet(this, true);
            }

            return(ReadOnlyWrapper);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Int32HashSet"/> class that is a read-only
        /// view of the specified instance.</summary>
        /// <param name="collection">
        /// The <see cref="Int32HashSet"/> collection that is wrapped by the new instance.</param>
        /// <param name="readOnly">
        /// The initial value for the <see cref="IsReadOnly"/> property. This argument must be
        /// <c>true</c>.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="collection"/> 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="collection"/>.
        /// </remarks>

        protected Int32HashSet(Int32HashSet collection, bool readOnly)
        {
            if (collection == null)
            {
                ThrowHelper.ThrowArgumentNullException("collection");
            }

            if (!readOnly)
            {
                ThrowHelper.ThrowArgumentExceptionWithFormat(
                    "readOnly", Strings.ArgumentEquals, false);
            }

            _data           = collection._data;
            ReadOnlyFlag    = readOnly;
            ReadOnlyWrapper = this;
        }