merged Sys.Web.Services 2.0 support in my branch:
[mono.git] / mono / tests / cas / linkdemand / refcas2.cs
1 using System;
2 using System.Reflection;
3 using System.Security;
4 using System.Security.Permissions;
5
6 [assembly: SecurityPermission (SecurityAction.RequestRefuse, ControlPrincipal=true)]
7
8 public class Program {
9
10         [SecurityPermission (SecurityAction.LinkDemand, ControlPrincipal=true)]
11         public static int Test ()
12         {
13                 return 2;
14         }
15
16         static int TestReflectedCall ()
17         {
18                 MethodInfo mi = typeof (Program).GetMethod ("Test", BindingFlags.Static | BindingFlags.Public);
19                 if (mi == null) {
20                         Console.WriteLine ("*0* Couldn't reflect on call Test (normal).");
21                         return 0;
22                 } else {
23                         Console.WriteLine ("*1* Reflected on call Test (abnormal).");
24                         return 1;
25                 }
26         }
27
28         static int Main ()
29         {
30                 try {
31                         int result = TestReflectedCall ();
32                         if (result == 2)
33                                 Console.WriteLine ("*{0}* Unexpected calling thru reflection.", result);
34                         return result;
35                 }
36                 catch (SecurityException se) {
37                         Console.WriteLine ("*3* Unexpected SecurityException.\n{0}", se);
38                         return 3;
39                 }
40                 catch (Exception e) {
41                         Console.WriteLine ("*4* Unexpected Exception.\n{0}", e);
42                         return 4;
43                 }
44         }
45 }