Esempio n. 1
0
        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) {
                throw new TargetInvocationException(e);
            }
        }
Esempio n. 2
0
        public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
        {
            if (binder == null)
            {
                binder = Binder.DefaultBinder;
            }
            ParameterInfo[] parameters2 = this.GetParameters();
            if ((parameters == null && parameters2.Length != 0) || (parameters != null && parameters.Length != parameters2.Length))
            {
                throw new TargetParameterCountException("parameters do not match signature");
            }
            if ((invokeAttr & BindingFlags.ExactBinding) == BindingFlags.Default)
            {
                if (!Binder.ConvertArgs(binder, parameters, parameters2, culture))
                {
                    throw new ArgumentException("failed to convert parameters");
                }
            }
            else
            {
                for (int i = 0; i < parameters2.Length; i++)
                {
                    if (parameters[i].GetType() != parameters2[i].ParameterType)
                    {
                        throw new ArgumentException("parameters do not match signature");
                    }
                }
            }
            if (obj == null && this.DeclaringType.ContainsGenericParameters)
            {
                throw new MemberAccessException("Cannot create an instance of " + this.DeclaringType + " because Type.ContainsGenericParameters is true.");
            }
            if ((invokeAttr & BindingFlags.CreateInstance) != BindingFlags.Default && this.DeclaringType.IsAbstract)
            {
                throw new MemberAccessException(string.Format("Cannot create an instance of {0} because it is an abstract class", this.DeclaringType));
            }
            Exception ex   = null;
            object    obj2 = null;

            try
            {
                obj2 = this.InternalInvoke(obj, parameters, out ex);
            }
            catch (MethodAccessException)
            {
                throw;
            }
            catch (Exception inner)
            {
                throw new TargetInvocationException(inner);
            }
            if (ex != null)
            {
                throw ex;
            }
            return((obj != null) ? null : obj2);
        }
Esempio n. 3
0
        public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
        {
            if (binder == null)
            {
                binder = Binder.DefaultBinder;
            }
            ParameterInfo[] parametersInfo = MonoMethodInfo.GetParametersInfo(this.mhandle, this);
            if ((parameters == null && parametersInfo.Length != 0) || (parameters != null && parameters.Length != parametersInfo.Length))
            {
                throw new TargetParameterCountException("parameters do not match signature");
            }
            if ((invokeAttr & BindingFlags.ExactBinding) == BindingFlags.Default)
            {
                if (!Binder.ConvertArgs(binder, parameters, parametersInfo, culture))
                {
                    throw new ArgumentException("failed to convert parameters");
                }
            }
            else
            {
                for (int i = 0; i < parametersInfo.Length; i++)
                {
                    if (parameters[i].GetType() != parametersInfo[i].ParameterType)
                    {
                        throw new ArgumentException("parameters do not match signature");
                    }
                }
            }
            if (this.ContainsGenericParameters)
            {
                throw new InvalidOperationException("Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true.");
            }
            object    result = null;
            Exception ex;

            try
            {
                result = this.InternalInvoke(obj, parameters, out ex);
            }
            catch (ThreadAbortException)
            {
                throw;
            }
            catch (MethodAccessException)
            {
                throw;
            }
            catch (Exception inner)
            {
                throw new TargetInvocationException(inner);
            }
            if (ex != null)
            {
                throw ex;
            }
            return(result);
        }
Esempio n. 4
0
        public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
        {
            if (binder == null)
            {
                binder = Binder.DefaultBinder;
            }

            ParameterInfo[] pinfo = MonoMethodInfo.GetParametersInfo(mhandle, this);

            if (!binder.ConvertArgs(parameters, pinfo, culture, (invokeAttr & BindingFlags.ExactBinding) != 0))
            {
                throw new ArgumentException("failed to convert parameters");
            }

#if !NET_2_1
            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);
            }
#endif

            if (obj == null && DeclaringType.ContainsGenericParameters)
            {
                throw new MemberAccessException("Cannot create an instance of " + DeclaringType + " because Type.ContainsGenericParameters is true.");
            }

            if ((invokeAttr & BindingFlags.CreateInstance) != 0 && DeclaringType.IsAbstract)
            {
                throw new MemberAccessException(String.Format("Cannot create an instance of {0} because it is an abstract class", DeclaringType));
            }

            Exception exc = null;
            object    o   = null;

            try {
                o = InternalInvoke(obj, parameters, out exc);
#if NET_2_1
            } catch (MethodAccessException) {
                throw;
#endif
            } catch (Exception e) {
                throw new TargetInvocationException(e);
            }

            if (exc != null)
            {
                throw exc;
            }
            return((obj == null) ? o : null);
        }
Esempio n. 5
0
        public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
        {
            if (binder == null)
            {
                binder = Binder.DefaultBinder;
            }

            /*Avoid allocating an array every time*/
            ParameterInfo[] pinfo = MonoMethodInfo.GetParametersInfo(mhandle, this);
            if (!binder.ConvertArgs(parameters, pinfo, culture, (invokeAttr & BindingFlags.ExactBinding) != 0))
            {
                throw new ArgumentException("failed to convert parameters");
            }

#if !NET_2_1
            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);
            }
#endif

            if (ContainsGenericParameters)
            {
                throw new InvalidOperationException("Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true.");
            }

            Exception exc;
            object    o = null;

            try {
                // The ex argument is used to distinguish exceptions thrown by the icall
                // from the exceptions thrown by the called method (which need to be
                // wrapped in TargetInvocationException).
                o = InternalInvoke(obj, parameters, out exc);
            } catch (ThreadAbortException) {
                throw;
#if NET_2_1
            } catch (MethodAccessException) {
                throw;
#endif
            } catch (Exception e) {
                throw new TargetInvocationException(e);
            }

            if (exc != null)
            {
                throw exc;
            }
            return(o);
        }
Esempio n. 6
0
		public override Object Invoke (Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 
		{
			if (binder == null)
				binder = Binder.DefaultBinder;

			ParameterInfo[] pinfo = MonoMethodInfo.GetParametersInfo (mhandle, this);

			if (!binder.ConvertArgs (parameters, pinfo, culture, (invokeAttr & BindingFlags.ExactBinding) != 0))
				throw new ArgumentException ("failed to convert parameters");

#if !NET_2_1
			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);
			}
#endif

			if (obj == null && DeclaringType.ContainsGenericParameters)
				throw new MemberAccessException ("Cannot create an instance of " + DeclaringType + " because Type.ContainsGenericParameters is true.");

			if ((invokeAttr & BindingFlags.CreateInstance) != 0 && DeclaringType.IsAbstract) {
				throw new MemberAccessException (String.Format ("Cannot create an instance of {0} because it is an abstract class", DeclaringType));
			}

			Exception exc = null;
			object o = null;

			try {
				o = InternalInvoke (obj, parameters, out exc);
#if NET_2_1
			} catch (MethodAccessException) {
				throw;
#endif
			} catch (Exception e) {
				throw new TargetInvocationException (e);
			}

			if (exc != null)
				throw exc;
			return (obj == null) ? o : null;
		}
Esempio n. 7
0
		public override Object Invoke (Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 
		{
			if (binder == null)
				binder = Binder.DefaultBinder;

			/*Avoid allocating an array every time*/
			ParameterInfo[] pinfo = MonoMethodInfo.GetParametersInfo (mhandle, this);
			if (!binder.ConvertArgs (parameters, pinfo, culture, (invokeAttr & BindingFlags.ExactBinding) != 0))
				throw new ArgumentException ("failed to convert parameters");

#if !NET_2_1
			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);
			}
#endif

			if (ContainsGenericParameters)
				throw new InvalidOperationException ("Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true.");

			Exception exc;
			object o = null;

			try {
				// The ex argument is used to distinguish exceptions thrown by the icall
				// from the exceptions thrown by the called method (which need to be
				// wrapped in TargetInvocationException).
				o = InternalInvoke (obj, parameters, out exc);
			} catch (ThreadAbortException) {
				throw;
#if NET_2_1
			} catch (MethodAccessException) {
				throw;
#endif
			} catch (Exception e) {
				throw new TargetInvocationException (e);
			}

			if (exc != null)
				throw exc;
			return o;
		}
Esempio n. 8
0
        public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
        {
            if (binder == null)
            {
                binder = Binder.DefaultBinder;
            }
            ParameterInfo[] pinfo = GetParameters();

            if ((parameters == null && pinfo.Length != 0) || (parameters != null && parameters.Length != pinfo.Length))
            {
                throw new TargetParameterCountException("parameters do not match signature");
            }

            if ((invokeAttr & BindingFlags.ExactBinding) == 0)
            {
                if (!Binder.ConvertArgs(binder, parameters, pinfo, culture))
                {
                    throw new ArgumentException("failed to convert parameters");
                }
            }
            else
            {
                for (int i = 0; i < pinfo.Length; i++)
                {
                    if (parameters[i].GetType() != pinfo[i].ParameterType)
                    {
                        throw new ArgumentException("parameters do not match signature");
                    }
                }
            }

#if !NET_2_1
            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);
            }
#endif

#if NET_2_0
            if (ContainsGenericParameters)
            {
                throw new InvalidOperationException("Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true.");
            }
#endif

            Exception exc;
            object    o = null;

            try {
                // The ex argument is used to distinguish exceptions thrown by the icall
                // from the exceptions thrown by the called method (which need to be
                // wrapped in TargetInvocationException).
                o = InternalInvoke(obj, parameters, out exc);
#if NET_2_0
            } catch (ThreadAbortException) {
                throw;
#endif
#if NET_2_1
            } catch (MethodAccessException) {
                throw;
#endif
            } catch (Exception e) {
                throw new TargetInvocationException(e);
            }

            if (exc != null)
            {
                throw exc;
            }
            return(o);
        }