File: ReadOnlyMetadataCollection.cs

package info (click to toggle)
mono 6.14.1%2Bds2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,282,732 kB
  • sloc: cs: 11,182,461; xml: 2,850,281; ansic: 699,123; cpp: 122,919; perl: 58,604; javascript: 30,841; asm: 21,845; makefile: 19,602; sh: 10,973; python: 4,772; pascal: 925; sql: 859; sed: 16; php: 1
file content (213 lines) | stat: -rw-r--r-- 7,692 bytes parent folder | download | duplicates (6)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
//---------------------------------------------------------------------
// <copyright file="ReadOnlyMetadataCollection.cs" company="Microsoft">
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//
// @owner       Microsoft
// @backupOwner Microsoft
//---------------------------------------------------------------------

using System.Collections;
using System.Collections.Generic;

namespace System.Data.Metadata.Edm
{
    /// <summary>
    /// Class representing a read-only wrapper around MetadataCollection
    /// </summary>
    /// <typeparam name="T">The type of items in this collection</typeparam>
    public class ReadOnlyMetadataCollection<T> : System.Collections.ObjectModel.ReadOnlyCollection<T> where T : MetadataItem
    {
        #region Constructors
        /// <summary>
        /// The constructor for constructing a read-only metadata collection to wrap another MetadataCollection.
        /// </summary>
        /// <param name="collection">The metadata collection to wrap</param>
        /// <exception cref="System.ArgumentNullException">Thrown if collection argument is null</exception>
        internal ReadOnlyMetadataCollection(IList<T> collection) : base(collection)
        {
        }
        #endregion

        #region InnerClasses
        // On the surface, this Enumerator doesn't do anything but delegating to the underlying enumerator

        /// <summary>
        /// The enumerator for MetadataCollection
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1815:OverrideEqualsAndOperatorEqualsOnValueTypes")]
        public struct Enumerator : IEnumerator<T>
        {
            /// <summary>
            /// Constructor for the enumerator
            /// </summary>
            /// <param name="collection">The collection that this enumerator should enumerate on</param>
            internal Enumerator(IList<T> collection)
            {
                _parent = collection;
                _nextIndex = 0;
                _current = null;
            }

            private int _nextIndex;
            private IList<T> _parent;
            private T _current;

            /// <summary>
            /// Gets the member at the current position
            /// </summary>
            public T Current
            {
                get
                {
                    return _current;
                }
            }

            /// <summary>
            /// Gets the member at the current position
            /// </summary>
            object IEnumerator.Current
            {
                get
                {
                    return this.Current;
                }
            }

            /// <summary>
            /// Dispose this enumerator
            /// </summary>
            public void Dispose()
            {
            }

            /// <summary>
            /// Move to the next member in the collection
            /// </summary>
            /// <returns>True if the enumerator is moved</returns>
            public bool MoveNext()
            {
                if ((uint)_nextIndex < (uint)_parent.Count)
                {
                    _current = _parent[_nextIndex];
                    _nextIndex++;
                    return true;
                }

                _current = null;
                return false;
            }

            /// <summary>
            /// Sets the enumerator to the initial position before the first member
            /// </summary>
            public void Reset()
            {
                _current = null;
                _nextIndex = 0;
            }
        }
        #endregion

        #region Properties
        /// <summary>
        /// Gets whether the collection is a readonly collection
        /// </summary>
        public bool IsReadOnly
        {
            get
            {
                return true;
            }
        }

        /// <summary>
        /// Gets an item from the collection with the given identity
        /// </summary>
        /// <param name="identity">The identity of the item to search for</param>
        /// <returns>An item from the collection</returns>
        /// <exception cref="System.ArgumentNullException">Thrown if identity argument passed in is null</exception>
        /// <exception cref="System.NotSupportedException">Thrown if setter is called</exception>
        public virtual T this[string identity]
        {
            get
            {
                return (((MetadataCollection<T>)this.Items)[identity]);
            }
        }

        /// <summary>
        /// Returns the metadata collection over which this collection is the view
        /// </summary>
        internal MetadataCollection<T> Source
        {
            get
            {
                return (MetadataCollection<T>)this.Items;
            }
        }
        #endregion

        #region Methods
        /// <summary>
        /// Gets an item from the collection with the given identity
        /// </summary>
        /// <param name="identity">The identity of the item to search for</param>
        /// <param name="ignoreCase">Whether case is ignore in the search</param>
        /// <returns>An item from the collection</returns>
        /// <exception cref="System.ArgumentNullException">Thrown if identity argument passed in is null</exception>
        /// <exception cref="System.ArgumentException">Thrown if the Collection does not have an item with the given identity</exception>
        public virtual T GetValue(string identity, bool ignoreCase)
        {
            return ((MetadataCollection<T>)this.Items).GetValue(identity, ignoreCase);
        }

        /// <summary>
        /// Determines if this collection contains an item of the given identity
        /// </summary>
        /// <param name="identity">The identity of the item to check for</param>
        /// <returns>True if the collection contains the item with the given identity</returns>
        /// <exception cref="System.ArgumentNullException">Thrown if identity argument passed in is null</exception>
        /// <exception cref="System.ArgumentException">Thrown if identity argument passed in is empty string</exception>
        public virtual bool Contains(string identity)
        {
            return ((MetadataCollection<T>)this.Items).ContainsIdentity(identity);
        }

        /// <summary>
        /// Gets an item from the collection with the given identity
        /// </summary>
        /// <param name="identity">The identity of the item to search for</param>
        /// <param name="ignoreCase">Whether case is ignored in the search</param>
        /// <param name="item">An item from the collection, null if the item is not found</param>
        /// <returns>True an item is retrieved</returns>
        /// <exception cref="System.ArgumentNullException">if identity argument is null</exception>
        public virtual bool TryGetValue(string identity, bool ignoreCase, out T item)
        {
            return ((MetadataCollection<T>)this.Items).TryGetValue(identity, ignoreCase, out item);
        }


        /// <summary>
        /// Gets the enumerator over this collection
        /// </summary>
        /// <returns></returns>
        public new Enumerator GetEnumerator()
        {
            return new Enumerator(this.Items);
        }

        /// <summary>
        /// Workaround for bug 
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public new virtual int IndexOf(T value)
        {
            return base.IndexOf(value);
        }

        #endregion
    }
}