@@ -15,6 +15,8 @@ namespace CodeJam.Collections
1515{
1616 partial class EnumerableExtensions
1717 {
18+ private const string _arrayTooShortMsg = "The array is too short." ;
19+ private const string _listTooShortMsg = "The list is too short." ;
1820 private const string _enumTooShortMsg = "The enumerable is too short." ;
1921
2022 /// <summary>
@@ -27,6 +29,7 @@ public static void Deconstruct<T>(
2729 out T item2 )
2830 {
2931 Code . NotNull ( array , nameof ( array ) ) ;
32+ Code . AssertArgument ( array . Length >= 2 , nameof ( array ) , _arrayTooShortMsg ) ;
3033
3134 item1 = array [ 0 ] ;
3235 item2 = array [ 1 ] ;
@@ -42,6 +45,7 @@ public static void Deconstruct<T>(
4245 out T item2 )
4346 {
4447 Code . NotNull ( list , nameof ( list ) ) ;
48+ Code . AssertArgument ( list . Count >= 2 , nameof ( list ) , _listTooShortMsg ) ;
4549
4650 item1 = list [ 0 ] ;
4751 item2 = list [ 1 ] ;
@@ -76,6 +80,7 @@ public static void Deconstruct<T>(
7680 out T item3 )
7781 {
7882 Code . NotNull ( array , nameof ( array ) ) ;
83+ Code . AssertArgument ( array . Length >= 3 , nameof ( array ) , _arrayTooShortMsg ) ;
7984
8085 item1 = array [ 0 ] ;
8186 item2 = array [ 1 ] ;
@@ -93,6 +98,7 @@ public static void Deconstruct<T>(
9398 out T item3 )
9499 {
95100 Code . NotNull ( list , nameof ( list ) ) ;
101+ Code . AssertArgument ( list . Count >= 3 , nameof ( list ) , _listTooShortMsg ) ;
96102
97103 item1 = list [ 0 ] ;
98104 item2 = list [ 1 ] ;
@@ -132,6 +138,7 @@ public static void Deconstruct<T>(
132138 out T item4 )
133139 {
134140 Code . NotNull ( array , nameof ( array ) ) ;
141+ Code . AssertArgument ( array . Length >= 4 , nameof ( array ) , _arrayTooShortMsg ) ;
135142
136143 item1 = array [ 0 ] ;
137144 item2 = array [ 1 ] ;
@@ -151,6 +158,7 @@ public static void Deconstruct<T>(
151158 out T item4 )
152159 {
153160 Code . NotNull ( list , nameof ( list ) ) ;
161+ Code . AssertArgument ( list . Count >= 4 , nameof ( list ) , _listTooShortMsg ) ;
154162
155163 item1 = list [ 0 ] ;
156164 item2 = list [ 1 ] ;
@@ -195,6 +203,7 @@ public static void Deconstruct<T>(
195203 out T item5 )
196204 {
197205 Code . NotNull ( array , nameof ( array ) ) ;
206+ Code . AssertArgument ( array . Length >= 5 , nameof ( array ) , _arrayTooShortMsg ) ;
198207
199208 item1 = array [ 0 ] ;
200209 item2 = array [ 1 ] ;
@@ -216,6 +225,7 @@ public static void Deconstruct<T>(
216225 out T item5 )
217226 {
218227 Code . NotNull ( list , nameof ( list ) ) ;
228+ Code . AssertArgument ( list . Count >= 5 , nameof ( list ) , _listTooShortMsg ) ;
219229
220230 item1 = list [ 0 ] ;
221231 item2 = list [ 1 ] ;
@@ -265,6 +275,7 @@ public static void Deconstruct<T>(
265275 out T item6 )
266276 {
267277 Code . NotNull ( array , nameof ( array ) ) ;
278+ Code . AssertArgument ( array . Length >= 6 , nameof ( array ) , _arrayTooShortMsg ) ;
268279
269280 item1 = array [ 0 ] ;
270281 item2 = array [ 1 ] ;
@@ -288,6 +299,7 @@ public static void Deconstruct<T>(
288299 out T item6 )
289300 {
290301 Code . NotNull ( list , nameof ( list ) ) ;
302+ Code . AssertArgument ( list . Count >= 6 , nameof ( list ) , _listTooShortMsg ) ;
291303
292304 item1 = list [ 0 ] ;
293305 item2 = list [ 1 ] ;
@@ -342,6 +354,7 @@ public static void Deconstruct<T>(
342354 out T item7 )
343355 {
344356 Code . NotNull ( array , nameof ( array ) ) ;
357+ Code . AssertArgument ( array . Length >= 7 , nameof ( array ) , _arrayTooShortMsg ) ;
345358
346359 item1 = array [ 0 ] ;
347360 item2 = array [ 1 ] ;
@@ -367,6 +380,7 @@ public static void Deconstruct<T>(
367380 out T item7 )
368381 {
369382 Code . NotNull ( list , nameof ( list ) ) ;
383+ Code . AssertArgument ( list . Count >= 7 , nameof ( list ) , _listTooShortMsg ) ;
370384
371385 item1 = list [ 0 ] ;
372386 item2 = list [ 1 ] ;
@@ -426,6 +440,7 @@ public static void Deconstruct<T>(
426440 out T item8 )
427441 {
428442 Code . NotNull ( array , nameof ( array ) ) ;
443+ Code . AssertArgument ( array . Length >= 8 , nameof ( array ) , _arrayTooShortMsg ) ;
429444
430445 item1 = array [ 0 ] ;
431446 item2 = array [ 1 ] ;
@@ -453,6 +468,7 @@ public static void Deconstruct<T>(
453468 out T item8 )
454469 {
455470 Code . NotNull ( list , nameof ( list ) ) ;
471+ Code . AssertArgument ( list . Count >= 8 , nameof ( list ) , _listTooShortMsg ) ;
456472
457473 item1 = list [ 0 ] ;
458474 item2 = list [ 1 ] ;
@@ -517,6 +533,7 @@ public static void Deconstruct<T>(
517533 out T item9 )
518534 {
519535 Code . NotNull ( array , nameof ( array ) ) ;
536+ Code . AssertArgument ( array . Length >= 9 , nameof ( array ) , _arrayTooShortMsg ) ;
520537
521538 item1 = array [ 0 ] ;
522539 item2 = array [ 1 ] ;
@@ -546,6 +563,7 @@ public static void Deconstruct<T>(
546563 out T item9 )
547564 {
548565 Code . NotNull ( list , nameof ( list ) ) ;
566+ Code . AssertArgument ( list . Count >= 9 , nameof ( list ) , _listTooShortMsg ) ;
549567
550568 item1 = list [ 0 ] ;
551569 item2 = list [ 1 ] ;
@@ -615,6 +633,7 @@ public static void Deconstruct<T>(
615633 out T item10 )
616634 {
617635 Code . NotNull ( array , nameof ( array ) ) ;
636+ Code . AssertArgument ( array . Length >= 10 , nameof ( array ) , _arrayTooShortMsg ) ;
618637
619638 item1 = array [ 0 ] ;
620639 item2 = array [ 1 ] ;
@@ -646,6 +665,7 @@ public static void Deconstruct<T>(
646665 out T item10 )
647666 {
648667 Code . NotNull ( list , nameof ( list ) ) ;
668+ Code . AssertArgument ( list . Count >= 10 , nameof ( list ) , _listTooShortMsg ) ;
649669
650670 item1 = list [ 0 ] ;
651671 item2 = list [ 1 ] ;
0 commit comments