コード例 #1
0
        private static async Task <Solution> FixDocumentAsync(FixAllContext fixAllContext, Document document)
        {
            Solution solution    = document.Project.Solution;
            var      diagnostics = await fixAllContext.GetDocumentDiagnosticsAsync(document).ConfigureAwait(false);

            if (diagnostics.Length == 0 || fixAllContext.CodeActionEquivalenceKey != await SA1412CodeFixProvider.GetEquivalenceKeyForDocumentAsync(document).ConfigureAwait(false))
            {
                return(solution);
            }

            return(await SA1412CodeFixProvider.GetTransformedSolutionAsync(document).ConfigureAwait(false));
        }
コード例 #2
0
        private static async Task <Solution> FixDocumentAsync(Solution solution, DocumentId documentId, ImmutableArray <Diagnostic> diagnostics, string codeActionEquivalenceKey, CancellationToken cancellationToken)
        {
            if (diagnostics.IsEmpty)
            {
                return(solution);
            }

            string equivalenceKey = nameof(SA1412CodeFixProvider) + "." + diagnostics[0].Properties[SA1412StoreFilesAsUtf8.EncodingProperty];

            if (codeActionEquivalenceKey != equivalenceKey)
            {
                return(solution);
            }

            Document document = solution.GetDocument(documentId);

            return(await SA1412CodeFixProvider.GetTransformedSolutionAsync(document, cancellationToken).ConfigureAwait(false));
        }
コード例 #3
0
        private static async Task <Solution> FixDocumentAsync(FixAllContext fixAllContext, Document document)
        {
            Solution solution    = document.Project.Solution;
            var      diagnostics = await fixAllContext.GetDocumentDiagnosticsAsync(document).ConfigureAwait(false);

            if (diagnostics.Length == 0)
            {
                return(solution);
            }

            string equivalenceKey = nameof(SA1412CodeFixProvider) + "." + diagnostics[0].Properties[SA1412StoreFilesAsUtf8.EncodingProperty];

            if (fixAllContext.CodeActionEquivalenceKey != equivalenceKey)
            {
                return(solution);
            }

            return(await SA1412CodeFixProvider.GetTransformedSolutionAsync(document, fixAllContext.CancellationToken).ConfigureAwait(false));
        }
コード例 #4
0
        public override async Task <CodeAction> GetFixAsync(FixAllContext fixAllContext)
        {
            Solution newSolution;

            switch (fixAllContext.Scope)
            {
            case FixAllScope.Document:
                newSolution = await FixDocumentAsync(fixAllContext, fixAllContext.Document).ConfigureAwait(false);

                break;

            case FixAllScope.Project:
                newSolution = await GetProjectFixesAsync(fixAllContext, fixAllContext.Project).ConfigureAwait(false);

                break;

            case FixAllScope.Solution:
                newSolution = fixAllContext.Solution;
                var projectIds = newSolution.ProjectIds;
                for (int i = 0; i < projectIds.Count; i++)
                {
                    newSolution = await GetProjectFixesAsync(fixAllContext, newSolution.GetProject(projectIds[i])).ConfigureAwait(false);
                }

                break;

            case FixAllScope.Custom:
            default:
                return(null);
            }

            return(CodeAction.Create(string.Format(MaintainabilityResources.SA1412CodeFix, await SA1412CodeFixProvider.GetEncodingNameForDocumentAsync(fixAllContext.Document).ConfigureAwait(false)), token => Task.FromResult(newSolution)));
        }