2005-05-16 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / class / corlib / System.Reflection / MonoMethod.cs
old mode 100755 (executable)
new mode 100644 (file)
index 6513e4c..263e4d1
@@ -6,10 +6,7 @@
 //   Paolo Molaro (lupus@ximian.com)
 //
 // (C) 2001 Ximian, Inc.  http://www.ximian.com
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using System;
 using System.Globalization;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Runtime.Serialization;
+using System.Security;
 
 namespace System.Reflection {
        
@@ -110,14 +107,25 @@ namespace System.Reflection {
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                internal extern Object InternalInvoke (Object obj, Object[] parameters);
                
-               public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
+               public override Object Invoke (Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 
+               {
                        if (binder == null)
                                binder = Binder.DefaultBinder;
                        ParameterInfo[] pinfo = GetParameters ();
                        if (!Binder.ConvertArgs (binder, parameters, pinfo, culture))
                                throw new ArgumentException ("parameters");
+
+                       if (SecurityManager.SecurityEnabled) {
+                               // sadly Attributes doesn't tell us which kind of security action this is so
+                               // we must do it the hard way - and it also means that we can skip calling
+                               // Attribute (which is another an icall)
+                               SecurityManager.ReflectedLinkDemandInvoke (this);
+                       }
+
                        try {
                                return InternalInvoke (obj, parameters);
+                       } catch (InvalidOperationException) {
+                               throw;
                        } catch (TargetException) {
                                throw;
                        } catch (Exception e) {
@@ -277,6 +285,12 @@ namespace System.Reflection {
                        get;
                }
 #endif
+
+#if NET_2_0
+               public override MethodBody GetMethodBody () {
+                       return GetMethodBody (mhandle);
+               }
+#endif
        }
        
        internal class MonoCMethod : ConstructorInfo, ISerializable\r
@@ -301,15 +315,26 @@ namespace System.Reflection {
                 */
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                internal extern Object InternalInvoke (Object obj, Object[] parameters);
-               
-               public override Object Invoke (Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
+
+               public override Object Invoke (Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 
+               {
                        if (binder == null)
                                binder = Binder.DefaultBinder;
                        ParameterInfo[] pinfo = GetParameters ();
                        if (!Binder.ConvertArgs (binder, parameters, pinfo, culture))
                                throw new ArgumentException ("parameters");
+
+                       if (SecurityManager.SecurityEnabled) {
+                               // sadly Attributes doesn't tell us which kind of security action this is so
+                               // we must do it the hard way - and it also means that we can skip calling
+                               // Attribute (which is another an icall)
+                               SecurityManager.ReflectedLinkDemandInvoke (this);
+                       }
+
                        try {
                                return InternalInvoke (obj, parameters);
+                       } catch (InvalidOperationException) {
+                               throw;
                        } catch (TargetException) {
                                throw;
                        } catch (Exception e) {
@@ -401,6 +426,12 @@ namespace System.Reflection {
                }
 #endif
 
+#if NET_2_0
+               public override MethodBody GetMethodBody () {
+                       return GetMethodBody (mhandle);
+               }
+#endif
+
                public override string ToString () {
                        string parms = "";
                        ParameterInfo[] p = GetParameters ();