Refactored HttpListenerPrefixCollection.cs

This commit is contained in:
sta 2014-04-12 17:59:40 +09:00
parent 93d4c77a4b
commit 99f7c9616e

View File

@ -1,32 +1,41 @@
//
// HttpListenerPrefixCollection.cs
// Copied from System.Net.HttpListenerPrefixCollection.cs
//
// Author:
// Gonzalo Paniagua Javier (gonzalo@novell.com)
//
// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
// Copyright (c) 2012-2013 sta.blockhead
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#region License
/*
* HttpListenerPrefixCollection.cs
*
* This code is derived from System.Net.HttpListenerPrefixCollection.cs of Mono
* (http://www.mono-project.com).
*
* The MIT License
*
* Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
* Copyright (c) 2012-2014 sta.blockhead
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#endregion
#region Authors
/*
* Authors:
* - Gonzalo Paniagua Javier <gonzalo@novell.com>
*/
#endregion
using System;
using System.Collections;
@ -37,7 +46,12 @@ namespace WebSocketSharp.Net
/// <summary>
/// Provides the collection used to store the URI prefixes for the <see cref="HttpListener"/>.
/// </summary>
public class HttpListenerPrefixCollection : ICollection<string>, IEnumerable<string>, IEnumerable
/// <remarks>
/// The <see cref="HttpListener"/> responds to the request which has a requested URI that
/// the prefixes most closely match.
/// </remarks>
public class HttpListenerPrefixCollection
: ICollection<string>, IEnumerable<string>, IEnumerable
{
#region Private Fields
@ -71,7 +85,7 @@ namespace WebSocketSharp.Net
/// Gets the number of prefixes contained in the <see cref="HttpListenerPrefixCollection"/>.
/// </summary>
/// <value>
/// A <see cref="int"/> that contains the number of prefixes.
/// An <see cref="int"/> that represents the number of prefixes.
/// </value>
public int Count {
get {
@ -80,7 +94,7 @@ namespace WebSocketSharp.Net
}
/// <summary>
/// Gets a value indicating whether access to the <see cref="HttpListenerPrefixCollection"/>
/// Gets a value indicating whether the access to the <see cref="HttpListenerPrefixCollection"/>
/// is read-only.
/// </summary>
/// <value>
@ -93,7 +107,7 @@ namespace WebSocketSharp.Net
}
/// <summary>
/// Gets a value indicating whether access to the <see cref="HttpListenerPrefixCollection"/>
/// Gets a value indicating whether the access to the <see cref="HttpListenerPrefixCollection"/>
/// is synchronized.
/// </summary>
/// <value>
@ -110,10 +124,13 @@ namespace WebSocketSharp.Net
#region Public Methods
/// <summary>
/// Adds the specified <paramref name="uriPrefix"/> to the <see cref="HttpListenerPrefixCollection"/>.
/// Adds the specified <paramref name="uriPrefix"/> to
/// the <see cref="HttpListenerPrefixCollection"/>.
/// </summary>
/// <param name="uriPrefix">
/// A <see cref="string"/> that contains a URI prefix to add.
/// 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 <c>"/"</c>.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="uriPrefix"/> is <see langword="null"/>.
@ -122,8 +139,8 @@ namespace WebSocketSharp.Net
/// <paramref name="uriPrefix"/> is invalid.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The <see cref="HttpListener"/> associated with this <see cref="HttpListenerPrefixCollection"/>
/// is closed.
/// The <see cref="HttpListener"/> associated with
/// this <see cref="HttpListenerPrefixCollection"/> is closed.
/// </exception>
public void Add (string uriPrefix)
{
@ -141,8 +158,8 @@ namespace WebSocketSharp.Net
/// Removes all URI prefixes from the <see cref="HttpListenerPrefixCollection"/>.
/// </summary>
/// <exception cref="ObjectDisposedException">
/// The <see cref="HttpListener"/> associated with this <see cref="HttpListenerPrefixCollection"/>
/// is closed.
/// The <see cref="HttpListener"/> associated with
/// this <see cref="HttpListenerPrefixCollection"/> is closed.
/// </exception>
public void Clear ()
{
@ -157,18 +174,18 @@ namespace WebSocketSharp.Net
/// the specified <paramref name="uriPrefix"/>.
/// </summary>
/// <returns>
/// <c>true</c> if the <see cref="HttpListenerPrefixCollection"/> contains <paramref name="uriPrefix"/>;
/// otherwise, <c>false</c>.
/// <c>true</c> if the <see cref="HttpListenerPrefixCollection"/> contains
/// <paramref name="uriPrefix"/>; otherwise, <c>false</c>.
/// </returns>
/// <param name="uriPrefix">
/// A <see cref="string"/> that contains a URI prefix to test.
/// A <see cref="string"/> that represents the URI prefix to test.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="uriPrefix"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The <see cref="HttpListener"/> associated with this <see cref="HttpListenerPrefixCollection"/>
/// is closed.
/// The <see cref="HttpListener"/> associated with
/// this <see cref="HttpListenerPrefixCollection"/> is closed.
/// </exception>
public bool Contains (string uriPrefix)
{
@ -184,16 +201,16 @@ namespace WebSocketSharp.Net
/// the specified <see cref="Array"/>.
/// </summary>
/// <param name="array">
/// An <see cref="Array"/> that receives the URI prefix strings
/// in the <see cref="HttpListenerPrefixCollection"/>.
/// An <see cref="Array"/> that receives the URI prefix strings in
/// the <see cref="HttpListenerPrefixCollection"/>.
/// </param>
/// <param name="offset">
/// An <see cref="int"/> that contains 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.
/// </param>
/// <exception cref="ObjectDisposedException">
/// The <see cref="HttpListener"/> associated with this <see cref="HttpListenerPrefixCollection"/>
/// is closed.
/// The <see cref="HttpListener"/> associated with
/// this <see cref="HttpListenerPrefixCollection"/> is closed.
/// </exception>
public void CopyTo (Array array, int offset)
{
@ -206,16 +223,16 @@ namespace WebSocketSharp.Net
/// the specified array of <see cref="string"/>.
/// </summary>
/// <param name="array">
/// An array of <see cref="string"/> that receives the URI prefix strings
/// in the <see cref="HttpListenerPrefixCollection"/>.
/// An array of <see cref="string"/> that receives the URI prefix strings in
/// the <see cref="HttpListenerPrefixCollection"/>.
/// </param>
/// <param name="offset">
/// An <see cref="int"/> that contains 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.
/// </param>
/// <exception cref="ObjectDisposedException">
/// The <see cref="HttpListener"/> associated with this <see cref="HttpListenerPrefixCollection"/>
/// is closed.
/// The <see cref="HttpListener"/> associated with
/// this <see cref="HttpListenerPrefixCollection"/> is closed.
/// </exception>
public void CopyTo (string [] array, int offset)
{
@ -224,11 +241,11 @@ namespace WebSocketSharp.Net
}
/// <summary>
/// Gets an object that can be used to iterate through the <see cref="HttpListenerPrefixCollection"/>.
/// Gets the enumerator used to iterate through the <see cref="HttpListenerPrefixCollection"/>.
/// </summary>
/// <returns>
/// An object that implements the IEnumerator&lt;string&gt; interface and provides access to
/// the URI prefix strings in the <see cref="HttpListenerPrefixCollection"/>.
/// An <see cref="T:System.Collections.Generic.IEnumerator{string}"/> instance used to iterate
/// through the <see cref="HttpListenerPrefixCollection"/>.
/// </returns>
public IEnumerator<string> GetEnumerator ()
{
@ -236,22 +253,22 @@ namespace WebSocketSharp.Net
}
/// <summary>
/// Removes the specified <paramref name="uriPrefix"/> from the list of prefixes
/// in the <see cref="HttpListenerPrefixCollection"/>.
/// Removes the specified <paramref name="uriPrefix"/> from the list of prefixes in
/// the <see cref="HttpListenerPrefixCollection"/>.
/// </summary>
/// <returns>
/// <c>true</c> if <paramref name="uriPrefix"/> is successfully found and removed;
/// otherwise, <c>false</c>.
/// </returns>
/// <param name="uriPrefix">
/// A <see cref="string"/> that contains a URI prefix to remove.
/// A <see cref="string"/> that represents the URI prefix to remove.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="uriPrefix"/> is <see langword="null"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// The <see cref="HttpListener"/> associated with this <see cref="HttpListenerPrefixCollection"/>
/// is closed.
/// The <see cref="HttpListener"/> associated with
/// this <see cref="HttpListenerPrefixCollection"/> is closed.
/// </exception>
public bool Remove (string uriPrefix)
{
@ -271,11 +288,11 @@ namespace WebSocketSharp.Net
#region Explicit Interface Implementation
/// <summary>
/// Gets an object that can be used to iterate through the <see cref="HttpListenerPrefixCollection"/>.
/// Gets the enumerator used to iterate through the <see cref="HttpListenerPrefixCollection"/>.
/// </summary>
/// <returns>
/// An object that implements the <see cref="IEnumerator"/> interface and provides access to
/// the URI prefix strings in the <see cref="HttpListenerPrefixCollection"/>.
/// An <see cref="IEnumerator"/> instance used to iterate through
/// the <see cref="HttpListenerPrefixCollection"/>.
/// </returns>
IEnumerator IEnumerable.GetEnumerator ()
{
@ -283,6 +300,5 @@ namespace WebSocketSharp.Net
}
#endregion
}
}