Beispiel #1
0
            public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
            {
                // always ask for MemberAccess
                new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Demand();

                RuntimeMethodHandle method = m_owner.GetMethodDescriptor();

                // ignore obj since it's a static method

                if ((CallingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs)
                {
                    throw new NotSupportedException(Environment.GetResourceString("NotSupported_CallToVarArg"));
                }

                // create a signature object
                RuntimeTypeHandle[] argumentHandles = new RuntimeTypeHandle[m_owner.m_parameterTypes.Length];
                for (int i = 0; i < argumentHandles.Length; i++)
                {
                    argumentHandles[i] = m_owner.m_parameterTypes[i].TypeHandle;
                }
                Signature sig = new Signature(
                    method, argumentHandles, m_owner.m_returnType.TypeHandle, m_callingConvention);


                // verify arguments
                int formalCount = sig.Arguments.Length;
                int actualCount = (parameters != null) ? parameters.Length : 0;

                if (formalCount != actualCount)
                {
                    throw new TargetParameterCountException(Environment.GetResourceString("Arg_ParmCnt"));
                }

                // if we are here we passed all the previous checks. Time to look at the arguments
                Object retValue = null;

                if (actualCount > 0)
                {
                    Object[] arguments = CheckArguments(parameters, binder, invokeAttr, culture, sig);
                    retValue = method.InvokeMethodFast(null, arguments, sig, m_attributes, RuntimeTypeHandle.EmptyHandle);
                    // copy out. This should be made only if ByRef are present.
                    for (int index = 0; index < actualCount; index++)
                    {
                        parameters[index] = arguments[index];
                    }
                }
                else
                {
                    retValue = method.InvokeMethodFast(null, null, sig, m_attributes, RuntimeTypeHandle.EmptyHandle);
                }

                GC.KeepAlive(this);
                return(retValue);
            }
        public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
        {
            if ((this.CallingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs)
            {
                throw new NotSupportedException(Environment.GetResourceString("NotSupported_CallToVarArg"));
            }
            this.GetMethodDescriptor();
            Signature sig    = new Signature(this.m_methodHandle, this.m_parameterTypes, this.m_returnType, this.CallingConvention);
            int       length = sig.Arguments.Length;
            int       num2   = (parameters != null) ? parameters.Length : 0;

            if (length != num2)
            {
                throw new TargetParameterCountException(Environment.GetResourceString("Arg_ParmCnt"));
            }
            object obj2 = null;

            if (num2 > 0)
            {
                object[] arguments = base.CheckArguments(parameters, binder, invokeAttr, culture, sig);
                obj2 = RuntimeMethodHandle.InvokeMethodFast(this.m_methodHandle, null, arguments, sig, this.Attributes, null);
                for (int i = 0; i < num2; i++)
                {
                    parameters[i] = arguments[i];
                }
            }
            else
            {
                obj2 = RuntimeMethodHandle.InvokeMethodFast(this.m_methodHandle, null, null, sig, this.Attributes, null);
            }
            GC.KeepAlive(this);
            return(obj2);
        }
Beispiel #3
0
        internal object Invoke(object obj, System.Reflection.BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture, bool skipVisibilityChecks)
        {
            int length = this.Signature.Arguments.Length;
            int num2   = (parameters != null) ? parameters.Length : 0;
            INVOCATION_FLAGS invocationFlags = this.InvocationFlags;

            if ((invocationFlags & (INVOCATION_FLAGS.INVOCATION_FLAGS_CONTAINS_STACK_POINTERS | INVOCATION_FLAGS.INVOCATION_FLAGS_NO_INVOKE)) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
            {
                this.ThrowNoInvokeException();
            }
            this.CheckConsistency(obj);
            if (length != num2)
            {
                throw new TargetParameterCountException(Environment.GetResourceString("Arg_ParmCnt"));
            }
            if (num2 > 0xffff)
            {
                throw new TargetParameterCountException(Environment.GetResourceString("NotSupported_TooManyArgs"));
            }
            if (!skipVisibilityChecks && ((invocationFlags & (INVOCATION_FLAGS.INVOCATION_FLAGS_FIELD_SPECIAL_CAST | INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY)) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN))
            {
                if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_FIELD_SPECIAL_CAST) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
                {
                    CodeAccessPermission.Demand(PermissionType.ReflectionMemberAccess);
                }
                if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
                {
                    RuntimeMethodHandle.PerformSecurityCheck(obj, this, this.m_declaringType, (uint)this.m_invocationFlags);
                }
            }
            RuntimeType typeOwner = null;

            if (!this.m_reflectedTypeCache.IsGlobal)
            {
                typeOwner = this.m_declaringType;
            }
            if (num2 == 0)
            {
                return(RuntimeMethodHandle.InvokeMethodFast(this, obj, null, this.Signature, this.m_methodAttributes, typeOwner));
            }
            object[] arguments = base.CheckArguments(parameters, binder, invokeAttr, culture, this.Signature);
            object   obj2      = RuntimeMethodHandle.InvokeMethodFast(this, obj, arguments, this.Signature, this.m_methodAttributes, typeOwner);

            for (int i = 0; i < num2; i++)
            {
                parameters[i] = arguments[i];
            }
            return(obj2);
        }
        public override object Invoke(object obj, System.Reflection.BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
        {
            INVOCATION_FLAGS invocationFlags = this.InvocationFlags;

            if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NO_INVOKE) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
            {
                this.ThrowNoInvokeException();
            }
            this.CheckConsistency(obj);
            if (obj != null)
            {
                new SecurityPermission(SecurityPermissionFlag.SkipVerification).Demand();
            }
            if ((invocationFlags & (INVOCATION_FLAGS.INVOCATION_FLAGS_FIELD_SPECIAL_CAST | INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY)) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
            {
                if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_FIELD_SPECIAL_CAST) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
                {
                    CodeAccessPermission.Demand(PermissionType.ReflectionMemberAccess);
                }
                if ((invocationFlags & INVOCATION_FLAGS.INVOCATION_FLAGS_NEED_SECURITY) != INVOCATION_FLAGS.INVOCATION_FLAGS_UNKNOWN)
                {
                    RuntimeMethodHandle.PerformSecurityCheck(obj, this, this.m_declaringType, (uint)this.m_invocationFlags);
                }
            }
            int length = this.Signature.Arguments.Length;
            int num2   = (parameters != null) ? parameters.Length : 0;

            if (length != num2)
            {
                throw new TargetParameterCountException(Environment.GetResourceString("Arg_ParmCnt"));
            }
            if (num2 <= 0)
            {
                return(RuntimeMethodHandle.InvokeMethodFast(this, obj, null, this.Signature, this.m_methodAttributes, (RuntimeType)this.DeclaringType));
            }
            object[] arguments = base.CheckArguments(parameters, binder, invokeAttr, culture, this.Signature);
            object   obj2      = RuntimeMethodHandle.InvokeMethodFast(this, obj, arguments, this.Signature, this.m_methodAttributes, (RuntimeType)this.ReflectedType);

            for (int i = 0; i < num2; i++)
            {
                parameters[i] = arguments[i];
            }
            return(obj2);
        }