Esempio n. 1
0
        object DoInvoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
        {
            if (binder == null)
            {
                binder = Binder.DefaultBinder;
            }

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

            binder.ConvertValues(parameters, pinfo, culture, (invokeAttr & BindingFlags.ExactBinding) != 0);

#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));
            }

            return(InternalInvoke(obj, parameters));
        }
Esempio n. 2
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 = GetParametersInternal();
            binder.ConvertValues(parameters, pinfo, culture, (invokeAttr & BindingFlags.ExactBinding) != 0);

#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. 3
0
		object DoInvoke (object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture) 
		{
			if (binder == null)
				binder = Binder.DefaultBinder;

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

			binder.ConvertValues (parameters, pinfo, culture, (invokeAttr & BindingFlags.ExactBinding) != 0);

#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));
			}

			return InternalInvoke (obj, parameters);
		}
Esempio n. 4
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 = GetParametersInternal ();
			binder.ConvertValues (parameters, pinfo, culture, (invokeAttr & BindingFlags.ExactBinding) != 0);

#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;
		}