public override async Task <IMethodSymbol?> TryGetBestMatchAsync(
            Project project,
            INamedTypeSymbol type,
            StackFrameSimpleNameNode methodNode,
            StackFrameParameterList methodArguments,
            StackFrameTypeArgumentList?methodTypeArguments,
            CancellationToken cancellationToken)
        {
            if (methodNode is not StackFrameLocalMethodNameNode localMethodNameNode)
            {
                return(null);
            }

            var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);

            if (compilation is null)
            {
                return(null);
            }

            var containingMethodName = localMethodNameNode.EncapsulatingMethod.Identifier.ToString();
            var semanticFacts        = project.GetRequiredLanguageService <ISemanticFactsService>();
            var candidateFunctions   = type.GetMembers()
                                       .Where(member => member.Name == containingMethodName)
                                       .SelectMany(member => semanticFacts.GetLocalFunctionSymbols(compilation, member, cancellationToken))
                                       .ToImmutableArray();

            return(TryGetBestMatch(candidateFunctions, methodTypeArguments, methodArguments));
        }
Ejemplo n.º 2
0
 public abstract Task <IMethodSymbol?> TryGetBestMatchAsync(
     Project project,
     INamedTypeSymbol type,
     StackFrameSimpleNameNode methodNode,
     StackFrameParameterList methodArguments,
     StackFrameTypeArgumentList?methodTypeArguments,
     CancellationToken cancellationToken);
Ejemplo n.º 3
0
        public StackFrameQualifiedNameNode(StackFrameNameNode left, StackFrameToken dotToken, StackFrameSimpleNameNode right) : base(StackFrameKind.MemberAccess)
        {
            Debug.Assert(dotToken.Kind == StackFrameKind.DotToken);

            Left     = left;
            DotToken = dotToken;
            Right    = right;
        }
Ejemplo n.º 4
0
        public override Task <IMethodSymbol?> TryGetBestMatchAsync(Project project,
                                                                   INamedTypeSymbol type,
                                                                   StackFrameSimpleNameNode methodNode,
                                                                   StackFrameParameterList methodArguments,
                                                                   StackFrameTypeArgumentList?methodTypeArguments,
                                                                   CancellationToken cancellationToken)
        {
            var methodName = methodNode.ToString();

            var candidateMethods = type
                                   .GetMembers()
                                   .OfType <IMethodSymbol>()
                                   .Where(m => m.Name == methodName)
                                   .ToImmutableArray();

            var match = TryGetBestMatch(candidateMethods, methodTypeArguments, methodArguments);

            return(Task.FromResult(match));
        }
Ejemplo n.º 5
0
        private static async Task <IMethodSymbol?> TryGetBestMatchAsync(Project project, string fullyQualifiedTypeName, StackFrameSimpleNameNode methodNode, StackFrameParameterList methodArguments, StackFrameTypeArgumentList?methodTypeArguments, CancellationToken cancellationToken)
        {
            var compilation = await project.GetRequiredCompilationAsync(cancellationToken).ConfigureAwait(false);

            var type = compilation.GetTypeByMetadataName(fullyQualifiedTypeName);

            if (type is null)
            {
                return(null);
            }

            foreach (var resolver in _resolvers)
            {
                var matchingMethod = await resolver.TryGetBestMatchAsync(project, type, methodNode, methodArguments, methodTypeArguments, cancellationToken).ConfigureAwait(false);

                if (matchingMethod is not null)
                {
                    return(matchingMethod);
                }
            }

            return(null);
        }