Refactored HttpListenerPrefixCollection.cs

This commit is contained in:
sta 2014-10-18 15:22:38 +09:00
parent cf82b45163
commit 0082b2d191

View File

@ -82,7 +82,7 @@ namespace WebSocketSharp.Net
#region Public Properties #region Public Properties
/// <summary> /// <summary>
/// Gets the number of prefixes contained in the <see cref="HttpListenerPrefixCollection"/>. /// Gets the number of prefixes in the collection.
/// </summary> /// </summary>
/// <value> /// <value>
/// An <see cref="int"/> that represents the number of prefixes. /// An <see cref="int"/> that represents the number of prefixes.
@ -94,8 +94,7 @@ namespace WebSocketSharp.Net
} }
/// <summary> /// <summary>
/// Gets a value indicating whether the access to the <see cref="HttpListenerPrefixCollection"/> /// Gets a value indicating whether the access to the collection is read-only.
/// is read-only.
/// </summary> /// </summary>
/// <value> /// <value>
/// Always returns <c>false</c>. /// Always returns <c>false</c>.
@ -107,8 +106,7 @@ namespace WebSocketSharp.Net
} }
/// <summary> /// <summary>
/// Gets a value indicating whether the access to the <see cref="HttpListenerPrefixCollection"/> /// Gets a value indicating whether the access to the collection is synchronized.
/// is synchronized.
/// </summary> /// </summary>
/// <value> /// <value>
/// Always returns <c>false</c>. /// Always returns <c>false</c>.
@ -124,13 +122,11 @@ namespace WebSocketSharp.Net
#region Public Methods #region Public Methods
/// <summary> /// <summary>
/// Adds the specified <paramref name="uriPrefix"/> to /// Adds the specified <paramref name="uriPrefix"/> to the collection.
/// the <see cref="HttpListenerPrefixCollection"/>.
/// </summary> /// </summary>
/// <param name="uriPrefix"> /// <param name="uriPrefix">
/// A <see cref="string"/> that represents the URI prefix to add. The prefix must be /// A <see cref="string"/> that represents the URI prefix to add. The prefix must be
/// a well-formed URI prefix with http or https scheme, and must be terminated with /// a well-formed URI prefix with http or https scheme, and must end with a <c>'/'</c>.
/// a <c>"/"</c>.
/// </param> /// </param>
/// <exception cref="ArgumentNullException"> /// <exception cref="ArgumentNullException">
/// <paramref name="uriPrefix"/> is <see langword="null"/>. /// <paramref name="uriPrefix"/> is <see langword="null"/>.
@ -139,8 +135,7 @@ namespace WebSocketSharp.Net
/// <paramref name="uriPrefix"/> is invalid. /// <paramref name="uriPrefix"/> is invalid.
/// </exception> /// </exception>
/// <exception cref="ObjectDisposedException"> /// <exception cref="ObjectDisposedException">
/// The <see cref="HttpListener"/> associated with /// The <see cref="HttpListener"/> associated with this collection is closed.
/// this <see cref="HttpListenerPrefixCollection"/> is closed.
/// </exception> /// </exception>
public void Add (string uriPrefix) public void Add (string uriPrefix)
{ {
@ -155,11 +150,10 @@ namespace WebSocketSharp.Net
} }
/// <summary> /// <summary>
/// Removes all URI prefixes from the <see cref="HttpListenerPrefixCollection"/>. /// Removes all URI prefixes from the collection.
/// </summary> /// </summary>
/// <exception cref="ObjectDisposedException"> /// <exception cref="ObjectDisposedException">
/// The <see cref="HttpListener"/> associated with /// The <see cref="HttpListener"/> associated with this collection is closed.
/// this <see cref="HttpListenerPrefixCollection"/> is closed.
/// </exception> /// </exception>
public void Clear () public void Clear ()
{ {
@ -170,12 +164,12 @@ namespace WebSocketSharp.Net
} }
/// <summary> /// <summary>
/// Returns a value indicating whether the <see cref="HttpListenerPrefixCollection"/> contains /// Returns a value indicating whether the collection contains the specified
/// the specified <paramref name="uriPrefix"/>. /// <paramref name="uriPrefix"/>.
/// </summary> /// </summary>
/// <returns> /// <returns>
/// <c>true</c> if the <see cref="HttpListenerPrefixCollection"/> contains /// <c>true</c> if the collection contains <paramref name="uriPrefix"/>;
/// <paramref name="uriPrefix"/>; otherwise, <c>false</c>. /// otherwise, <c>false</c>.
/// </returns> /// </returns>
/// <param name="uriPrefix"> /// <param name="uriPrefix">
/// A <see cref="string"/> that represents the URI prefix to test. /// A <see cref="string"/> that represents the URI prefix to test.
@ -184,8 +178,7 @@ namespace WebSocketSharp.Net
/// <paramref name="uriPrefix"/> is <see langword="null"/>. /// <paramref name="uriPrefix"/> is <see langword="null"/>.
/// </exception> /// </exception>
/// <exception cref="ObjectDisposedException"> /// <exception cref="ObjectDisposedException">
/// The <see cref="HttpListener"/> associated with /// The <see cref="HttpListener"/> associated with this collection is closed.
/// this <see cref="HttpListenerPrefixCollection"/> is closed.
/// </exception> /// </exception>
public bool Contains (string uriPrefix) public bool Contains (string uriPrefix)
{ {
@ -197,20 +190,17 @@ namespace WebSocketSharp.Net
} }
/// <summary> /// <summary>
/// Copies the contents of the <see cref="HttpListenerPrefixCollection"/> to /// Copies the contents of the collection to the specified <see cref="Array"/>.
/// the specified <see cref="Array"/>.
/// </summary> /// </summary>
/// <param name="array"> /// <param name="array">
/// An <see cref="Array"/> that receives the URI prefix strings in /// An <see cref="Array"/> that receives the URI prefix strings in the collection.
/// the <see cref="HttpListenerPrefixCollection"/>.
/// </param> /// </param>
/// <param name="offset"> /// <param name="offset">
/// An <see cref="int"/> that represents the zero-based index in <paramref name="array"/> /// An <see cref="int"/> that represents the zero-based index in <paramref name="array"/>
/// at which copying begins. /// at which copying begins.
/// </param> /// </param>
/// <exception cref="ObjectDisposedException"> /// <exception cref="ObjectDisposedException">
/// The <see cref="HttpListener"/> associated with /// The <see cref="HttpListener"/> associated with this collection is closed.
/// this <see cref="HttpListenerPrefixCollection"/> is closed.
/// </exception> /// </exception>
public void CopyTo (Array array, int offset) public void CopyTo (Array array, int offset)
{ {
@ -219,22 +209,19 @@ namespace WebSocketSharp.Net
} }
/// <summary> /// <summary>
/// Copies the contents of the <see cref="HttpListenerPrefixCollection"/> to /// Copies the contents of the collection to the specified array of <see cref="string"/>.
/// the specified array of <see cref="string"/>.
/// </summary> /// </summary>
/// <param name="array"> /// <param name="array">
/// An array of <see cref="string"/> that receives the URI prefix strings in /// An array of <see cref="string"/> that receives the URI prefix strings in the collection.
/// the <see cref="HttpListenerPrefixCollection"/>.
/// </param> /// </param>
/// <param name="offset"> /// <param name="offset">
/// An <see cref="int"/> that represents the zero-based index in <paramref name="array"/> /// An <see cref="int"/> that represents the zero-based index in <paramref name="array"/>
/// at which copying begins. /// at which copying begins.
/// </param> /// </param>
/// <exception cref="ObjectDisposedException"> /// <exception cref="ObjectDisposedException">
/// The <see cref="HttpListener"/> associated with /// The <see cref="HttpListener"/> associated with this collection is closed.
/// this <see cref="HttpListenerPrefixCollection"/> is closed.
/// </exception> /// </exception>
public void CopyTo (string [] array, int offset) public void CopyTo (string[] array, int offset)
{ {
_listener.CheckDisposed (); _listener.CheckDisposed ();
_prefixes.CopyTo (array, offset); _prefixes.CopyTo (array, offset);
@ -245,7 +232,7 @@ namespace WebSocketSharp.Net
/// </summary> /// </summary>
/// <returns> /// <returns>
/// An <see cref="T:System.Collections.Generic.IEnumerator{string}"/> instance used to iterate /// An <see cref="T:System.Collections.Generic.IEnumerator{string}"/> instance used to iterate
/// through the <see cref="HttpListenerPrefixCollection"/>. /// through the collection.
/// </returns> /// </returns>
public IEnumerator<string> GetEnumerator () public IEnumerator<string> GetEnumerator ()
{ {
@ -253,8 +240,7 @@ namespace WebSocketSharp.Net
} }
/// <summary> /// <summary>
/// Removes the specified <paramref name="uriPrefix"/> from the list of prefixes in /// Removes the specified <paramref name="uriPrefix"/> from the collection.
/// the <see cref="HttpListenerPrefixCollection"/>.
/// </summary> /// </summary>
/// <returns> /// <returns>
/// <c>true</c> if <paramref name="uriPrefix"/> is successfully found and removed; /// <c>true</c> if <paramref name="uriPrefix"/> is successfully found and removed;
@ -267,8 +253,7 @@ namespace WebSocketSharp.Net
/// <paramref name="uriPrefix"/> is <see langword="null"/>. /// <paramref name="uriPrefix"/> is <see langword="null"/>.
/// </exception> /// </exception>
/// <exception cref="ObjectDisposedException"> /// <exception cref="ObjectDisposedException">
/// The <see cref="HttpListener"/> associated with /// The <see cref="HttpListener"/> associated with this collection is closed.
/// this <see cref="HttpListenerPrefixCollection"/> is closed.
/// </exception> /// </exception>
public bool Remove (string uriPrefix) public bool Remove (string uriPrefix)
{ {
@ -276,23 +261,22 @@ namespace WebSocketSharp.Net
if (uriPrefix == null) if (uriPrefix == null)
throw new ArgumentNullException ("uriPrefix"); throw new ArgumentNullException ("uriPrefix");
var result = _prefixes.Remove (uriPrefix); var res = _prefixes.Remove (uriPrefix);
if (result && _listener.IsListening) if (res && _listener.IsListening)
EndPointManager.RemovePrefix (uriPrefix, _listener); EndPointManager.RemovePrefix (uriPrefix, _listener);
return result; return res;
} }
#endregion #endregion
#region Explicit Interface Implementation #region Explicit Interface Implementations
/// <summary> /// <summary>
/// Gets the enumerator used to iterate through the <see cref="HttpListenerPrefixCollection"/>. /// Gets the enumerator used to iterate through the <see cref="HttpListenerPrefixCollection"/>.
/// </summary> /// </summary>
/// <returns> /// <returns>
/// An <see cref="IEnumerator"/> instance used to iterate through /// An <see cref="IEnumerator"/> instance used to iterate through the collection.
/// the <see cref="HttpListenerPrefixCollection"/>.
/// </returns> /// </returns>
IEnumerator IEnumerable.GetEnumerator () IEnumerator IEnumerable.GetEnumerator ()
{ {