Ejemplo n.º 1
0
        public static Task <Document> RefactorAsync(
            Document document,
            ConstructorDeclarationSyntax constructor,
            CancellationToken cancellationToken)
        {
            ParameterListSyntax          parameterList = constructor.ParameterList;
            ConstructorInitializerSyntax initializer   = constructor.Initializer;

            if (parameterList.GetTrailingTrivia().All(f => f.IsWhitespaceOrEndOfLineTrivia()) &&
                initializer.GetLeadingTrivia().All(f => f.IsWhitespaceOrEndOfLineTrivia()))
            {
                ConstructorDeclarationSyntax newConstructor = constructor
                                                              .WithParameterList(parameterList.WithTrailingTrivia(initializer.GetTrailingTrivia()))
                                                              .WithInitializer(null);

                return(document.ReplaceNodeAsync(constructor, newConstructor, cancellationToken));
            }
            else
            {
                return(document.RemoveNodeAsync(initializer, SyntaxRemoveOptions.KeepExteriorTrivia, cancellationToken));
            }
        }