Beispiel #1
0
        private async Task <Solution> MoveExceptionFirstAsync(Document document, ArgumentSyntax argument, CancellationToken cancellationToken)
        {
            var root = await document.GetSyntaxRootAsync(cancellationToken);

            var argumentList = argument.AncestorsAndSelf().OfType <ArgumentListSyntax>().First();

            var newList = argumentList.Arguments.Remove(argument);

            newList = newList.Insert(0, argument);

            root     = root.ReplaceNode(argumentList, argumentList.WithArguments(newList));
            document = document.WithSyntaxRoot(root);

            return(document.Project.Solution);
        }
Beispiel #2
0
        private async Task <Solution> MoveExceptionFirstAsync(Document document, ArgumentSyntax argument, CancellationToken cancellationToken)
        {
            var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

            var argumentList = argument.AncestorsAndSelf().OfType <ArgumentListSyntax>().First();

            var newList = argumentList.Arguments.Remove(argument);

            var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);

            var symbolInfo = semanticModel.GetSymbolInfo(argumentList.Parent);

            if (symbolInfo.Symbol is IMethodSymbol methodSymbol && methodSymbol.IsExtensionMethod && methodSymbol.IsStatic)
            {
                // This is a static method invocation of an extension method, so the first parameter is the
                // extended type itself; hence we insert at the second position
                newList = newList.Insert(1, argument);
            }