Extends NameValueCollection to provide a read-only option.
Inheritance: System.Collections.Specialized.NameValueCollection
Ejemplo n.º 1
0
 /// <summary>
 /// Creates a copy of the current instance that is read-only.
 /// <seealso cref="IsReadOnly"/>
 /// </summary>
 /// <returns>A read-only instance.</returns>
 public NameValueCollectionEx ToReadOnly()
 {
     NameValueCollectionEx result = new NameValueCollectionEx();
     result.Add(this);
     result.IsReadOnly = true;
     return result;
 }
Ejemplo n.º 2
0
 public void ToReadOnlyTest()
 {
     NameValueCollectionEx target = new NameValueCollectionEx();
     target.Add("name", "value");
     NameValueCollectionEx actual = target.ToReadOnly();
     actual.Add("exception", "here");
 }
        /// <summary>
        /// Creates a copy of the current instance that is read-only.
        /// </summary>
        /// <param name="value">Specifies the collection to convert to read-only.</param>
        /// <returns>A read-only instance.</returns>
        public static NameValueCollection ToReadOnly(this NameValueCollection value)
        {
            Contract.Requires<ArgumentNullException>(value != null, "value is null.");

            NameValueCollectionEx result = new NameValueCollectionEx();
            result.Add(value);
            return result.ToReadOnly();
        }
        /// <summary>
        /// Creates a copy of the current instance that is read-only.
        /// </summary>
        /// <param name="value">Specifies the collection to convert to read-only.</param>
        /// <returns>A read-only instance.</returns>
        public static NameValueCollection ToReadOnly(this NameValueCollection value)
        {
            if (value == null)
                throw new ArgumentNullException("value", "value is null.");

            NameValueCollectionEx result = new NameValueCollectionEx();
            result.Add(value);
            return result.ToReadOnly();
        }