1 //------------------------------------------------------------------------------
2 // <copyright file="HttpListenerPrefixCollection.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //------------------------------------------------------------------------------
9 using System.Collections;
10 using System.Collections.Generic;
12 internal class ListenerPrefixEnumerator:IEnumerator<string>{
13 IEnumerator enumerator;
15 internal ListenerPrefixEnumerator(IEnumerator enumerator){
16 this.enumerator = enumerator;
19 public string Current{
21 return (string)enumerator.Current;
24 public bool MoveNext(){
25 return enumerator.MoveNext();
28 public void Dispose(){
31 void System.Collections.IEnumerator.Reset(){
35 object System.Collections.IEnumerator.Current{
37 return enumerator.Current;
43 public class HttpListenerPrefixCollection : ICollection<string> {
44 private HttpListener m_HttpListener;
46 internal HttpListenerPrefixCollection(HttpListener listener) {
47 m_HttpListener = listener;
50 public void CopyTo(Array array, int offset) {
51 m_HttpListener.CheckDisposed();
52 if (Count>array.Length) {
53 throw new ArgumentOutOfRangeException("array", SR.GetString(SR.net_array_too_small));
55 if (offset+Count>array.Length) {
56 throw new ArgumentOutOfRangeException("offset");
59 foreach (string uriPrefix in m_HttpListener.m_UriPrefixes.Keys) {
60 array.SetValue(uriPrefix, offset + index++);
64 public void CopyTo(string[] array, int offset) {
65 m_HttpListener.CheckDisposed();
66 if (Count>array.Length) {
67 throw new ArgumentOutOfRangeException("array", SR.GetString(SR.net_array_too_small));
69 if (offset+Count>array.Length) {
70 throw new ArgumentOutOfRangeException("offset");
73 foreach (string uriPrefix in m_HttpListener.m_UriPrefixes.Keys) {
74 array[offset + index++] = uriPrefix;
80 return m_HttpListener.m_UriPrefixes.Count;
83 public bool IsSynchronized {
89 public bool IsReadOnly {
95 public void Add(string uriPrefix) {
96 m_HttpListener.AddPrefix(uriPrefix);
99 public bool Contains(string uriPrefix) {
100 return m_HttpListener.m_UriPrefixes.Contains(uriPrefix);
103 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
104 return this.GetEnumerator();
107 public IEnumerator<string> GetEnumerator() {
108 return new ListenerPrefixEnumerator(m_HttpListener.m_UriPrefixes.Keys.GetEnumerator());
111 public bool Remove(string uriPrefix) {
112 return m_HttpListener.RemovePrefix(uriPrefix);
115 public void Clear() {
116 m_HttpListener.RemoveAll(true);