Exemplo n.º 1
0
        OverloadResolutionErrors IsUnambiguousCall(ExpectedTargetDetails expectedTargetDetails, IMethod method,
                                                   TranslatedExpression target, IType[] typeArguments, IList <TranslatedExpression> arguments)
        {
            var lookup = new MemberLookup(resolver.CurrentTypeDefinition, resolver.CurrentTypeDefinition.ParentAssembly);
            var or     = new OverloadResolution(resolver.Compilation, arguments.SelectArray(a => a.ResolveResult), typeArguments: typeArguments);

            if (expectedTargetDetails.CallOpCode == OpCode.NewObj)
            {
                foreach (IMethod ctor in method.DeclaringType.GetConstructors())
                {
                    if (lookup.IsAccessible(ctor, allowProtectedAccess: resolver.CurrentTypeDefinition == method.DeclaringTypeDefinition))
                    {
                        or.AddCandidate(ctor);
                    }
                }
            }
            else
            {
                var result = lookup.Lookup(target.ResolveResult, method.Name, EmptyList <IType> .Instance, true) as MethodGroupResolveResult;
                if (result == null)
                {
                    return(OverloadResolutionErrors.AmbiguousMatch);
                }
                or.AddMethodLists(result.MethodsGroupedByDeclaringType.ToArray());
            }
            if (or.BestCandidateErrors != OverloadResolutionErrors.None)
            {
                return(or.BestCandidateErrors);
            }
            if (!IsAppropriateCallTarget(expectedTargetDetails, method, or.GetBestCandidateWithSubstitutedTypeArguments()))
            {
                return(OverloadResolutionErrors.AmbiguousMatch);
            }
            return(OverloadResolutionErrors.None);
        }