using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; #if __MOBILE__ class GenericsTests #else class Tests #endif { struct TestStruct { public int i; public int j; public TestStruct (int i, int j) { this.i = i; this.j = j; } } #if !__MOBILE__ public static int Main (string[] args) { return TestDriver.RunTests (typeof (Tests), args); } #endif public static int test_1_no_nullable_unbox () { return Unbox (1); } public static int test_1_nullable_unbox_null () { return Unbox (null).HasValue ? 0 : 1; } public static int test_1_nullable_box () { return (int) Box (1); } public static int test_1_nullable_box_null () { return Box (null) == null ? 1 : 0; } public static int test_1_isinst_nullable () { object o = 1; return (o is int?) ? 1 : 0; } public static int test_1_nullable_unbox_vtype () { return Unbox (new TestStruct (1, 2)).Value.i; } public static int test_1_nullable_unbox_null_vtype () { return Unbox (null).HasValue ? 0 : 1; } public static int test_1_nullable_box_vtype () { return ((TestStruct)(Box (new TestStruct (1, 2)))).i; } public static int test_1_nullable_box_null_vtype () { return Box (null) == null ? 1 : 0; } public static int test_1_isinst_nullable_vtype () { object o = new TestStruct (1, 2); return (o is TestStruct?) ? 1 : 0; } public static int test_0_nullable_normal_unbox () { int? i = 5; object o = i; // This uses unbox instead of unbox_any int? j = (int?)o; if (j != 5) return 1; return 0; } public static void stelem_any (T[] arr, T elem) { arr [0] = elem; } public static T ldelem_any (T[] arr) { return arr [0]; } public static int test_1_ldelem_stelem_any_int () { int[] arr = new int [3]; stelem_any (arr, 1); return ldelem_any (arr); } public static T return_ref (ref T t) { return t; } public static T ldelema_any (T[] arr) { return return_ref (ref arr [0]); } public static int test_0_ldelema () { string[] arr = new string [1]; arr [0] = "Hello"; if (ldelema_any (arr) == "Hello") return 0; else return 1; } public static T[,] newarr_multi () { return new T [1, 1]; } public static int test_0_newarr_multi_dim () { return newarr_multi ().GetType () == typeof (string[,]) ? 0 : 1; } static object Box (T t) { return t; } static T Unbox (object o) { return (T) o; } }