2 using System.Reflection;
4 using System.Security.Permissions;
8 [SecurityPermission (SecurityAction.LinkDemand, ControlPrincipal=true)]
9 public static int Test ()
14 static MethodInfo GetReflectedCall ()
16 return typeof (Program).GetMethod ("Test", BindingFlags.Static | BindingFlags.Public);
19 static int LinkReflectedCall (MethodInfo mi)
21 // if a LinkDemand is enforced this will succeed;
22 // if a full Demand is enforced (stack walk) then it will fail
23 return (int) mi.Invoke (null, null);
26 [SecurityPermission (SecurityAction.Deny, ControlPrincipal=true)]
27 static int CallReflectedCall (MethodInfo mi)
29 return LinkReflectedCall (mi);
35 MethodInfo mi = GetReflectedCall ();
37 Console.WriteLine ("*2* Couldn't reflect on call Test (failure).");
40 int result = CallReflectedCall (mi);
42 Console.WriteLine ("*{0}* Unexpected calling thru reflection.", result);
44 Console.WriteLine ("*{0}* Unexpected return value from reflection.", result);
49 catch (SecurityException) {
50 Console.WriteLine ("*0* Expected SecurityException.");