Ejemplo n.º 1
0
            /// <summary>
            /// if a nested type is being moved, this ensures its containing type is partial.
            /// </summary>
            private void AddPartialModifiersToTypeChain(
                DocumentEditor documentEditor,
                bool removeAttributesAndComments,
                bool removeTypeInheritance
                )
            {
                var semanticFacts =
                    State.SemanticDocument.Document.GetRequiredLanguageService <ISemanticFactsService>();
                var typeChain = State.TypeNode.Ancestors().OfType <TTypeDeclarationSyntax>();

                foreach (var node in typeChain)
                {
                    var symbol =
                        (ITypeSymbol?)State.SemanticDocument.SemanticModel.GetDeclaredSymbol(
                            node,
                            CancellationToken
                            );
                    Contract.ThrowIfNull(symbol);
                    if (!semanticFacts.IsPartial(symbol, CancellationToken))
                    {
                        documentEditor.SetModifiers(
                            node,
                            documentEditor.Generator.GetModifiers(node)
                            | DeclarationModifiers.Partial
                            );
                    }

                    if (removeAttributesAndComments)
                    {
                        documentEditor.RemoveAllAttributes(node);
                        documentEditor.RemoveAllComments(node);
                    }

                    if (removeTypeInheritance)
                    {
                        documentEditor.RemoveAllTypeInheritance(node);
                    }
                }

                documentEditor.ReplaceNode(
                    State.TypeNode,
                    (currentNode, generator) =>
                {
                    var currentTypeNode = (TTypeDeclarationSyntax)currentNode;

                    // Trim leading blank lines from the type so we don't have an
                    // excessive number of them.
                    return(RemoveLeadingBlankLines(currentTypeNode));
                }
                    );
            }