Esempio n. 1
0
 internal static MethodBase GetCallTarget(Symbols.Method TargetProcedure, BindingFlags Flags)
 {
     if (TargetProcedure.IsMethod)
     {
         return(TargetProcedure.AsMethod());
     }
     if (TargetProcedure.IsProperty)
     {
         return(MatchesPropertyRequirements(TargetProcedure, Flags));
     }
     return(null);
 }
Esempio n. 2
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);
            }
 private static void FindBestMatch(Type TargetType, Type SourceType, List <Symbols.Method> SearchList, List <Symbols.Method> ResultList, ref bool GenericMembersExistInList)
 {
     List <Symbols.Method> .Enumerator enumerator;
     try
     {
         enumerator = SearchList.GetEnumerator();
         while (enumerator.MoveNext())
         {
             Symbols.Method current       = enumerator.Current;
             MethodBase     base2         = current.AsMethod();
             Type           parameterType = base2.GetParameters()[0].ParameterType;
             Type           returnType    = ((MethodInfo)base2).ReturnType;
             if ((parameterType == SourceType) && (returnType == TargetType))
             {
                 InsertInOperatorListIfLessGenericThanExisting(current, ResultList, ref GenericMembersExistInList);
             }
         }
     }
     finally
     {
         enumerator.Dispose();
     }
 }
Esempio n. 4
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 }));
        }
 private static void InsertIfMethodAvailable(MemberInfo NewCandidate, ParameterInfo[] NewCandidateSignature, int NewCandidateParamArrayIndex, bool ExpandNewCandidateParamArray, object[] Arguments, int ArgumentCount, string[] ArgumentNames, Type[] TypeArguments, bool CollectOnlyOperators, List<Symbols.Method> Candidates)
 {
     Symbols.Method candidate = null;
     if (!CollectOnlyOperators)
     {
         MethodBase method = NewCandidate as MethodBase;
         bool flag = false;
         if ((NewCandidate.MemberType == MemberTypes.Method) && Symbols.IsRawGeneric(method))
         {
             candidate = new Symbols.Method(method, NewCandidateSignature, NewCandidateParamArrayIndex, ExpandNewCandidateParamArray);
             RejectUncallableProcedure(candidate, Arguments, ArgumentNames, TypeArguments);
             NewCandidate = candidate.AsMethod();
             NewCandidateSignature = candidate.Parameters;
         }
         if (((NewCandidate != null) && (NewCandidate.MemberType == MemberTypes.Method)) && Symbols.IsRawGeneric(NewCandidate as MethodBase))
         {
             flag = true;
         }
         int num5 = Candidates.Count - 1;
         for (int i = 0; i <= num5; i++)
         {
             Symbols.Method method2 = Candidates[i];
             if (method2 != null)
             {
                 MethodBase base3;
                 ParameterInfo[] parameters = method2.Parameters;
                 if (method2.IsMethod)
                 {
                     base3 = method2.AsMethod();
                 }
                 else
                 {
                     base3 = null;
                 }
                 if (NewCandidate != method2)
                 {
                     int index = 0;
                     int num = 0;
                     int num6 = ArgumentCount;
                     for (int j = 1; j <= num6; j++)
                     {
                         bool bothLose = false;
                         bool leftWins = false;
                         bool rightWins = false;
                         CompareParameterSpecificity(null, NewCandidateSignature[index], method, ExpandNewCandidateParamArray, parameters[num], base3, method2.ParamArrayExpanded, ref leftWins, ref rightWins, ref bothLose);
                         if (!((bothLose | leftWins) | rightWins))
                         {
                             if ((index != NewCandidateParamArrayIndex) || !ExpandNewCandidateParamArray)
                             {
                                 index++;
                             }
                             if ((num != method2.ParamArrayIndex) || !method2.ParamArrayExpanded)
                             {
                                 num++;
                             }
                         }
                     }
                     if (!IsExactSignatureMatch(NewCandidateSignature, Symbols.GetTypeParameters(NewCandidate).Length, method2.Parameters, method2.TypeParameters.Length))
                     {
                         if (!flag && ((base3 == null) || !Symbols.IsRawGeneric(base3)))
                         {
                             if (ExpandNewCandidateParamArray || !method2.ParamArrayExpanded)
                             {
                                 if (ExpandNewCandidateParamArray && !method2.ParamArrayExpanded)
                                 {
                                     return;
                                 }
                                 if (ExpandNewCandidateParamArray || method2.ParamArrayExpanded)
                                 {
                                     if (index <= num)
                                     {
                                         if (num > index)
                                         {
                                             return;
                                         }
                                     }
                                     else
                                     {
                                         Candidates[i] = null;
                                     }
                                 }
                             }
                             else
                             {
                                 Candidates[i] = null;
                             }
                         }
                     }
                     else
                     {
                         if (NewCandidate.DeclaringType == method2.DeclaringType)
                         {
                             break;
                         }
                         if ((flag || (base3 == null)) || !Symbols.IsRawGeneric(base3))
                         {
                             return;
                         }
                     }
                 }
             }
         }
     }
     if (candidate != null)
     {
         Candidates.Add(candidate);
     }
     else if (NewCandidate.MemberType == MemberTypes.Property)
     {
         Candidates.Add(new Symbols.Method((PropertyInfo) NewCandidate, NewCandidateSignature, NewCandidateParamArrayIndex, ExpandNewCandidateParamArray));
     }
     else
     {
         Candidates.Add(new Symbols.Method((MethodBase) NewCandidate, NewCandidateSignature, NewCandidateParamArrayIndex, ExpandNewCandidateParamArray));
     }
 }