@@ -24,10 +24,14 @@ public static class ObservableGroupedCollectionExtensions
24
24
/// <param name="source">The source <see cref="ObservableGroupedCollection{TKey, TElement}"/> instance.</param>
25
25
/// <param name="key">The key of the group to query.</param>
26
26
/// <returns>The first group matching <paramref name="key"/>.</returns>
27
+ /// <exception cref="ArgumentNullException">Thrown if <paramref name="source"/> or <paramref name="key"/> are <see langword="null"/>.</exception>
27
28
/// <exception cref="InvalidOperationException">The target group does not exist.</exception>
28
29
public static ObservableGroup < TKey , TElement > FirstGroupByKey < TKey , TElement > ( this ObservableGroupedCollection < TKey , TElement > source , TKey key )
29
30
where TKey : notnull
30
31
{
32
+ ArgumentNullException . ThrowIfNull ( source ) ;
33
+ ArgumentNullException . For < TKey > . ThrowIfNull ( key ) ;
34
+
31
35
ObservableGroup < TKey , TElement > ? group = source . FirstGroupByKeyOrDefault ( key ) ;
32
36
33
37
if ( group is null )
@@ -52,9 +56,13 @@ static void ThrowArgumentExceptionForKeyNotFound()
52
56
/// <param name="source">The source <see cref="ObservableGroupedCollection{TKey, TElement}"/> instance.</param>
53
57
/// <param name="key">The key of the group to query.</param>
54
58
/// <returns>The first group matching <paramref name="key"/> or null.</returns>
59
+ /// <exception cref="ArgumentNullException">Thrown if <paramref name="source"/> or <paramref name="key"/> are <see langword="null"/>.</exception>
55
60
public static ObservableGroup < TKey , TElement > ? FirstGroupByKeyOrDefault < TKey , TElement > ( this ObservableGroupedCollection < TKey , TElement > source , TKey key )
56
61
where TKey : notnull
57
62
{
63
+ ArgumentNullException . ThrowIfNull ( source ) ;
64
+ ArgumentNullException . For < TKey > . ThrowIfNull ( key ) ;
65
+
58
66
if ( source . TryGetList ( out List < ObservableGroup < TKey , TElement > > ? list ) )
59
67
{
60
68
foreach ( ObservableGroup < TKey , TElement > ? group in list )
@@ -85,9 +93,13 @@ static void ThrowArgumentExceptionForKeyNotFound()
85
93
/// <param name="source">The source <see cref="ObservableGroupedCollection{TKey, TElement}"/> instance.</param>
86
94
/// <param name="key">The key of the group to add.</param>
87
95
/// <returns>The added <see cref="ObservableGroup{TKey, TValue}"/>.</returns>
96
+ /// <exception cref="ArgumentNullException">Thrown if <paramref name="source"/> or <paramref name="key"/> are <see langword="null"/>.</exception>
88
97
public static ObservableGroup < TKey , TElement > AddGroup < TKey , TElement > ( this ObservableGroupedCollection < TKey , TElement > source , TKey key )
89
98
where TKey : notnull
90
99
{
100
+ ArgumentNullException . ThrowIfNull ( source ) ;
101
+ ArgumentNullException . For < TKey > . ThrowIfNull ( key ) ;
102
+
91
103
ObservableGroup < TKey , TElement > group = new ( key ) ;
92
104
93
105
source . Add ( group ) ;
@@ -103,9 +115,13 @@ public static ObservableGroup<TKey, TElement> AddGroup<TKey, TElement>(this Obse
103
115
/// <param name="source">The source <see cref="ObservableGroupedCollection{TKey, TElement}"/> instance.</param>
104
116
/// <param name="grouping">The group of items to add.</param>
105
117
/// <returns>The added <see cref="ObservableGroup{TKey, TValue}"/>.</returns>
118
+ /// <exception cref="ArgumentNullException">Thrown if <paramref name="source"/> or <paramref name="grouping"/> are <see langword="null"/>.</exception>
106
119
public static ObservableGroup < TKey , TElement > AddGroup < TKey , TElement > ( this ObservableGroupedCollection < TKey , TElement > source , IGrouping < TKey , TElement > grouping )
107
120
where TKey : notnull
108
121
{
122
+ ArgumentNullException . ThrowIfNull ( source ) ;
123
+ ArgumentNullException . ThrowIfNull ( grouping ) ;
124
+
109
125
ObservableGroup < TKey , TElement > group = new ( grouping ) ;
110
126
111
127
source . Add ( group ) ;
@@ -122,9 +138,14 @@ public static ObservableGroup<TKey, TElement> AddGroup<TKey, TElement>(this Obse
122
138
/// <param name="key">The key of the group where <paramref name="collection"/> will be added.</param>
123
139
/// <param name="collection">The collection to add.</param>
124
140
/// <returns>The added <see cref="ObservableGroup{TKey, TElement}"/>.</returns>
141
+ /// <exception cref="ArgumentNullException">Thrown if <paramref name="source"/>, <paramref name="key"/> or <paramref name="collection"/> are <see langword="null"/>.</exception>
125
142
public static ObservableGroup < TKey , TElement > AddGroup < TKey , TElement > ( this ObservableGroupedCollection < TKey , TElement > source , TKey key , IEnumerable < TElement > collection )
126
143
where TKey : notnull
127
144
{
145
+ ArgumentNullException . ThrowIfNull ( source ) ;
146
+ ArgumentNullException . For < TKey > . ThrowIfNull ( key ) ;
147
+ ArgumentNullException . ThrowIfNull ( collection ) ;
148
+
128
149
ObservableGroup < TKey , TElement > group = new ( key , collection ) ;
129
150
130
151
source . Add ( group ) ;
@@ -140,9 +161,13 @@ public static ObservableGroup<TKey, TElement> AddGroup<TKey, TElement>(this Obse
140
161
/// <param name="source">The source <see cref="ObservableGroupedCollection{TKey, TElement}"/> instance.</param>
141
162
/// <param name="key">The key of the group to add.</param>
142
163
/// <returns>The added <see cref="ObservableGroup{TKey, TValue}"/>.</returns>
164
+ /// <exception cref="ArgumentNullException">Thrown if <paramref name="source"/> or <paramref name="key"/> are <see langword="null"/>.</exception>
143
165
public static ObservableGroup < TKey , TElement > InsertGroup < TKey , TElement > ( this ObservableGroupedCollection < TKey , TElement > source , TKey key )
144
166
where TKey : notnull
145
167
{
168
+ ArgumentNullException . ThrowIfNull ( source ) ;
169
+ ArgumentNullException . For < TKey > . ThrowIfNull ( key ) ;
170
+
146
171
if ( source . TryGetList ( out List < ObservableGroup < TKey , TElement > > ? list ) )
147
172
{
148
173
int index = 0 ;
@@ -197,9 +222,13 @@ static ObservableGroup<TKey, TElement> InsertGroupFallback(ObservableGroupedColl
197
222
/// <param name="source">The source <see cref="ObservableGroupedCollection{TKey, TElement}"/> instance.</param>
198
223
/// <param name="grouping">The group of items to add.</param>
199
224
/// <returns>The added <see cref="ObservableGroup{TKey, TValue}"/>.</returns>
225
+ /// <exception cref="ArgumentNullException">Thrown if <paramref name="source"/> or <paramref name="grouping"/> are <see langword="null"/>.</exception>
200
226
public static ObservableGroup < TKey , TElement > InsertGroup < TKey , TElement > ( this ObservableGroupedCollection < TKey , TElement > source , IGrouping < TKey , TElement > grouping )
201
227
where TKey : notnull
202
228
{
229
+ ArgumentNullException . ThrowIfNull ( source ) ;
230
+ ArgumentNullException . ThrowIfNull ( grouping ) ;
231
+
203
232
if ( source . TryGetList ( out List < ObservableGroup < TKey , TElement > > ? list ) )
204
233
{
205
234
int index = 0 ;
@@ -255,9 +284,14 @@ static ObservableGroup<TKey, TElement> InsertGroupFallback(ObservableGroupedColl
255
284
/// <param name="key">The key of the group where <paramref name="collection"/> will be added.</param>
256
285
/// <param name="collection">The collection to add.</param>
257
286
/// <returns>The added <see cref="ObservableGroup{TKey, TValue}"/>.</returns>
287
+ /// <exception cref="ArgumentNullException">Thrown if <paramref name="source"/>, <paramref name="key"/> or <paramref name="collection"/> are <see langword="null"/>.</exception>
258
288
public static ObservableGroup < TKey , TElement > InsertGroup < TKey , TElement > ( this ObservableGroupedCollection < TKey , TElement > source , TKey key , IEnumerable < TElement > collection )
259
289
where TKey : notnull
260
290
{
291
+ ArgumentNullException . ThrowIfNull ( source ) ;
292
+ ArgumentNullException . For < TKey > . ThrowIfNull ( key ) ;
293
+ ArgumentNullException . ThrowIfNull ( collection ) ;
294
+
261
295
if ( source . TryGetList ( out List < ObservableGroup < TKey , TElement > > ? list ) )
262
296
{
263
297
int index = 0 ;
@@ -313,9 +347,14 @@ static ObservableGroup<TKey, TElement> InsertGroupFallback(ObservableGroupedColl
313
347
/// <param name="key">The key of the group to add.</param>
314
348
/// <param name="comparer">The <see cref="IComparer{T}"/> instance to insert <typeparamref name="TKey"/> at the right position.</param>
315
349
/// <returns>The added <see cref="ObservableGroup{TKey, TValue}"/>.</returns>
350
+ /// <exception cref="ArgumentNullException">Thrown if <paramref name="source"/>, <paramref name="key"/> or <paramref name="comparer"/> are <see langword="null"/>.</exception>
316
351
public static ObservableGroup < TKey , TElement > InsertGroup < TKey , TElement > ( this ObservableGroupedCollection < TKey , TElement > source , TKey key , IComparer < TKey > comparer )
317
352
where TKey : notnull
318
353
{
354
+ ArgumentNullException . ThrowIfNull ( source ) ;
355
+ ArgumentNullException . For < TKey > . ThrowIfNull ( key ) ;
356
+ ArgumentNullException . ThrowIfNull ( comparer ) ;
357
+
319
358
if ( source . TryGetList ( out List < ObservableGroup < TKey , TElement > > ? list ) )
320
359
{
321
360
int index = 0 ;
@@ -371,9 +410,14 @@ static ObservableGroup<TKey, TElement> InsertGroupFallback(ObservableGroupedColl
371
410
/// <param name="grouping">The group of items to add.</param>
372
411
/// <param name="comparer">The <see cref="IComparer{T}"/> instance to insert <typeparamref name="TKey"/> at the right position.</param>
373
412
/// <returns>The added <see cref="ObservableGroup{TKey, TValue}"/>.</returns>
413
+ /// <exception cref="ArgumentNullException">Thrown if <paramref name="source"/>, <paramref name="grouping"/> or <paramref name="comparer"/> are <see langword="null"/>.</exception>
374
414
public static ObservableGroup < TKey , TElement > InsertGroup < TKey , TElement > ( this ObservableGroupedCollection < TKey , TElement > source , IGrouping < TKey , TElement > grouping , IComparer < TKey > comparer )
375
415
where TKey : notnull
376
416
{
417
+ ArgumentNullException . ThrowIfNull ( source ) ;
418
+ ArgumentNullException . ThrowIfNull ( grouping ) ;
419
+ ArgumentNullException . ThrowIfNull ( comparer ) ;
420
+
377
421
if ( source . TryGetList ( out List < ObservableGroup < TKey , TElement > > ? list ) )
378
422
{
379
423
int index = 0 ;
@@ -430,9 +474,15 @@ static ObservableGroup<TKey, TElement> InsertGroupFallback(ObservableGroupedColl
430
474
/// <param name="comparer">The <see cref="IComparer{T}"/> instance to insert <typeparamref name="TKey"/> at the right position.</param>
431
475
/// <param name="collection">The collection to add.</param>
432
476
/// <returns>The added <see cref="ObservableGroup{TKey, TValue}"/>.</returns>
477
+ /// <exception cref="ArgumentNullException">Thrown if <paramref name="source"/>, <paramref name="key"/>, <paramref name="comparer"/> or <paramref name="collection"/> are <see langword="null"/>.</exception>
433
478
public static ObservableGroup < TKey , TElement > InsertGroup < TKey , TElement > ( this ObservableGroupedCollection < TKey , TElement > source , TKey key , IComparer < TKey > comparer , IEnumerable < TElement > collection )
434
479
where TKey : notnull
435
480
{
481
+ ArgumentNullException . ThrowIfNull ( source ) ;
482
+ ArgumentNullException . For < TKey > . ThrowIfNull ( key ) ;
483
+ ArgumentNullException . ThrowIfNull ( comparer ) ;
484
+ ArgumentNullException . ThrowIfNull ( collection ) ;
485
+
436
486
if ( source . TryGetList ( out List < ObservableGroup < TKey , TElement > > ? list ) )
437
487
{
438
488
int index = 0 ;
@@ -489,9 +539,13 @@ static ObservableGroup<TKey, TElement> InsertGroupFallback(ObservableGroupedColl
489
539
/// <param name="key">The key of the group where the <paramref name="item"/> should be added.</param>
490
540
/// <param name="item">The item to add.</param>
491
541
/// <returns>The instance of the <see cref="ObservableGroup{TKey, TElement}"/> which will receive the value. It will either be an existing group or a new group.</returns>
542
+ /// <exception cref="ArgumentNullException">Thrown if <paramref name="source"/> or <paramref name="key"/> are <see langword="null"/>.</exception>
492
543
public static ObservableGroup < TKey , TElement > AddItem < TKey , TElement > ( this ObservableGroupedCollection < TKey , TElement > source , TKey key , TElement item )
493
544
where TKey : notnull
494
545
{
546
+ ArgumentNullException . ThrowIfNull ( source ) ;
547
+ ArgumentNullException . For < TKey > . ThrowIfNull ( key ) ;
548
+
495
549
ObservableGroup < TKey , TElement > ? group = source . FirstGroupByKeyOrDefault ( key ) ;
496
550
497
551
if ( group is null )
@@ -517,9 +571,13 @@ public static ObservableGroup<TKey, TElement> AddItem<TKey, TElement>(this Obser
517
571
/// <param name="key">The key of the group where to insert <paramref name="item"/>.</param>
518
572
/// <param name="item">The item to add.</param>
519
573
/// <returns>The instance of the <see cref="ObservableGroup{TKey, TElement}"/> which will receive the value.</returns>
574
+ /// <exception cref="ArgumentNullException">Thrown if <paramref name="source"/> or <paramref name="key"/> are <see langword="null"/>.</exception>
520
575
public static ObservableGroup < TKey , TElement > InsertItem < TKey , TElement > ( this ObservableGroupedCollection < TKey , TElement > source , TKey key , TElement item )
521
576
where TKey : notnull
522
577
{
578
+ ArgumentNullException . ThrowIfNull ( source ) ;
579
+ ArgumentNullException . For < TKey > . ThrowIfNull ( key ) ;
580
+
523
581
ObservableGroup < TKey , TElement > ? group = source . FirstGroupByKeyOrDefault ( key ) ;
524
582
525
583
if ( group is null )
@@ -580,6 +638,7 @@ static void InsertItemFallback(ObservableCollection<TElement> source, TElement i
580
638
/// <param name="item">The item to add.</param>
581
639
/// <param name="itemComparer">The <see cref="IComparer{T}"/> instance to compare elements.</param>
582
640
/// <returns>The instance of the <see cref="ObservableGroup{TKey, TElement}"/> which will receive the value.</returns>
641
+ /// <exception cref="ArgumentNullException">Thrown if <paramref name="source"/>, <paramref name="key"/>, <paramref name="keyComparer"/> or <paramref name="itemComparer"/> are <see langword="null"/>.</exception>
583
642
public static ObservableGroup < TKey , TElement > InsertItem < TKey , TElement > (
584
643
this ObservableGroupedCollection < TKey , TElement > source ,
585
644
TKey key ,
@@ -588,6 +647,11 @@ public static ObservableGroup<TKey, TElement> InsertItem<TKey, TElement>(
588
647
IComparer < TElement > itemComparer )
589
648
where TKey : notnull
590
649
{
650
+ ArgumentNullException . ThrowIfNull ( source ) ;
651
+ ArgumentNullException . For < TKey > . ThrowIfNull ( key ) ;
652
+ ArgumentNullException . ThrowIfNull ( keyComparer ) ;
653
+ ArgumentNullException . ThrowIfNull ( itemComparer ) ;
654
+
591
655
ObservableGroup < TKey , TElement > ? group = source . FirstGroupByKeyOrDefault ( key ) ;
592
656
593
657
if ( group is null )
@@ -645,9 +709,13 @@ static void InsertItemFallback(ObservableCollection<TElement> source, TElement i
645
709
/// <typeparam name="TValue">The type of the items in the collection.</typeparam>
646
710
/// <param name="source">The source <see cref="ObservableGroupedCollection{TKey, TValue}"/> instance.</param>
647
711
/// <param name="key">The key of the group to remove.</param>
712
+ /// <exception cref="ArgumentNullException">Thrown if <paramref name="source"/> or <paramref name="key"/> are <see langword="null"/>.</exception>
648
713
public static void RemoveGroup < TKey , TValue > ( this ObservableGroupedCollection < TKey , TValue > source , TKey key )
649
714
where TKey : notnull
650
715
{
716
+ ArgumentNullException . ThrowIfNull ( source ) ;
717
+ ArgumentNullException . For < TKey > . ThrowIfNull ( key ) ;
718
+
651
719
if ( source . TryGetList ( out List < ObservableGroup < TKey , TValue > > ? list ) )
652
720
{
653
721
int index = 0 ;
@@ -697,9 +765,13 @@ static void RemoveGroupFallback(ObservableGroupedCollection<TKey, TValue> source
697
765
/// <param name="key">The key of the group where the <paramref name="item"/> should be removed.</param>
698
766
/// <param name="item">The item to remove.</param>
699
767
/// <param name="removeGroupIfEmpty">If true (default value), the group will be removed once it becomes empty.</param>
768
+ /// <exception cref="ArgumentNullException">Thrown if <paramref name="source"/> or <paramref name="key"/> are <see langword="null"/>.</exception>
700
769
public static void RemoveItem < TKey , TValue > ( this ObservableGroupedCollection < TKey , TValue > source , TKey key , TValue item , bool removeGroupIfEmpty = true )
701
770
where TKey : notnull
702
771
{
772
+ ArgumentNullException . ThrowIfNull ( source ) ;
773
+ ArgumentNullException . For < TKey > . ThrowIfNull ( key ) ;
774
+
703
775
if ( source . TryGetList ( out List < ObservableGroup < TKey , TValue > > ? list ) )
704
776
{
705
777
int index = 0 ;
0 commit comments