Beispiel #1
0
        internal static Symbols.Method ResolveCall(Symbols.Container BaseReference, string MethodName, MemberInfo[] Members, object[] Arguments, string[] ArgumentNames, Type[] TypeArguments, BindingFlags LookupFlags, bool ReportErrors, ref OverloadResolution.ResolutionFailure Failure)
        {
            Failure = OverloadResolution.ResolutionFailure.None;
            if ((Members[0].MemberType != MemberTypes.Method) && (Members[0].MemberType != MemberTypes.Property))
            {
                Failure = OverloadResolution.ResolutionFailure.InvalidTarget;
                if (ReportErrors)
                {
                    throw new ArgumentException(Utils.GetResourceString("ExpressionNotProcedure", new string[] { MethodName, BaseReference.VBFriendlyName }));
                }
                return(null);
            }
            int    length   = Arguments.Length;
            object argument = null;

            if (Symbols.HasFlag(LookupFlags, BindingFlags.SetProperty))
            {
                if (Arguments.Length == 0)
                {
                    Failure = OverloadResolution.ResolutionFailure.InvalidArgument;
                    if (ReportErrors)
                    {
                        throw new InvalidCastException(Utils.GetResourceString("PropertySetMissingArgument1", new string[] { MethodName }));
                    }
                    return(null);
                }
                object[] sourceArray = Arguments;
                Arguments = new object[(length - 2) + 1];
                Array.Copy(sourceArray, Arguments, Arguments.Length);
                argument = sourceArray[length - 1];
            }
            Symbols.Method targetProcedure = OverloadResolution.ResolveOverloadedCall(MethodName, Members, Arguments, ArgumentNames, TypeArguments, LookupFlags, ReportErrors, ref Failure);
            if (Failure != OverloadResolution.ResolutionFailure.None)
            {
                return(null);
            }
            if (!targetProcedure.ArgumentsValidated && !OverloadResolution.CanMatchArguments(targetProcedure, Arguments, ArgumentNames, TypeArguments, false, null))
            {
                Failure = OverloadResolution.ResolutionFailure.InvalidArgument;
                if (!ReportErrors)
                {
                    return(null);
                }
                string        str  = "";
                List <string> list = new List <string>();
                bool          flag = OverloadResolution.CanMatchArguments(targetProcedure, Arguments, ArgumentNames, TypeArguments, false, list);
                foreach (string str2 in list)
                {
                    str = str + "\r\n    " + str2;
                }
                throw new InvalidCastException(Utils.GetResourceString("MatchArgumentFailure2", new string[] { targetProcedure.ToString(), str }));
            }
            if (targetProcedure.IsProperty)
            {
                if (MatchesPropertyRequirements(targetProcedure, LookupFlags) == null)
                {
                    Failure = OverloadResolution.ResolutionFailure.InvalidTarget;
                    if (ReportErrors)
                    {
                        throw ReportPropertyMismatch(targetProcedure, LookupFlags);
                    }
                    return(null);
                }
            }
            else if (Symbols.HasFlag(LookupFlags, BindingFlags.SetProperty))
            {
                Failure = OverloadResolution.ResolutionFailure.InvalidTarget;
                if (ReportErrors)
                {
                    throw new MissingMemberException(Utils.GetResourceString("MethodAssignment1", new string[] { targetProcedure.AsMethod().Name }));
                }
                return(null);
            }
            if (!Symbols.HasFlag(LookupFlags, BindingFlags.SetProperty))
            {
                return(targetProcedure);
            }
            ParameterInfo[] parameters = GetCallTarget(targetProcedure, LookupFlags).GetParameters();
            ParameterInfo   parameter  = parameters[parameters.Length - 1];
            bool            requiresNarrowingConversion = false;
            bool            allNarrowingIsFromObject    = false;

            if (OverloadResolution.CanPassToParameter(targetProcedure, argument, parameter, false, false, null, ref requiresNarrowingConversion, ref allNarrowingIsFromObject))
            {
                return(targetProcedure);
            }
            Failure = OverloadResolution.ResolutionFailure.InvalidArgument;
            if (!ReportErrors)
            {
                return(null);
            }
            string        str3   = "";
            List <string> errors = new List <string>();

            allNarrowingIsFromObject    = false;
            requiresNarrowingConversion = false;
            bool flag2 = OverloadResolution.CanPassToParameter(targetProcedure, argument, parameter, false, false, errors, ref allNarrowingIsFromObject, ref requiresNarrowingConversion);

            foreach (string str4 in errors)
            {
                str3 = str3 + "\r\n    " + str4;
            }
            throw new InvalidCastException(Utils.GetResourceString("MatchArgumentFailure2", new string[] { targetProcedure.ToString(), str3 }));
        }
Beispiel #2
0
            internal object InvokeMethod(Symbols.Method TargetProcedure, object[] Arguments, bool[] CopyBack, BindingFlags Flags)
            {
                object     obj3;
                MethodBase callTarget = NewLateBinding.GetCallTarget(TargetProcedure, Flags);

                object[] parameters = NewLateBinding.ConstructCallArguments(TargetProcedure, Arguments, Flags);
                if ((this.m_Instance == null) && !Symbols.IsShared(callTarget))
                {
                    throw new NullReferenceException(Utils.GetResourceString("NullReference_InstanceReqToAccessMember1", new string[] { TargetProcedure.ToString() }));
                }
                if (Symbols.IsNonPublicRuntimeMember(callTarget))
                {
                    throw new MissingMemberException();
                }
                try
                {
                    obj3 = callTarget.Invoke(this.m_Instance, parameters);
                }
                catch (TargetInvocationException exception)
                {
                    throw exception.InnerException;
                }
                OverloadResolution.ReorderArgumentArray(TargetProcedure, parameters, Arguments, CopyBack, Flags);
                return(obj3);
            }
Beispiel #3
0
        private static object ObjectLateGet(object Instance, Type Type, string MemberName, object[] Arguments, string[] ArgumentNames, Type[] TypeArguments, bool[] CopyBack)
        {
            Symbols.Container container;
            OverloadResolution.ResolutionFailure failure;
            if (Type != null)
            {
                container = new Symbols.Container(Type);
            }
            else
            {
                container = new Symbols.Container(Instance);
            }
            BindingFlags lookupFlags = BindingFlags.GetProperty | BindingFlags.InvokeMethod;

            MemberInfo[] members = container.GetMembers(ref MemberName, true);
            if (members[0].MemberType == MemberTypes.Field)
            {
                if (TypeArguments.Length > 0)
                {
                    throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue"));
                }
                object fieldValue = container.GetFieldValue((FieldInfo)members[0]);
                if (Arguments.Length == 0)
                {
                    return(fieldValue);
                }
                return(LateIndexGet(fieldValue, Arguments, ArgumentNames, CopyBack));
            }
            if ((ArgumentNames.Length > Arguments.Length) || ((CopyBack != null) && (CopyBack.Length != Arguments.Length)))
            {
                throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue"));
            }
            Symbols.Method targetProcedure = ResolveCall(container, MemberName, members, Arguments, ArgumentNames, TypeArguments, lookupFlags, false, ref failure);
            if (failure == OverloadResolution.ResolutionFailure.None)
            {
                return(container.InvokeMethod(targetProcedure, Arguments, CopyBack, lookupFlags));
            }
            if (((Arguments.Length > 0) && (members.Length == 1)) && IsZeroArgumentCall(members[0]))
            {
                targetProcedure = ResolveCall(container, MemberName, members, Symbols.NoArguments, Symbols.NoArgumentNames, TypeArguments, lookupFlags, false, ref failure);
                if (failure == OverloadResolution.ResolutionFailure.None)
                {
                    object instance = container.InvokeMethod(targetProcedure, Symbols.NoArguments, null, lookupFlags);
                    if (instance == null)
                    {
                        throw new MissingMemberException(Utils.GetResourceString("IntermediateLateBoundNothingResult1", new string[] { targetProcedure.ToString(), container.VBFriendlyName }));
                    }
                    instance = InternalLateIndexGet(instance, Arguments, ArgumentNames, false, ref failure, CopyBack);
                    if (failure == OverloadResolution.ResolutionFailure.None)
                    {
                        return(instance);
                    }
                }
            }
            ResolveCall(container, MemberName, members, Arguments, ArgumentNames, TypeArguments, lookupFlags, true, ref failure);
            throw new InternalErrorException();
        }
Beispiel #4
0
            private static Symbols.Method VerifyForLoopOperator(Symbols.UserDefinedOperator Op, object ForLoopArgument, Type ForLoopArgumentType)
            {
                Symbols.Method callableUserDefinedOperator = Operators.GetCallableUserDefinedOperator(Op, new object[] { ForLoopArgument, ForLoopArgument });
                if (callableUserDefinedOperator == null)
                {
                    throw new ArgumentException(Utils.GetResourceString("ForLoop_OperatorRequired2", new string[] { Utils.VBFriendlyNameOfType(ForLoopArgumentType, true), Symbols.OperatorNames[(int)Op] }));
                }
                MethodInfo info = callableUserDefinedOperator.AsMethod() as MethodInfo;

                ParameterInfo[] parameters = info.GetParameters();
                switch (Op)
                {
                case Symbols.UserDefinedOperator.Plus:
                case Symbols.UserDefinedOperator.Minus:
                    if ((((parameters.Length != 2) || (parameters[0].ParameterType != ForLoopArgumentType)) || (parameters[1].ParameterType != ForLoopArgumentType)) || (info.ReturnType != ForLoopArgumentType))
                    {
                        throw new ArgumentException(Utils.GetResourceString("ForLoop_UnacceptableOperator2", new string[] { callableUserDefinedOperator.ToString(), Utils.VBFriendlyNameOfType(ForLoopArgumentType, true) }));
                    }
                    return(callableUserDefinedOperator);

                case Symbols.UserDefinedOperator.Multiply:
                case Symbols.UserDefinedOperator.Divide:
                case Symbols.UserDefinedOperator.Power:
                case Symbols.UserDefinedOperator.IntegralDivide:
                case Symbols.UserDefinedOperator.Concatenate:
                case Symbols.UserDefinedOperator.ShiftLeft:
                case Symbols.UserDefinedOperator.ShiftRight:
                case Symbols.UserDefinedOperator.Modulus:
                case Symbols.UserDefinedOperator.Or:
                case Symbols.UserDefinedOperator.Xor:
                case Symbols.UserDefinedOperator.And:
                case Symbols.UserDefinedOperator.Like:
                case Symbols.UserDefinedOperator.Equal:
                case Symbols.UserDefinedOperator.NotEqual:
                case Symbols.UserDefinedOperator.Less:
                    return(callableUserDefinedOperator);

                case Symbols.UserDefinedOperator.LessEqual:
                case Symbols.UserDefinedOperator.GreaterEqual:
                    if (((parameters.Length != 2) || (parameters[0].ParameterType != ForLoopArgumentType)) || (parameters[1].ParameterType != ForLoopArgumentType))
                    {
                        throw new ArgumentException(Utils.GetResourceString("ForLoop_UnacceptableRelOperator2", new string[] { callableUserDefinedOperator.ToString(), Utils.VBFriendlyNameOfType(ForLoopArgumentType, true) }));
                    }
                    return(callableUserDefinedOperator);
                }
                return(callableUserDefinedOperator);
            }