@@ -69,11 +69,11 @@ internal interface ICountableGrouping<TKey, TElement> : IGrouping<TKey, TElement
6969 /// <typeparam name="TKey">The type of the keys in the <see cref="Lookup{TKey, TElement}"/>.</typeparam>
7070 /// <typeparam name="TElement">The type of the elements of each value in the <see cref="Lookup{TKey, TElement}"/>.</typeparam>
7171 [ Serializable ]
72- [ DebuggerTypeProxy ( typeof ( LookupDebugView < , > ) ) ]
72+ [ DebuggerTypeProxy ( typeof ( IMutableLookupDebugView < , > ) ) ]
7373 [ DebuggerDisplay ( "Count = {Count}" ) ]
74- public class Lookup < TKey , TElement > : IMutableLookup < TKey , TElement > , IEnumerable < KeyValuePair < TKey , TElement > > , IEnumerable < Lookup < TKey , TElement > . Grouping >
74+ public class Lookup < TKey , TElement > : IMutableLookup < TKey , TElement > , IEnumerable < KeyValuePair < TKey , TElement > > , IEnumerable < Grouping < TKey , TElement > >
7575 {
76- private readonly Dictionary < TKey , Grouping > dic ;
76+ private readonly Dictionary < TKey , Grouping < TKey , TElement > > dic ;
7777 /// <summary>
7878 /// Initialize a new instance of <see cref="Lookup{TKey, TElement}"/> class.
7979 /// </summary>
@@ -101,7 +101,7 @@ public Lookup(IEqualityComparer<TKey> comparer)
101101 /// <param name="comparer">The comparer of the keys.</param>
102102 public Lookup ( int capacity , IEqualityComparer < TKey > comparer )
103103 {
104- dic = new Dictionary < TKey , Grouping > ( capacity , comparer ) ;
104+ dic = new Dictionary < TKey , Grouping < TKey , TElement > > ( capacity , comparer ) ;
105105 }
106106 /// <summary>
107107 /// Initialize a new instance of <see cref="Lookup{TKey, TElement}"/> class.
@@ -120,10 +120,10 @@ public Lookup(ILookup<TKey, TElement> lookup, IEqualityComparer<TKey> comparer)
120120 switch ( lookup ?? throw ExceptionHelper . ArgumentNull ( nameof ( lookup ) ) )
121121 {
122122 case Lookup < TKey , TElement > lkp :
123- dic = new Dictionary < TKey , Grouping > ( lkp . dic , comparer ) ;
123+ dic = new Dictionary < TKey , Grouping < TKey , TElement > > ( lkp . dic , comparer ) ;
124124 break ;
125125 default :
126- dic = new Dictionary < TKey , Grouping > ( lookup . Count , comparer ) ;
126+ dic = new Dictionary < TKey , Grouping < TKey , TElement > > ( lookup . Count , comparer ) ;
127127 foreach ( var grouping in lookup )
128128 {
129129 foreach ( var item in grouping )
@@ -145,7 +145,7 @@ public ICollection<TElement> this[TKey key]
145145 {
146146 if ( ! dic . ContainsKey ( key ) )
147147 {
148- dic [ key ] = new Grouping ( key ) ;
148+ dic [ key ] = new Grouping < TKey , TElement > ( key ) ;
149149 }
150150 return dic [ key ] ;
151151 }
@@ -167,11 +167,11 @@ public ICollection<TElement> this[TKey key]
167167 /// </summary>
168168 /// <param name="key">The specified key.</param>
169169 /// <param name="element">The specified element.</param>
170- public void Add ( TKey key , TElement element )
170+ public void Add ( TKey key , TElement element )
171171 {
172- if ( ! dic . ContainsKey ( key ) )
172+ if ( ! dic . ContainsKey ( key ) )
173173 {
174- dic [ key ] = new Grouping ( key ) ;
174+ dic [ key ] = new Grouping < TKey , TElement > ( key ) ;
175175 }
176176 dic [ key ] . AddElement ( element ) ;
177177 }
@@ -241,9 +241,9 @@ public bool TryGetElements(TKey key, out IEnumerable<TElement> elements)
241241 /// <returns>An enumerator for the <see cref="Lookup{TKey, TElement}"/>.</returns>
242242 public IEnumerator < KeyValuePair < TKey , TElement > > GetEnumerator ( )
243243 {
244- foreach ( var grouping in dic )
244+ foreach ( var grouping in dic )
245245 {
246- foreach ( var item in grouping . Value )
246+ foreach ( var item in grouping . Value )
247247 {
248248 yield return new KeyValuePair < TKey , TElement > ( grouping . Key , item ) ;
249249 }
@@ -258,7 +258,7 @@ public IEnumerator<KeyValuePair<TKey, TElement>> GetEnumerator()
258258 /// Returns a generic enumerator that iterates through the <see cref="Lookup{TKey, TElement}"/>.
259259 /// </summary>
260260 /// <returns>An enumerator for the <see cref="Lookup{TKey, TElement}"/>.</returns>
261- IEnumerator < Grouping > IEnumerable < Grouping > . GetEnumerator ( ) => GetEnumeratorInternal ( ) ;
261+ IEnumerator < Grouping < TKey , TElement > > IEnumerable < Grouping < TKey , TElement > > . GetEnumerator ( ) => GetEnumeratorInternal ( ) ;
262262 /// <summary>
263263 /// Returns an enumerator that iterates through the <see cref="Lookup{TKey, TElement}"/>. This class cannot be inherited.
264264 /// </summary>
@@ -268,107 +268,110 @@ public IEnumerator<KeyValuePair<TKey, TElement>> GetEnumerator()
268268 /// Returns a generic enumerator that iterates through the <see cref="Lookup{TKey, TElement}"/>.
269269 /// </summary>
270270 /// <returns>An enumerator for the <see cref="Lookup{TKey, TElement}"/>.</returns>
271- internal IEnumerator < Grouping > GetEnumeratorInternal ( )
271+ internal IEnumerator < Grouping < TKey , TElement > > GetEnumeratorInternal ( )
272272 {
273273 foreach ( var item in dic )
274274 {
275275 yield return item . Value ;
276276 }
277277 }
278+ }
279+ /// <summary>
280+ /// Represents a key and a sequence of elements.
281+ /// </summary>
282+ [ Serializable ]
283+ [ DebuggerTypeProxy ( typeof ( ICountableGroupingDebugView < , > ) ) ]
284+ [ DebuggerDisplay ( "Count = {Count}" ) ]
285+ internal class Grouping < TKey , TElement > : ICountableGrouping < TKey , TElement > , ICollection < TElement >
286+ {
287+ private readonly TKey key ;
288+ private readonly Collection < TElement > collection ;
278289 /// <summary>
279- /// Represents a key and a sequence of elements .
290+ /// Initialize a new instance of <see cref="Grouping{TKey, TElement}"/> class .
280291 /// </summary>
281- internal class Grouping : ICountableGrouping < TKey , TElement > , ICollection < TElement >
292+ /// <param name="key"></param>
293+ public Grouping ( TKey key )
282294 {
283- private readonly TKey key ;
284- private readonly Collection < TElement > collection ;
285- /// <summary>
286- /// Initialize a new instance of <see cref="Grouping"/> class.
287- /// </summary>
288- /// <param name="key"></param>
289- public Grouping ( TKey key )
290- {
291- this . key = key ;
292- this . collection = new Collection < TElement > ( ) ;
293- }
294- /// <summary>
295- /// The key of the <see cref="Grouping"/>.
296- /// </summary>
297- public TKey Key => key ;
298- /// <summary>
299- /// Count of the elements.
300- /// </summary>
301- public int Count => collection . Count ;
302- /// <summary>
303- /// The <see cref="Grouping"/> is not read-only.
304- /// </summary>
305- public bool IsReadOnly => true ;
306- /// <summary>
307- /// Adds element to the grouping.
308- /// </summary>
309- /// <param name="item">The specified element.</param>
310- internal void AddElement ( TElement item ) => collection . Add ( item ) ;
311- /// <summary>
312- /// This function is not supported.
313- /// </summary>
314- /// <param name="item">The specified element.</param>
315- /// <exception cref="NotSupportedException"/>
316- public void Add ( TElement item ) => throw ExceptionHelper . NotSupported ( ) ;
317- /// <summary>
318- /// Clears the elements.
319- /// </summary>
320- internal void ClearElements ( ) => collection . Clear ( ) ;
321- /// <summary>
322- /// This function is not supported.
323- /// </summary>
324- /// <exception cref="NotSupportedException"/>
325- public void Clear ( ) => throw ExceptionHelper . NotSupported ( ) ;
326- /// <summary>
327- /// Removes the specified element.
328- /// </summary>
329- /// <param name="item">The specified element.</param>
330- /// <returns><see langword="true"/> if removes successfully; otherwise, <see langword="false"/>.</returns>
331- internal bool RemoveElement ( TElement item ) => collection . Remove ( item ) ;
332- /// <summary>
333- /// This function is not supported.
334- /// </summary>
335- /// <param name="item">The specified element.</param>
336- /// <returns><see langword="true"/> if removes successfully; otherwise, <see langword="false"/>.</returns>
337- /// <exception cref="NotSupportedException"/>
338- public bool Remove ( TElement item ) => throw ExceptionHelper . NotSupported ( ) ;
339- /// <summary>
340- /// Determines whether a specified key is in the <see cref="Grouping"/>.
341- /// </summary>
342- /// <param name="item">The element to find in the <see cref="Grouping"/>.</param>
343- /// <returns><see langword="true"/> if <paramref name="item"/> is in the <see cref="Grouping"/>; otherwise, <see langword="false"/>.</returns>
344- public bool Contains ( TElement item ) => collection . Contains ( item ) ;
345- /// <summary>
346- /// Copies the entire <see cref="Collection{T}"/> to a compatible one-dimensional <see cref="Array"/>, starting at the specified index of the target array.
347- /// </summary>
348- /// <param name="array">The one-dimensional <see cref="Array"/> that is the destination of the elements copied from <see cref="Collection{T}"/>. The <see cref="Array"/> must have zero-based indexing.</param>
349- /// <param name="arrayIndex">The zero-based index in array at which copying begins.</param>
350- public void CopyTo ( TElement [ ] array , int arrayIndex )
351- {
352- if ( array == null )
353- throw ExceptionHelper . ArgumentNull ( nameof ( array ) ) ;
354- if ( arrayIndex < 0 )
355- throw ExceptionHelper . ArgumentOutOfRange ( nameof ( arrayIndex ) ) ;
356- if ( arrayIndex > array . Length )
357- throw ExceptionHelper . ArgumentOutOfRange ( nameof ( arrayIndex ) ) ;
358- if ( array . Length - arrayIndex < collection . Count )
359- throw ExceptionHelper . ArrayTooSmall ( ) ;
360- collection . CopyTo ( array , arrayIndex ) ;
361- }
362- /// <summary>
363- /// Returns a generic enumerator that iterates through the <see cref="Grouping"/>.
364- /// </summary>
365- /// <returns>An enumerator for the <see cref="Grouping"/>.</returns>
366- public IEnumerator < TElement > GetEnumerator ( ) => collection . GetEnumerator ( ) ;
367- /// <summary>
368- /// Returns a generic enumerator that iterates through the <see cref="Grouping"/>.
369- /// </summary>
370- /// <returns>An enumerator for the <see cref="Grouping"/>.</returns>
371- IEnumerator IEnumerable . GetEnumerator ( ) => GetEnumerator ( ) ;
295+ this . key = key ;
296+ this . collection = new Collection < TElement > ( ) ;
372297 }
298+ /// <summary>
299+ /// The key of the <see cref="Grouping{TKey, TElement}"/>.
300+ /// </summary>
301+ public TKey Key => key ;
302+ /// <summary>
303+ /// Count of the elements.
304+ /// </summary>
305+ public int Count => collection . Count ;
306+ /// <summary>
307+ /// The <see cref="Grouping{TKey, TElement}"/> is not read-only.
308+ /// </summary>
309+ public bool IsReadOnly => true ;
310+ /// <summary>
311+ /// Adds element to the grouping.
312+ /// </summary>
313+ /// <param name="item">The specified element.</param>
314+ internal void AddElement ( TElement item ) => collection . Add ( item ) ;
315+ /// <summary>
316+ /// This function is not supported.
317+ /// </summary>
318+ /// <param name="item">The specified element.</param>
319+ /// <exception cref="NotSupportedException"/>
320+ public void Add ( TElement item ) => throw ExceptionHelper . NotSupported ( ) ;
321+ /// <summary>
322+ /// Clears the elements.
323+ /// </summary>
324+ internal void ClearElements ( ) => collection . Clear ( ) ;
325+ /// <summary>
326+ /// This function is not supported.
327+ /// </summary>
328+ /// <exception cref="NotSupportedException"/>
329+ public void Clear ( ) => throw ExceptionHelper . NotSupported ( ) ;
330+ /// <summary>
331+ /// Removes the specified element.
332+ /// </summary>
333+ /// <param name="item">The specified element.</param>
334+ /// <returns><see langword="true"/> if removes successfully; otherwise, <see langword="false"/>.</returns>
335+ internal bool RemoveElement ( TElement item ) => collection . Remove ( item ) ;
336+ /// <summary>
337+ /// This function is not supported.
338+ /// </summary>
339+ /// <param name="item">The specified element.</param>
340+ /// <returns><see langword="true"/> if removes successfully; otherwise, <see langword="false"/>.</returns>
341+ /// <exception cref="NotSupportedException"/>
342+ public bool Remove ( TElement item ) => throw ExceptionHelper . NotSupported ( ) ;
343+ /// <summary>
344+ /// Determines whether a specified key is in the <see cref="Grouping{TKey, TElement}"/>.
345+ /// </summary>
346+ /// <param name="item">The element to find in the <see cref="Grouping{TKey, TElement}"/>.</param>
347+ /// <returns><see langword="true"/> if <paramref name="item"/> is in the <see cref="Grouping{TKey, TElement}"/>; otherwise, <see langword="false"/>.</returns>
348+ public bool Contains ( TElement item ) => collection . Contains ( item ) ;
349+ /// <summary>
350+ /// Copies the entire <see cref="Collection{T}"/> to a compatible one-dimensional <see cref="Array"/>, starting at the specified index of the target array.
351+ /// </summary>
352+ /// <param name="array">The one-dimensional <see cref="Array"/> that is the destination of the elements copied from <see cref="Collection{T}"/>. The <see cref="Array"/> must have zero-based indexing.</param>
353+ /// <param name="arrayIndex">The zero-based index in array at which copying begins.</param>
354+ public void CopyTo ( TElement [ ] array , int arrayIndex )
355+ {
356+ if ( array == null )
357+ throw ExceptionHelper . ArgumentNull ( nameof ( array ) ) ;
358+ if ( arrayIndex < 0 )
359+ throw ExceptionHelper . ArgumentOutOfRange ( nameof ( arrayIndex ) ) ;
360+ if ( arrayIndex > array . Length )
361+ throw ExceptionHelper . ArgumentOutOfRange ( nameof ( arrayIndex ) ) ;
362+ if ( array . Length - arrayIndex < collection . Count )
363+ throw ExceptionHelper . ArrayTooSmall ( ) ;
364+ collection . CopyTo ( array , arrayIndex ) ;
365+ }
366+ /// <summary>
367+ /// Returns a generic enumerator that iterates through the <see cref="Grouping{TKey, TElement}"/>.
368+ /// </summary>
369+ /// <returns>An enumerator for the <see cref="Grouping{TKey, TElement}"/>.</returns>
370+ public IEnumerator < TElement > GetEnumerator ( ) => collection . GetEnumerator ( ) ;
371+ /// <summary>
372+ /// Returns a generic enumerator that iterates through the <see cref="Grouping{TKey, TElement}"/>.
373+ /// </summary>
374+ /// <returns>An enumerator for the <see cref="Grouping{TKey, TElement}"/>.</returns>
375+ IEnumerator IEnumerable . GetEnumerator ( ) => GetEnumerator ( ) ;
373376 }
374377}
0 commit comments