public sealed override Task RegisterCodeFixesAsync(CodeFixContext context) { var project = context.Document.Project; var publicSurfaceAreaDocument = PublicApiFixHelpers.GetUnshippedDocument(project); foreach (Diagnostic diagnostic in context.Diagnostics) { string minimalSymbolName = diagnostic.Properties[DeclarePublicApiAnalyzer.MinimalNamePropertyBagKey]; string publicSurfaceAreaSymbolName = diagnostic.Properties[DeclarePublicApiAnalyzer.PublicApiNamePropertyBagKey]; ImmutableHashSet <string> siblingSymbolNamesToRemove = diagnostic.Properties[DeclarePublicApiAnalyzer.PublicApiNamesOfSiblingsToRemovePropertyBagKey] .Split(DeclarePublicApiAnalyzer.PublicApiNamesOfSiblingsToRemovePropertyBagValueSeparator.ToCharArray()) .ToImmutableHashSet(); context.RegisterCodeFix( new AdditionalDocumentChangeAction( $"Add {minimalSymbolName} to public API", c => GetFixAsync(publicSurfaceAreaDocument, project, publicSurfaceAreaSymbolName, siblingSymbolNamesToRemove, c)), diagnostic); } return(Task.CompletedTask); }
public sealed override Task RegisterCodeFixesAsync(CodeFixContext context) { Project project = context.Document.Project; foreach (Diagnostic diagnostic in context.Diagnostics) { string minimalSymbolName = diagnostic.Properties[DeclarePublicApiAnalyzer.MinimalNamePropertyBagKey]; string publicSymbolName = diagnostic.Properties[DeclarePublicApiAnalyzer.PublicApiNamePropertyBagKey]; string publicSymbolNameWithNullability = diagnostic.Properties[DeclarePublicApiAnalyzer.PublicApiNameWithNullabilityPropertyBagKey]; bool isShippedDocument = diagnostic.Properties[DeclarePublicApiAnalyzer.PublicApiIsShippedPropertyBagKey] == "true"; TextDocument?document = isShippedDocument ? PublicApiFixHelpers.GetShippedDocument(project) : PublicApiFixHelpers.GetUnshippedDocument(project); if (document != null) { context.RegisterCodeFix( new DeclarePublicApiFix.AdditionalDocumentChangeAction( $"Annotate {minimalSymbolName} in public API", c => GetFix(document, publicSymbolName, publicSymbolNameWithNullability, c)), diagnostic); } } return(Task.CompletedTask);