2 using System.Collections.Generic;
4 // Generics mutate tests
6 class Disposable<T> : IDisposable
13 interface IFoo<TOne,TTwo>
21 public static readonly T Value;
22 public readonly T Value2;
28 static Func<T[]> For<T> (List<T> list)
32 for (int i = 0; i < t.Length; ++i) {
40 static Func<T> Throw<T> (T t)
44 throw new ApplicationException (l.ToString ());
48 static Func<Type> TypeOf<T> (T t)
53 var e = typeof (Disposable <T>);
54 e = typeof (Disposable <>);
55 e = typeof (IFoo <,>);
60 static Func<T> Do<T> (T t)
67 } while (default (T) != null);
73 static Func<T> Lock<T> (T t)
85 static Func<T> Catch<T> (T t)
90 throw new ApplicationException (l.ToString ());
97 static Func<T> Finally<T> (T t)
111 static Func<T> Using<T> (T t)
114 using (var d = new Disposable<T> ())
122 static Func<T> Switch<T> (T t)
133 static Func<List<T>> ForForeach<T> (T[] t)
137 return new List<T> () { e };
139 throw new ApplicationException ();
143 public void ArrayMutate<T> (T[] array)
146 Action<int> anonMeth = delegate (int slc) {
147 long[] idx = new long[] { 0, 0 };
148 for (int i = 0; i < r; i++) {
154 static Func<T[][]> ArrayMultiMutate<T> (T[][] array)
157 for (int i = 0; i < 3; i++) {
158 array [i][i] = default (T);
165 static Func<T[]> NestedTypeMutate<T> ()
167 var local = new CA<T>.Nested ();
169 return new [] { CA<T>.Nested.Value, local.Value2 };
173 public static int Main ()
175 if (For (new List<int> { 5, 10 })() [1] != 10)
182 } catch (ApplicationException)
198 var t6 = Finally (5);
202 var t7 = Using (1.1);
206 var t8 = Switch (55);
210 var t9 = ForForeach (new [] { 4, 1 });
214 var t10 = ArrayMultiMutate (new string [][] { new string [] { "a", "b", "c" }, new string [] { "1", "2", "3" }, new string [] { "A", "B", "C" }});
215 if (t10 () [2] [2] != null)
218 var t11 = TypeOf ("b");
219 if (t11 () != typeof (string))
222 var t12 = NestedTypeMutate<ulong> ()();
223 if (t12 [0] != 0 || t12 [1] != 0)
226 Console.WriteLine ("OK");