private SyntaxNode FixOutParameters(ArgumentListSyntax argumentListSyntax) { var invocationExpression = argumentListSyntax.FirstAncestorOrSelf <InvocationExpressionSyntax>(); if (invocationExpression == null) { return(argumentListSyntax); } if (_semanticModel.GetSymbolInfo(invocationExpression) .ExtractBestMatch(s => s is IMethodSymbol ims && argumentListSyntax.Arguments.Count == ims.Parameters.Length) is IMethodSymbol methodSymbol) { //Won't work for named parameters for (var index = 0; index < Math.Min(argumentListSyntax.Arguments.Count, methodSymbol.Parameters.Length); index++) { var argument = argumentListSyntax.Arguments[index]; var refOrOutKeyword = GetRefKeyword(methodSymbol.Parameters[index]); var currentSyntaxKind = argumentListSyntax.Arguments[index].Kind(); if (!refOrOutKeyword.IsKind(currentSyntaxKind)) { argumentListSyntax = argumentListSyntax.ReplaceNode(argument, argument.WithRefOrOutKeyword(refOrOutKeyword)); } } } return(argumentListSyntax); }
private SyntaxNode FixOutParameters(ArgumentListSyntax argumentListSyntax) { var invocationExpression = argumentListSyntax.FirstAncestorOrSelf <InvocationExpressionSyntax>(); if (invocationExpression == null) { return(argumentListSyntax); } var methodSymbol = _semanticModel.GetSymbolInfo(invocationExpression).CandidateSymbols.OfType <IMethodSymbol>() .FirstOrDefault(s => argumentListSyntax.Arguments.Count == s.Parameters.Length); if (methodSymbol != null) { //Won't work for named parameters for (var index = 0; index < Math.Min(argumentListSyntax.Arguments.Count, methodSymbol.Parameters.Length); index++) { var argument = argumentListSyntax.Arguments[index]; var refOrOutKeyword = GetRefKeyword(methodSymbol.Parameters[index]); var currentSyntaxKind = argumentListSyntax.Arguments[index].Kind(); if (!refOrOutKeyword.IsKind(currentSyntaxKind)) { argumentListSyntax = argumentListSyntax.ReplaceNode(argument, argument.WithRefOrOutKeyword(refOrOutKeyword)); } } } return(argumentListSyntax); }