Adding reference source for System.Net
[mono.git] / mcs / class / referencesource / System / net / System / Net / HttpListenerPrefixCollection.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="HttpListenerPrefixCollection.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //------------------------------------------------------------------------------
6
7 namespace System.Net {
8     using System;
9     using System.Collections;
10     using System.Collections.Generic;
11
12     internal class ListenerPrefixEnumerator:IEnumerator<string>{
13         IEnumerator enumerator;
14
15         internal ListenerPrefixEnumerator(IEnumerator enumerator){
16             this.enumerator = enumerator;
17         }
18
19         public string Current{
20             get{
21                 return (string)enumerator.Current;
22             }
23         }
24         public bool MoveNext(){
25             return enumerator.MoveNext();
26         }
27
28         public void Dispose(){
29         }
30
31         void System.Collections.IEnumerator.Reset(){
32             enumerator.Reset();
33         }
34
35         object System.Collections.IEnumerator.Current{
36             get{
37                 return enumerator.Current;
38             }
39         }
40     }
41
42
43     public class HttpListenerPrefixCollection : ICollection<string> {
44         private HttpListener m_HttpListener;
45
46         internal HttpListenerPrefixCollection(HttpListener listener) {
47             m_HttpListener = listener;
48         }
49
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));
54             }
55             if (offset+Count>array.Length) {
56                 throw new ArgumentOutOfRangeException("offset");
57             }
58             int index = 0;
59             foreach (string uriPrefix in m_HttpListener.m_UriPrefixes.Keys) {
60                 array.SetValue(uriPrefix, offset + index++);
61             }
62         }
63
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));
68             }
69             if (offset+Count>array.Length) {
70                 throw new ArgumentOutOfRangeException("offset");
71             }
72             int index = 0;
73             foreach (string uriPrefix in m_HttpListener.m_UriPrefixes.Keys) {
74                 array[offset + index++] = uriPrefix;
75             }
76         }
77         
78         public int Count {
79             get {
80                 return m_HttpListener.m_UriPrefixes.Count;
81             }
82         }
83         public bool IsSynchronized {
84             get {
85                 return false;
86             }
87         }
88         
89         public bool IsReadOnly {
90             get {
91                 return false;
92             }
93         }
94
95         public void Add(string uriPrefix) {
96             m_HttpListener.AddPrefix(uriPrefix);
97         }
98
99         public bool Contains(string uriPrefix) {
100             return m_HttpListener.m_UriPrefixes.Contains(uriPrefix);
101         }
102
103         System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
104             return this.GetEnumerator();
105         }
106
107         public IEnumerator<string> GetEnumerator() {
108             return new ListenerPrefixEnumerator(m_HttpListener.m_UriPrefixes.Keys.GetEnumerator());
109         }
110
111         public bool Remove(string uriPrefix) {
112             return m_HttpListener.RemovePrefix(uriPrefix);
113         }
114
115         public void Clear() {
116             m_HttpListener.RemoveAll(true);
117         }
118     }
119 }
120