···2233public static class ArrayDestructuringExtensions
44{
55- public static void Deconstruct<T>(this T[] array, out T item1)
55+ extension<T>(T[] array)
66 {
77- if (array.Length != 1)
88- throw new Exception("This deconstructor only takes arrays of length 1");
77+ public void Deconstruct(out T item1)
88+ {
99+ if (array.Length != 1)
1010+ throw new Exception("This deconstructor only takes arrays of length 1");
9111010- item1 = array[0];
1111- }
1212+ item1 = array[0];
1313+ }
12141313- public static void Deconstruct<T>(this T[] array, out T item1, out T item2)
1414- {
1515- if (array.Length != 2)
1616- throw new Exception("This deconstructor only takes arrays of length 2");
1515+ public void Deconstruct(out T item1, out T item2)
1616+ {
1717+ if (array.Length != 2)
1818+ throw new Exception("This deconstructor only takes arrays of length 2");
17191818- item1 = array[0];
1919- item2 = array[1];
2020- }
2020+ item1 = array[0];
2121+ item2 = array[1];
2222+ }
21232222- public static void Deconstruct<T>(this T[] array, out T item1, out T item2, out T item3)
2323- {
2424- if (array.Length != 3)
2525- throw new Exception("This deconstructor only takes arrays of length 3");
2424+ public void Deconstruct(out T item1, out T item2, out T item3)
2525+ {
2626+ if (array.Length != 3)
2727+ throw new Exception("This deconstructor only takes arrays of length 3");
26282727- item1 = array[0];
2828- item2 = array[1];
2929- item3 = array[2];
3030- }
2929+ item1 = array[0];
3030+ item2 = array[1];
3131+ item3 = array[2];
3232+ }
31333232- public static void Deconstruct<T>(this T[] array, out T item1, out T item2, out T item3, out T item4)
3333- {
3434- if (array.Length != 4)
3535- throw new Exception("This deconstructor only takes arrays of length 4");
3434+ public void Deconstruct(out T item1, out T item2, out T item3, out T item4)
3535+ {
3636+ if (array.Length != 4)
3737+ throw new Exception("This deconstructor only takes arrays of length 4");
36383737- item1 = array[0];
3838- item2 = array[1];
3939- item3 = array[2];
4040- item4 = array[3];
4141- }
3939+ item1 = array[0];
4040+ item2 = array[1];
4141+ item3 = array[2];
4242+ item4 = array[3];
4343+ }
42444343- public static void Deconstruct<T>(this T[] array, out T item1, out T item2, out T item3, out T item4, out T item5)
4444- {
4545- if (array.Length != 5)
4646- throw new Exception("This deconstructor only takes arrays of length 5");
4545+ public void Deconstruct(out T item1, out T item2, out T item3, out T item4, out T item5)
4646+ {
4747+ if (array.Length != 5)
4848+ throw new Exception("This deconstructor only takes arrays of length 5");
47494848- item1 = array[0];
4949- item2 = array[1];
5050- item3 = array[2];
5151- item4 = array[3];
5252- item5 = array[4];
5050+ item1 = array[0];
5151+ item2 = array[1];
5252+ item3 = array[2];
5353+ item4 = array[3];
5454+ item5 = array[4];
5555+ }
5356 }
5457}
···2233public static class ListDestructuringExtensions
44{
55- public static void Deconstruct<T>(this IList<T> list, out T item1)
55+ extension<T>(IList<T> list)
66 {
77- if (list.Count != 1)
88- throw new Exception("This deconstructor only takes lists of length 1");
77+ public void Deconstruct(out T item1)
88+ {
99+ if (list.Count != 1)
1010+ throw new Exception("This deconstructor only takes lists of length 1");
9111010- item1 = list[0];
1111- }
1212+ item1 = list[0];
1313+ }
12141313- public static void Deconstruct<T>(this IList<T> list, out T item1, out T item2)
1414- {
1515- if (list.Count != 2)
1616- throw new Exception("This deconstructor only takes lists of length 2");
1515+ public void Deconstruct(out T item1, out T item2)
1616+ {
1717+ if (list.Count != 2)
1818+ throw new Exception("This deconstructor only takes lists of length 2");
17191818- item1 = list[0];
1919- item2 = list[1];
2020- }
2020+ item1 = list[0];
2121+ item2 = list[1];
2222+ }
21232222- public static void Deconstruct<T>(this IList<T> list, out T item1, out T item2, out T item3)
2323- {
2424- if (list.Count != 3)
2525- throw new Exception("This deconstructor only takes lists of length 3");
2424+ public void Deconstruct(out T item1, out T item2, out T item3)
2525+ {
2626+ if (list.Count != 3)
2727+ throw new Exception("This deconstructor only takes lists of length 3");
26282727- item1 = list[0];
2828- item2 = list[1];
2929- item3 = list[2];
3030- }
2929+ item1 = list[0];
3030+ item2 = list[1];
3131+ item3 = list[2];
3232+ }
31333232- public static void Deconstruct<T>(this IList<T> list, out T item1, out T item2, out T item3, out T item4)
3333- {
3434- if (list.Count != 4)
3535- throw new Exception("This deconstructor only takes lists of length 4");
3434+ public void Deconstruct(out T item1, out T item2, out T item3, out T item4)
3535+ {
3636+ if (list.Count != 4)
3737+ throw new Exception("This deconstructor only takes lists of length 4");
36383737- item1 = list[0];
3838- item2 = list[1];
3939- item3 = list[2];
4040- item4 = list[3];
4141- }
3939+ item1 = list[0];
4040+ item2 = list[1];
4141+ item3 = list[2];
4242+ item4 = list[3];
4343+ }
42444343- public static void Deconstruct<T>(
4444- this IList<T> list, out T item1, out T item2, out T item3, out T item4, out T item5
4545- )
4646- {
4747- if (list.Count != 5)
4848- throw new Exception("This deconstructor only takes lists of length 5");
4545+ public void Deconstruct(
4646+ out T item1, out T item2, out T item3, out T item4, out T item5
4747+ )
4848+ {
4949+ if (list.Count != 5)
5050+ throw new Exception("This deconstructor only takes lists of length 5");
49515050- item1 = list[0];
5151- item2 = list[1];
5252- item3 = list[2];
5353- item4 = list[3];
5454- item5 = list[4];
5252+ item1 = list[0];
5353+ item2 = list[1];
5454+ item3 = list[2];
5555+ item4 = list[3];
5656+ item5 = list[4];
5757+ }
5558 }
5659}