~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/mono-addins/Mono.Addins/Mono.Addins/ExtensionNodeList.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// ExtensionNodeList.cs
 
3
//
 
4
// Author:
 
5
//   Lluis Sanchez Gual
 
6
//
 
7
// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
 
8
//
 
9
// Permission is hereby granted, free of charge, to any person obtaining
 
10
// a copy of this software and associated documentation files (the
 
11
// "Software"), to deal in the Software without restriction, including
 
12
// without limitation the rights to use, copy, modify, merge, publish,
 
13
// distribute, sublicense, and/or sell copies of the Software, and to
 
14
// permit persons to whom the Software is furnished to do so, subject to
 
15
// the following conditions:
 
16
// 
 
17
// The above copyright notice and this permission notice shall be
 
18
// included in all copies or substantial portions of the Software.
 
19
// 
 
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
27
//
 
28
 
 
29
 
 
30
using System;
 
31
using System.Collections;
 
32
using System.Collections.Generic;
 
33
 
 
34
namespace Mono.Addins
 
35
{
 
36
        /// <summary>
 
37
        /// A list of extension nodes.
 
38
        /// </summary>
 
39
        public class ExtensionNodeList: IEnumerable
 
40
        {
 
41
                internal List<ExtensionNode> list;
 
42
                
 
43
                internal static ExtensionNodeList Empty = new ExtensionNodeList (new List<ExtensionNode> ());
 
44
                
 
45
                internal ExtensionNodeList (List<ExtensionNode> list)
 
46
                {
 
47
                        this.list = list;
 
48
                }
 
49
                
 
50
                /// <summary>
 
51
                /// Returns the node in the specified index.
 
52
                /// </summary>
 
53
                /// <param name="n">
 
54
                /// The index.
 
55
                /// </param>
 
56
                public ExtensionNode this [int n] {
 
57
                        get {
 
58
                                if (list == null)
 
59
                                        throw new System.IndexOutOfRangeException ();
 
60
                                else
 
61
                                        return (ExtensionNode) list [n];
 
62
                        }
 
63
                }
 
64
                
 
65
                /// <summary>
 
66
                /// Returns the node with the specified ID.
 
67
                /// </summary>
 
68
                /// <param name="id">
 
69
                /// An id.
 
70
                /// </param>
 
71
                public ExtensionNode this [string id] {
 
72
                        get {
 
73
                                if (list == null)
 
74
                                        return null;
 
75
                                else {
 
76
                                        for (int n = list.Count - 1; n >= 0; n--)
 
77
                                                if (((ExtensionNode) list [n]).Id == id)
 
78
                                                        return (ExtensionNode) list [n];
 
79
                                        return null;
 
80
                                }
 
81
                        }
 
82
                }
 
83
 
 
84
                /// <summary>
 
85
                /// Gets an enumerator which enumerates all nodes in the list
 
86
                /// </summary>
 
87
                public IEnumerator GetEnumerator () 
 
88
                {
 
89
                        if (list == null)
 
90
                                return ((IList)Type.EmptyTypes).GetEnumerator ();
 
91
                        return list.GetEnumerator ();
 
92
                }
 
93
                
 
94
                /// <summary>
 
95
                /// Number of nodes of the collection.
 
96
                /// </summary>
 
97
                public int Count {
 
98
                        get { return list == null ? 0 : list.Count; }
 
99
                }
 
100
 
 
101
                /// <summary>
 
102
                /// Copies all nodes to an array
 
103
                /// </summary>
 
104
                /// <param name='array'>
 
105
                /// The target array
 
106
                /// </param>
 
107
                /// <param name='index'>
 
108
                /// Initial index where to copy to
 
109
                /// </param>
 
110
                public void CopyTo (ExtensionNode[] array, int index)
 
111
                {
 
112
                        if (list != null)
 
113
                                list.CopyTo (array, index);
 
114
                }
 
115
        }
 
116
 
 
117
        /// <summary>
 
118
        /// A list of extension nodes.
 
119
        /// </summary>
 
120
        public class ExtensionNodeList<T>: IEnumerable, IEnumerable<T> where T: ExtensionNode
 
121
        {
 
122
                List<ExtensionNode> list;
 
123
                
 
124
                internal static ExtensionNodeList<T> Empty = new ExtensionNodeList<T> (new List<ExtensionNode> ());
 
125
                
 
126
                internal ExtensionNodeList (List<ExtensionNode> list)
 
127
                {
 
128
                        this.list = list;
 
129
                }
 
130
                
 
131
                /// <summary>
 
132
                /// Returns the node in the specified index.
 
133
                /// </summary>
 
134
                /// <param name="n">
 
135
                /// The index.
 
136
                /// </param>
 
137
                public T this [int n] {
 
138
                        get {
 
139
                                if (list == null)
 
140
                                        throw new System.IndexOutOfRangeException ();
 
141
                                else
 
142
                                        return (T) list [n];
 
143
                        }
 
144
                }
 
145
                
 
146
                /// <summary>
 
147
                /// Returns the node with the specified ID.
 
148
                /// </summary>
 
149
                /// <param name="id">
 
150
                /// An id.
 
151
                /// </param>
 
152
                public T this [string id] {
 
153
                        get {
 
154
                                if (list == null)
 
155
                                        return null;
 
156
                                else {
 
157
                                        for (int n = list.Count - 1; n >= 0; n--)
 
158
                                                if (list [n].Id == id)
 
159
                                                        return (T) list [n];
 
160
                                        return null;
 
161
                                }
 
162
                        }
 
163
                }
 
164
                
 
165
                /// <summary>
 
166
                /// Gets an enumerator which enumerates all nodes in the list
 
167
                /// </summary>
 
168
                public IEnumerator<T> GetEnumerator () 
 
169
                {
 
170
                        if (list == null)
 
171
                                yield break;
 
172
                        foreach (ExtensionNode n in list)
 
173
                                yield return (T) n;
 
174
                }
 
175
                
 
176
                IEnumerator IEnumerable.GetEnumerator () 
 
177
                {
 
178
                        if (list == null)
 
179
                                return ((IList)Type.EmptyTypes).GetEnumerator ();
 
180
                        return list.GetEnumerator ();
 
181
                }
 
182
                
 
183
                /// <summary>
 
184
                /// Number of nodes of the collection.
 
185
                /// </summary>
 
186
                public int Count {
 
187
                        get { return list == null ? 0 : list.Count; }
 
188
                }
 
189
                
 
190
                /// <summary>
 
191
                /// Copies all nodes to an array
 
192
                /// </summary>
 
193
                /// <param name='array'>
 
194
                /// The target array
 
195
                /// </param>
 
196
                /// <param name='index'>
 
197
                /// Initial index where to copy to
 
198
                /// </param>
 
199
                public void CopyTo (T[] array, int index)
 
200
                {
 
201
                        if (list != null)
 
202
                                list.CopyTo (array, index);
 
203
                }
 
204
        }
 
205
}