Exemple #1
0
        private async Task <string> GetArgumentListWithLocalVariables(Document document, IInvocation invocation, bool generateNamedParameters, SemanticModel semanticModel)
        {
            var mappingSourceFinder = LocalScopeMappingSourceFinder.FromScope(semanticModel, invocation.SourceNode, AllowedSymbolsForCompletion);

            mappingSourceFinder.AllowMatchOnlyByTypeWhenSingleCandidate = true;

            var syntaxGenerator       = SyntaxGenerator.GetGenerator(document);
            var overloadParameterSets = invocation.GetOverloadParameterSets(semanticModel);

            if (overloadParameterSets != null)
            {
                var mappingEngine   = new MappingEngine(semanticModel, syntaxGenerator);
                var mappingContext  = new MappingContext(invocation.SourceNode, semanticModel);
                var parametersMatch = await MethodHelper.FindBestParametersMatch(mappingSourceFinder, overloadParameterSets, mappingContext).ConfigureAwait(false);

                if (parametersMatch != null)
                {
                    var argumentList = await parametersMatch.ToArgumentListSyntaxAsync(mappingEngine, mappingContext, generateNamedParameters).ConfigureAwait(false);

                    var chunks = argumentList.Arguments.Select(a => a.ToString());
                    return(string.Join(", ", chunks));
                }
            }

            return(null);
        }
        private async Task <Document> UseLocalVariablesAsParameters(Document document, IInvocation invocation, bool generateNamedParameters, CancellationToken cancellationToken)
        {
            var semanticModel = await document.GetSemanticModelAsync(cancellationToken);

            var mappingSourceFinder = LocalScopeMappingSourceFinder.FromScope(semanticModel, invocation.SourceNode);

            return(await CodeFixHelper.FixInvocationWithParameters(document, invocation, generateNamedParameters, semanticModel, mappingSourceFinder, cancellationToken));
        }