/// <summary> /// if a nested type is being moved, this ensures its containing type is partial. /// </summary> private void AddPartialModifiersToTypeChain( DocumentEditor documentEditor, bool removeAttributesAndComments) { var semanticFacts = State.SemanticDocument.Document.GetLanguageService <ISemanticFactsService>(); var typeChain = State.TypeNode.Ancestors().OfType <TTypeDeclarationSyntax>(); foreach (var node in typeChain) { var symbol = (ITypeSymbol)State.SemanticDocument.SemanticModel.GetDeclaredSymbol(node, CancellationToken); if (!semanticFacts.IsPartial(symbol, CancellationToken)) { documentEditor.SetModifiers(node, documentEditor.Generator.GetModifiers(node) | DeclarationModifiers.Partial); } if (removeAttributesAndComments) { documentEditor.RemoveAllAttributes(node); documentEditor.RemoveAllComments(node); } } documentEditor.ReplaceNode(State.TypeNode, (currentNode, generator) => { var currentTypeNode = (TTypeDeclarationSyntax)currentNode; // Trim leading whitespace from the type so we don't have excessive // leading blank lines. return(RemoveLeadingWhitespace(currentTypeNode)); }); }
/// <summary> /// if a nested type is being moved, this ensures its containing type is partial. /// </summary> private void AddPartialModifiersToTypeChain( DocumentEditor documentEditor, bool removeAttributes) { var semanticFacts = State.SemanticDocument.Document.GetLanguageService <ISemanticFactsService>(); var typeChain = State.TypeNode.Ancestors().OfType <TTypeDeclarationSyntax>(); foreach (var node in typeChain) { var symbol = (ITypeSymbol)State.SemanticDocument.SemanticModel.GetDeclaredSymbol(node, CancellationToken); if (!semanticFacts.IsPartial(symbol, CancellationToken)) { documentEditor.SetModifiers(node, DeclarationModifiers.Partial); } if (removeAttributes) { documentEditor.RemoveAllAttributes(node); } } }