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
<>);
60 static Func
<T
> Do
<T
> (T t
)
67 } while (default (T
) != null);
73 static Func
<T
> Lock
<T
> (T t
)
84 static Func
<T
> Catch
<T
> (T t
)
89 throw new ApplicationException (l
.ToString ());
96 static Func
<T
> Catch_2
<T
> (T t
) where T
: Exception
101 throw new NotSupportedException ();
105 throw new ApplicationException ("Should not be reached");
110 static Func
<T
> Finally
<T
> (T t
)
124 static Func
<T
> Using
<T
> (T t
)
127 using (var d
= new Disposable
<T
> ()) {
134 static Func
<T
> Switch
<T
> (T t
)
145 static Func
<List
<T
>> ForForeach
<T
> (T
[] t
)
149 return new List
<T
> () { e }
;
151 throw new ApplicationException ();
155 public void ArrayMutate
<T
> (T
[] array
)
158 Action
<int> anonMeth
= delegate (int slc
) {
159 long[] idx
= new long[] { 0, 0 }
;
160 for (int i
= 0; i
< r
; i
++) {
166 static Func
<T
[][]> ArrayMultiMutate
<T
> (T
[][] array
)
169 for (int i
= 0; i
< 3; i
++) {
170 array
[i
][i
] = default (T
);
177 static Func
<int> ArrayMultiMutate
<T
> (T
[,] array
)
180 return array
[0, 0].GetHashCode ();
184 static Func
<T
[]> NestedTypeMutate
<T
> () where T
: IEquatable
<T
>
186 var local
= new CA
<T
>.Nested ();
188 return new[] { CA<T>.Nested.Value, local.Value2 }
;
192 public static int Main ()
194 if (For (new List
<int> { 5, 10 }
) ()[1] != 10)
201 } catch (ApplicationException
) {
216 var ex
= new NotSupportedException ();
217 var t5_2
= Catch_2 (ex
);
221 var t6
= Finally (5);
225 var t7
= Using (1.1);
229 var t8
= Switch (55);
233 var t9
= ForForeach (new[] { 4, 1 }
);
237 var t10
= ArrayMultiMutate (new string[][] { new string[] { "a", "b", "c" }
, new string[] { "1", "2", "3" }
, new string[] { "A", "B", "C" }
});
238 if (t10 ()[2][2] != null)
241 var array
= new short[,] { { 10, 20 }
};
242 var t10a
= ArrayMultiMutate (array
);
243 if (t10a () != array
[0, 0].GetHashCode ())
246 var t11
= TypeOf ("b");
247 if (t11 () != typeof (string))
250 var t12
= NestedTypeMutate
<ulong> () ();
251 if (t12
[0] != 0 || t12
[1] != 0)
254 Console
.WriteLine ("OK");