private static async Task <Document> ChangeToPublicInterfaceImplementationAsync(Document document, ISymbol symbolToChange, CancellationToken cancellationToken) { SymbolEditor editor = SymbolEditor.Create(document); IEnumerable <ISymbol>?explicitImplementations = GetExplicitImplementations(symbolToChange); if (explicitImplementations == null) { return(document); } await editor.EditAllDeclarationsAsync(symbolToChange, (docEditor, declaration) => { SyntaxNode newDeclaration = declaration; foreach (ISymbol implementedMember in explicitImplementations) { SyntaxNode interfaceTypeNode = docEditor.Generator.TypeExpression(implementedMember.ContainingType); newDeclaration = docEditor.Generator.AsPublicInterfaceImplementation(newDeclaration, interfaceTypeNode); } docEditor.ReplaceNode(declaration, newDeclaration); }, cancellationToken).ConfigureAwait(false); return(editor.GetChangedDocuments().First()); }
private async Task <Document> MakeProtected(Document document, ISymbol symbolToChange, CancellationToken cancellationToken) { SymbolEditor editor = SymbolEditor.Create(document); await editor.EditAllDeclarationsAsync(symbolToChange, (docEditor, declaration) => { docEditor.SetAccessibility(declaration, Accessibility.Protected); }, cancellationToken).ConfigureAwait(false); return(editor.GetChangedDocuments().First()); }
private async Task <Document> MakeContainingTypeSealed(Document document, IMethodSymbol methodSymbol, CancellationToken cancellationToken) { SymbolEditor editor = SymbolEditor.Create(document); await editor.EditAllDeclarationsAsync(methodSymbol.ContainingType, (docEditor, declaration) => { DeclarationModifiers modifiers = docEditor.Generator.GetModifiers(declaration); docEditor.SetModifiers(declaration, modifiers + DeclarationModifiers.Sealed); }, cancellationToken).ConfigureAwait(false); return(editor.GetChangedDocuments().First()); }
private static async Task <Document> MakeProtectedAsync(Document document, ISymbol symbolToChange, bool checkSetter, CancellationToken cancellationToken) { SymbolEditor editor = SymbolEditor.Create(document); ISymbol?getter = null; ISymbol?setter = null; if (symbolToChange.Kind == SymbolKind.Property) { var propertySymbol = (IPropertySymbol)symbolToChange; getter = propertySymbol.GetMethod; setter = propertySymbol.SetMethod; } await editor.EditAllDeclarationsAsync(symbolToChange, (docEditor, declaration) => { docEditor.SetAccessibility(declaration, Accessibility.Protected); }, cancellationToken).ConfigureAwait(false); if (getter != null && getter.DeclaredAccessibility == Accessibility.Private) { await editor.EditAllDeclarationsAsync(getter, (docEditor, declaration) => { docEditor.SetAccessibility(declaration, Accessibility.NotApplicable); }, cancellationToken).ConfigureAwait(false); } if (checkSetter && setter != null && setter.DeclaredAccessibility == Accessibility.Private) { await editor.EditAllDeclarationsAsync(setter, (docEditor, declaration) => { docEditor.SetAccessibility(declaration, Accessibility.NotApplicable); }, cancellationToken).ConfigureAwait(false); } return(editor.GetChangedDocuments().First()); }