|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | 3 |
|
4 | 4 | usingSystem; |
5 | | -usingSystem.Runtime.CompilerServices; |
6 | 5 |
|
7 | | -#iffalse |
8 | | - |
9 | | -publicclassMyBox<T> |
10 | | -{ |
11 | | -privateT_value; |
12 | | -publicTValue{get=>_value;privateset{_value=value;}} |
13 | | -publicMyBox(Tinp){Value=inp;} |
14 | | -} |
15 | | - |
16 | | -publicclassSimpleBox |
| 6 | +namespaceHelloWorld |
17 | 7 | { |
18 | | -privatedecimal_value; |
19 | | -publicdecimalValue{get=>_value;privateset{_value=value;}} |
20 | | -publicSimpleBox(decimalinp){Value=inp;} |
21 | | -} |
22 | | - |
23 | | -publicclassProgram |
24 | | -{ |
25 | | -publicstaticvoidMain() |
| 8 | +internalclassProgram |
26 | 9 | { |
27 | | -varsbox=newSimpleBox((decimal)-5); |
28 | | -RunSimple(sbox,(decimal)20); |
29 | | -Console.WriteLine("20 = {0}",sbox.Value); |
30 | | -varbox=newMyBox<string>("xyz"); |
31 | | -RunItAgain<string>(box,"hjk"); |
32 | | -Console.WriteLine("hjk = {0}",box.Value); |
33 | | -varbox2=newMyBox<decimal>((decimal)-2); |
34 | | -RunItAgain<decimal>(box2,(decimal)10.0); |
35 | | -Console.WriteLine(box2.Value); |
36 | | -RunIt<string>(box,"abc"); |
37 | | -Console.WriteLine("abc = {0}",box.Value); |
38 | | -} |
39 | | - |
40 | | -[MethodImpl(MethodImplOptions.NoInlining)] |
41 | | -publicstaticvoidRunIt<H>(MyBox<H>dest,Hinput) |
42 | | -{ |
43 | | -refHboxWriter=refAccessBox(dest); |
44 | | -boxWriter=input; |
45 | | -} |
46 | | - |
47 | | -[MethodImpl(MethodImplOptions.NoInlining)] |
48 | | -publicstaticvoidRunItAgain<S>(MyBox<S>dest,Sinput) |
49 | | -{ |
50 | | -refSboxWriter=refAccessHelper<S>.AccessBox2(dest); |
51 | | -boxWriter=input; |
52 | | -} |
53 | | - |
54 | | -[UnsafeAccessor(UnsafeAccessorKind.Field,Name="_value")] |
55 | | -privatestaticexternrefWAccessBox<W>(MyBox<W>x); |
56 | | - |
57 | | -[MethodImpl(MethodImplOptions.NoInlining)] |
58 | | -privatestaticvoidRunSimple(SimpleBoxs,decimalinput) |
59 | | -{ |
60 | | -refdecimalboxWriter=refSimpleHelper.AccessSimpleBox(s); |
61 | | -boxWriter=input; |
62 | | -} |
63 | | -} |
64 | | - |
65 | | -publicclassAccessHelper<Q> |
66 | | -{ |
67 | | -#iffalse |
68 | | -[MethodImpl(MethodImplOptions.NoInlining)] |
69 | | -publicstatic/*extern*/refQAccessBox2(MyBox<Q>q)=>thrownewNotImplementedException("exn"); |
70 | | -#else |
71 | | -[UnsafeAccessor(UnsafeAccessorKind.Field,Name="_value")] |
72 | | -publicstaticexternrefQAccessBox2(MyBox<Q>q); |
73 | | -#endif |
74 | | -} |
75 | | - |
76 | | -publicclassSimpleHelper |
77 | | -{ |
78 | | -[UnsafeAccessor(UnsafeAccessorKind.Field,Name="_value")] |
79 | | -publicstaticexternrefdecimalAccessSimpleBox(SimpleBoxb); |
80 | | -} |
81 | | - |
82 | | -#else |
83 | | - |
84 | | -publicclassMyService<T> |
85 | | -{ |
86 | | -publicMyService(){} |
87 | | - |
88 | | -privatestaticstringExplain(Targ)=>arg.ToString()+" : "+typeof(T).ToString();//$"{arg} : {typeof(T)}"; |
89 | | -} |
90 | | - |
91 | | -publicclassProgram |
92 | | -{ |
93 | | -publicstaticvoidMain() |
| 10 | +privatestaticvoidMain(string[]args) |
94 | 11 | { |
95 | | -newProgram().Runner<string>("abcd"); |
| 12 | +boolisMono=typeof(object).Assembly.GetType("Mono.RuntimeStructs")!=null; |
| 13 | +Console.WriteLine($"Hello World{(isMono?"from Mono!":"from CoreCLR!")}"); |
| 14 | +Console.WriteLine(typeof(object).Assembly.FullName); |
| 15 | +Console.WriteLine(System.Reflection.Assembly.GetEntryAssembly()); |
| 16 | +Console.WriteLine(System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription); |
96 | 17 | } |
97 | | - |
98 | | -[MethodImpl(MethodImplOptions.NoInlining)] |
99 | | -publicvoidRunner<Q>(Qx) |
100 | | -{ |
101 | | -Console.WriteLine(AccessHelper<Q>.CallExplain(default,x)); |
102 | | -} |
103 | | - |
104 | | -} |
105 | | - |
106 | | -publicstaticclassAccessHelper<W> |
107 | | -{ |
108 | | -[UnsafeAccessor(UnsafeAccessorKind.StaticMethod,Name="Explain")] |
109 | | -publicstaticexternstringCallExplain(MyService<W>target,Warg); |
110 | | - |
| 18 | +} |
111 | 19 | } |
112 | | - |
113 | | -#endif |