Beispiel #1
0
        private static object FastCall(object o, MethodBase method, ParameterInfo[] Parameters, object[] args, Type objType, IReflect objIReflect)
        {
            int upperBound = args.GetUpperBound(0);

            for (int i = 0; i <= upperBound; i++)
            {
                ParameterInfo info         = Parameters[i];
                object        defaultValue = args[i];
                if ((defaultValue is Missing) && info.IsOptional)
                {
                    defaultValue = info.DefaultValue;
                }
                args[i] = ObjectType.CTypeHelper(defaultValue, info.ParameterType);
            }
            VBBinder.SecurityCheckForLateboundCalls(method, objType, objIReflect);
            if (((objType != objIReflect) && !method.IsStatic) && !DoesTargetObjectMatch(o, method))
            {
                return(InvokeMemberOnIReflect(objIReflect, method, BindingFlags.InvokeMethod, o, args));
            }
            VerifyObjRefPresentForInstanceCall(o, method);
            return(method.Invoke(o, args));
        }
Beispiel #2
0
        internal static object InternalLateCall(object o, Type objType, string name, object[] args, string[] paramnames, bool[] CopyBack, bool IgnoreReturn)
        {
            object       obj2;
            BindingFlags flags = BindingFlags.OptionalParamBinding | BindingFlags.InvokeMethod | BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.IgnoreCase;

            if (IgnoreReturn)
            {
                flags |= BindingFlags.IgnoreReturn;
            }
            if (objType == null)
            {
                if (o == null)
                {
                    throw ExceptionUtils.VbMakeException(0x5b);
                }
                objType = o.GetType();
            }
            IReflect correctIReflect = GetCorrectIReflect(o, objType);

            if (objType.IsCOMObject)
            {
                CheckForClassExtendingCOMClass(objType);
            }
            if (name == null)
            {
                name = "";
            }
            VBBinder binder = new VBBinder(CopyBack);

            if (!objType.IsCOMObject)
            {
                MemberInfo[] mi = GetMembersByName(correctIReflect, name, flags);
                if ((mi == null) || (mi.Length == 0))
                {
                    throw new MissingMemberException(Utils.GetResourceString("MissingMember_MemberNotFoundOnType2", new string[] { name, Utils.VBFriendlyName(objType, o) }));
                }
                if (MemberIsField(mi))
                {
                    throw new ArgumentException(Utils.GetResourceString("ExpressionNotProcedure", new string[] { name, Utils.VBFriendlyName(objType, o) }));
                }
                if ((mi.Length == 1) && ((paramnames == null) || (paramnames.Length == 0)))
                {
                    MemberInfo getMethod = mi[0];
                    if (getMethod.MemberType == MemberTypes.Property)
                    {
                        getMethod = ((PropertyInfo)getMethod).GetGetMethod();
                        if (getMethod == null)
                        {
                            throw new MissingMemberException(Utils.GetResourceString("MissingMember_MemberNotFoundOnType2", new string[] { name, Utils.VBFriendlyName(objType, o) }));
                        }
                    }
                    MethodBase      method     = (MethodBase)getMethod;
                    ParameterInfo[] parameters = method.GetParameters();
                    int             length     = args.Length;
                    int             num2       = parameters.Length;
                    if (num2 == length)
                    {
                        if (num2 == 0)
                        {
                            return(FastCall(o, method, parameters, args, objType, correctIReflect));
                        }
                        if ((CopyBack == null) && NoByrefs(parameters))
                        {
                            ParameterInfo info2 = parameters[num2 - 1];
                            if (!info2.ParameterType.IsArray)
                            {
                                return(FastCall(o, method, parameters, args, objType, correctIReflect));
                            }
                            object[] customAttributes = info2.GetCustomAttributes(typeof(ParamArrayAttribute), false);
                            if ((customAttributes == null) || (customAttributes.Length == 0))
                            {
                                return(FastCall(o, method, parameters, args, objType, correctIReflect));
                            }
                        }
                    }
                }
            }
            try
            {
                obj2 = binder.InvokeMember(name, flags, objType, correctIReflect, o, args, paramnames);
            }
            catch (MissingMemberException)
            {
                throw;
            }
            catch when(?)
                {
                    throw new MissingMemberException(Utils.GetResourceString("MissingMember_MemberNotFoundOnType2", new string[] { name, Utils.VBFriendlyName(objType, o) }));
                }