|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | + |
| 4 | +using System; |
| 5 | +using System.Runtime.CompilerServices; |
| 6 | +using Xunit; |
| 7 | + |
| 8 | +public class Runtime_121066 |
| 9 | +{ |
| 10 | + public static int preciseInitCctorsRun = 0; |
| 11 | + |
| 12 | + class MyPreciseInitClass<T> |
| 13 | + { |
| 14 | + static MyPreciseInitClass() |
| 15 | + { |
| 16 | + preciseInitCctorsRun++; |
| 17 | + } |
| 18 | + |
| 19 | + public static void TriggerCctorClass() |
| 20 | + { |
| 21 | + } |
| 22 | + |
| 23 | + public static void TriggerCctorMethod<U>() |
| 24 | + { } |
| 25 | + } |
| 26 | + |
| 27 | + class MyClass<T> |
| 28 | + { |
| 29 | + static Type staticVarType = typeof(MyClass<T>); |
| 30 | + public Type GetTypeOf() |
| 31 | + { |
| 32 | + return typeof(MyClass<T>); |
| 33 | + } |
| 34 | + public static Type GetTypeOfStatic() |
| 35 | + { |
| 36 | + return typeof(MyClass<T>); |
| 37 | + } |
| 38 | + |
| 39 | + public static Type GetTypeThroughStaticVar() |
| 40 | + { |
| 41 | + return staticVarType; |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + [Fact] |
| 46 | + public static void TestEntryPoint() |
| 47 | + { |
| 48 | + Assert.True(TestPreciseInitCctors()); |
| 49 | + } |
| 50 | + |
| 51 | + public static bool TestPreciseInitCctors() |
| 52 | + { |
| 53 | + if (preciseInitCctorsRun != 0) |
| 54 | + { |
| 55 | + Console.WriteLine("preciseInitCctorsRun should be 0, but is {0}", preciseInitCctorsRun); |
| 56 | + return false; |
| 57 | + } |
| 58 | + MyPreciseInitClass<int>.TriggerCctorClass(); |
| 59 | + if (preciseInitCctorsRun != 1) |
| 60 | + { |
| 61 | + Console.WriteLine("preciseInitCctorsRun should be 1, but is {0}", preciseInitCctorsRun); |
| 62 | + return false; |
| 63 | + } |
| 64 | + MyPreciseInitClass<short>.TriggerCctorMethod<int>(); |
| 65 | + if (preciseInitCctorsRun != 2) |
| 66 | + { |
| 67 | + Console.WriteLine("TriggerCctorClass should return 2, but is {0}", preciseInitCctorsRun); |
| 68 | + return false; |
| 69 | + } |
| 70 | + |
| 71 | + object o = new MyPreciseInitClass<double>(); |
| 72 | + if (preciseInitCctorsRun != 3) |
| 73 | + { |
| 74 | + Console.WriteLine("TriggerCctorClass should return 3, but is {0}", preciseInitCctorsRun); |
| 75 | + return false; |
| 76 | + } |
| 77 | + |
| 78 | + MyPreciseInitClass<object>.TriggerCctorClass(); |
| 79 | + if (preciseInitCctorsRun != 4) |
| 80 | + { |
| 81 | + Console.WriteLine("preciseInitCctorsRun should be 4 but is {0}", preciseInitCctorsRun); |
| 82 | + return false; |
| 83 | + } |
| 84 | + MyPreciseInitClass<string>.TriggerCctorMethod<object>(); |
| 85 | + if (preciseInitCctorsRun != 5) |
| 86 | + { |
| 87 | + Console.WriteLine("TriggerCctorClass should return 5, but is {0}", preciseInitCctorsRun); |
| 88 | + return false; |
| 89 | + } |
| 90 | + |
| 91 | + o = new MyPreciseInitClass<Type>(); |
| 92 | + if (preciseInitCctorsRun != 6) |
| 93 | + { |
| 94 | + Console.WriteLine("TriggerCctorClass should return 6, but is {0}", preciseInitCctorsRun); |
| 95 | + return false; |
| 96 | + } |
| 97 | + |
| 98 | + return true; |
| 99 | + } |
| 100 | +} |
0 commit comments