New test.
[mono.git] / mono / tests / cas / linkdemand / icall2.cs
1 using System;
2 using System.Reflection;
3 using System.Security;
4
5 public class Program {
6
7         static bool RunningOnMono ()
8         {
9                 bool mono = (Type.GetType ("Mono.Math.BigInteger") != null); 
10                 Console.WriteLine ("Running on {0} runtime...", mono ? "Mono" : "Microsoft");
11                 return mono;
12         }
13
14         static int Main ()
15         {
16                 string icall = null;
17                 MethodInfo mi = null;
18                 bool mono = RunningOnMono ();
19
20                 if (mono) {
21                         icall = "internalGetGacPath";
22                         mi = typeof (System.Environment).GetMethod (icall, BindingFlags.Static | BindingFlags.NonPublic);
23                 } else {
24                         // private internal call for MS runtime
25                         // http://msdn.microsoft.com/msdnmag/issues/04/11/NETMatters/
26                         icall = "CompleteGuid";
27                         mi = typeof (System.Guid).GetMethod (icall, BindingFlags.Instance | BindingFlags.NonPublic);
28                 }
29
30                 if (mi == null) {
31                         Console.WriteLine ("*3* Couldn't reflect on internalcall {0}", icall);
32                                 return 3;
33                 }
34
35                 try {
36                         string result = null;
37                         if (mono) {
38                                 result = (string) mi.Invoke (null, null);
39                         } else {
40                                 System.Guid g = new System.Guid ();
41 #if NET_2_0
42                                 mi.Invoke (g, null);
43                                 result = "completed";
44 #else
45                                 result = ((bool) mi.Invoke (g, null)).ToString ();
46 #endif
47                         }
48                         Console.WriteLine ("*0* [Reflected]{0}: {1}", icall, result);
49                         return 0;
50                 }
51                 catch (SecurityException se) {
52                         Console.WriteLine ("*1* SecurityException\n{0}", se);
53                         return 1;
54                 }
55                 catch (Exception e) {
56                         Console.WriteLine ("*2* Unexpected exception\n{0}", e);
57                         return 2;
58                 }
59         }
60 }