summaryrefslogtreecommitdiff
path: root/external/aspnetwebstack/src/System.Web.WebPages/UrlDataList.cs
blob: 96cd32889a637946b2f2e93a6bc0c7d27d6b71f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web.WebPages.Resources;

namespace System.Web.WebPages
{
    // Wrapper for list that lets us return empty string for non existant pieces of the Url
    internal class UrlDataList : IList<string>
    {
        private List<string> _urlData;

        public UrlDataList(string pathInfo)
        {
            if (String.IsNullOrEmpty(pathInfo))
            {
                _urlData = new List<string>();
            }
            else
            {
                _urlData = pathInfo.Split(new char[] { '/' }).ToList();
            }
        }

        public int Count
        {
            get { return _urlData.Count; }
        }

        public bool IsReadOnly
        {
            get { return true; }
        }

        public string this[int index]
        {
            get
            {
                // REVIEW: what about index < 0
                if (index >= _urlData.Count)
                {
                    return String.Empty;
                }
                return _urlData[index];
            }
            set { throw new NotSupportedException(WebPageResources.UrlData_ReadOnly); }
        }

        public int IndexOf(string item)
        {
            return _urlData.IndexOf(item);
        }

        public void Insert(int index, string item)
        {
            throw new NotSupportedException(WebPageResources.UrlData_ReadOnly);
        }

        public void RemoveAt(int index)
        {
            throw new NotSupportedException(WebPageResources.UrlData_ReadOnly);
        }

        public void Add(string item)
        {
            throw new NotSupportedException(WebPageResources.UrlData_ReadOnly);
        }

        public void Clear()
        {
            throw new NotSupportedException(WebPageResources.UrlData_ReadOnly);
        }

        public bool Contains(string item)
        {
            return _urlData.Contains(item);
        }

        public void CopyTo(string[] array, int arrayIndex)
        {
            _urlData.CopyTo(array, arrayIndex);
        }

        public bool Remove(string item)
        {
            throw new NotSupportedException(WebPageResources.UrlData_ReadOnly);
        }

        public IEnumerator<string> GetEnumerator()
        {
            return _urlData.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return _urlData.GetEnumerator();
        }
    }
}