Ejemplo n.º 1
0
        private static List <Symbols.Method> ResolveConversion(Type TargetType, Type SourceType, List <Symbols.Method> OperatorSet, bool WideningOnly, ref bool ResolutionIsAmbiguous)
        {
            ResolutionIsAmbiguous = false;
            Type sourceType = null;
            Type targetType = null;
            bool genericMembersExistInList     = false;
            List <Symbols.Method> operatorList = new List <Symbols.Method>(OperatorSet.Count);
            List <Symbols.Method> searchList   = new List <Symbols.Method>(OperatorSet.Count);
            List <Type>           types        = new List <Type>(OperatorSet.Count);
            List <Type>           list7        = new List <Type>(OperatorSet.Count);
            List <Type>           list5        = null;
            List <Type>           list6        = null;

            if (!WideningOnly)
            {
                list5 = new List <Type>(OperatorSet.Count);
                list6 = new List <Type>(OperatorSet.Count);
            }
            foreach (Symbols.Method method in OperatorSet)
            {
                MethodBase base2 = method.AsMethod();
                if (WideningOnly && Symbols.IsNarrowingConversionOperator(base2))
                {
                    break;
                }
                Type parameterType = base2.GetParameters()[0].ParameterType;
                Type returnType    = ((MethodInfo)base2).ReturnType;
                if ((!Symbols.IsGeneric(base2) && !Symbols.IsGeneric(base2.DeclaringType)) || (ClassifyPredefinedConversion(returnType, parameterType) == ConversionClass.None))
                {
                    if ((parameterType == SourceType) && (returnType == TargetType))
                    {
                        InsertInOperatorListIfLessGenericThanExisting(method, operatorList, ref genericMembersExistInList);
                        continue;
                    }
                    if (operatorList.Count == 0)
                    {
                        if (Encompasses(parameterType, SourceType) && Encompasses(TargetType, returnType))
                        {
                            searchList.Add(method);
                            if (parameterType == SourceType)
                            {
                                sourceType = parameterType;
                            }
                            else
                            {
                                types.Add(parameterType);
                            }
                            if (returnType == TargetType)
                            {
                                targetType = returnType;
                            }
                            else
                            {
                                list7.Add(returnType);
                            }
                            continue;
                        }
                        if ((!WideningOnly && Encompasses(parameterType, SourceType)) && NotEncompasses(TargetType, returnType))
                        {
                            searchList.Add(method);
                            if (parameterType == SourceType)
                            {
                                sourceType = parameterType;
                            }
                            else
                            {
                                types.Add(parameterType);
                            }
                            if (returnType == TargetType)
                            {
                                targetType = returnType;
                            }
                            else
                            {
                                list6.Add(returnType);
                            }
                            continue;
                        }
                        if ((!WideningOnly && NotEncompasses(parameterType, SourceType)) && NotEncompasses(TargetType, returnType))
                        {
                            searchList.Add(method);
                            if (parameterType == SourceType)
                            {
                                sourceType = parameterType;
                            }
                            else
                            {
                                list5.Add(parameterType);
                            }
                            if (returnType == TargetType)
                            {
                                targetType = returnType;
                            }
                            else
                            {
                                list6.Add(returnType);
                            }
                        }
                    }
                }
            }
            if ((operatorList.Count == 0) && (searchList.Count > 0))
            {
                if (sourceType == null)
                {
                    if (types.Count > 0)
                    {
                        sourceType = MostEncompassed(types);
                    }
                    else
                    {
                        sourceType = MostEncompassing(list5);
                    }
                }
                if (targetType == null)
                {
                    if (list7.Count > 0)
                    {
                        targetType = MostEncompassing(list7);
                    }
                    else
                    {
                        targetType = MostEncompassed(list6);
                    }
                }
                if ((sourceType == null) || (targetType == null))
                {
                    ResolutionIsAmbiguous = true;
                    return(new List <Symbols.Method>());
                }
                FindBestMatch(targetType, sourceType, searchList, operatorList, ref genericMembersExistInList);
            }
            if (operatorList.Count > 1)
            {
                ResolutionIsAmbiguous = true;
            }
            return(operatorList);
        }