當前位置: 首頁>>代碼示例>>C#>>正文


C# Suppression.AbstractSuppressionCodeFixProvider類代碼示例

本文整理匯總了C#中Microsoft.CodeAnalysis.CodeFixes.Suppression.AbstractSuppressionCodeFixProvider的典型用法代碼示例。如果您正苦於以下問題:C# AbstractSuppressionCodeFixProvider類的具體用法?C# AbstractSuppressionCodeFixProvider怎麽用?C# AbstractSuppressionCodeFixProvider使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AbstractSuppressionCodeFixProvider類屬於Microsoft.CodeAnalysis.CodeFixes.Suppression命名空間,在下文中一共展示了AbstractSuppressionCodeFixProvider類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetNewStartToken

            private static SyntaxToken GetNewStartToken(SyntaxToken startToken, Diagnostic diagnostic, AbstractSuppressionCodeFixProvider fixer)
            {
                var trivia = startToken.LeadingTrivia.ToImmutableArray();

                // Insert the #pragma disable directive after all leading new line trivia but before first trivia of any other kind.
                int index;
                SyntaxTrivia firstNonEOLTrivia = trivia.FirstOrDefault(t => !fixer.IsEndOfLine(t));
                if (firstNonEOLTrivia == default(SyntaxTrivia))
                {
                    index = trivia.Length;
                }
                else
                {
                    index = trivia.IndexOf(firstNonEOLTrivia);
                }

                bool needsLeadingEOL;
                if (index > 0)
                {
                    needsLeadingEOL = !fixer.IsEndOfLine(trivia[index - 1]);
                }
                else if (startToken.FullSpan.Start == 0)
                {
                    needsLeadingEOL = false;
                }
                else
                {
                    needsLeadingEOL = true;
                }

                var pragmaWarningTrivia = fixer.CreatePragmaDisableDirectiveTrivia(diagnostic, needsLeadingEOL);

                return startToken.WithLeadingTrivia(trivia.InsertRange(index, pragmaWarningTrivia));
            }
開發者ID:noahfalk,項目名稱:roslyn,代碼行數:34,代碼來源:AbstractSuppressionCodeFixProvider.PragmaWarningCodeAction.cs

示例2: Create

 public static AttributeRemoveAction Create(
     AttributeData attribute,
     Project project,
     Diagnostic diagnostic,
     AbstractSuppressionCodeFixProvider fixer)
 {
     return new AttributeRemoveAction(attribute, project, diagnostic, fixer);
 }
開發者ID:CAPCHIK,項目名稱:roslyn,代碼行數:8,代碼來源:AbstractSuppressionCodeFixProvider.RemoveSuppressionCodeAction_Attribute.cs

示例3: RemoveSuppressionCodeAction

 protected RemoveSuppressionCodeAction(
     Diagnostic diagnostic,
     AbstractSuppressionCodeFixProvider fixer,
     bool forFixMultipleContext = false)
     : base(fixer, title: string.Format(FeaturesResources.Remove_Suppression_0, diagnostic.Id))
 {
     _diagnostic = diagnostic;
     _forFixMultipleContext = forFixMultipleContext;
 }
開發者ID:Rickinio,項目名稱:roslyn,代碼行數:9,代碼來源:AbstractSuppressionCodeFixProvider.RemoveSuppressionCodeAction.cs

示例4: LocalSuppressMessageCodeAction

            public LocalSuppressMessageCodeAction(AbstractSuppressionCodeFixProvider fixer, ISymbol targetSymbol, SyntaxNode targetNode, Document document, Diagnostic diagnostic)
            {
                _fixer = fixer;
                _targetSymbol = targetSymbol;
                _targetNode = targetNode;
                _document = document;
                _diagnostic = diagnostic;

                _title = FeaturesResources.SuppressWithLocalSuppressMessage;
            }
開發者ID:GloryChou,項目名稱:roslyn,代碼行數:10,代碼來源:AbstractSuppressionCodeFixProvider.LocalSuppressMessageCodeAction.cs

示例5: PragmaRemoveAction

 private PragmaRemoveAction(
     SuppressionTargetInfo suppressionTargetInfo,
     Document document,
     Diagnostic diagnostic,
     AbstractSuppressionCodeFixProvider fixer,
     bool forFixMultipleContext = false)
     : base(document, diagnostic, fixer, forFixMultipleContext)
 {
     _suppressionTargetInfo = suppressionTargetInfo;
 }
開發者ID:nemec,項目名稱:roslyn,代碼行數:10,代碼來源:AbstractSuppressionCodeFixProvider.RemoveSuppressionCodeAction_Pragma.cs

示例6: AttributeRemoveAction

 private AttributeRemoveAction(
     AttributeData attribute,
     Project project,
     Diagnostic diagnostic,
     AbstractSuppressionCodeFixProvider fixer,
     bool forFixMultipleContext = false)
     : base(diagnostic, fixer, forFixMultipleContext)
 {
     _project = project;
     _attribute = attribute;
 }
開發者ID:CAPCHIK,項目名稱:roslyn,代碼行數:11,代碼來源:AbstractSuppressionCodeFixProvider.RemoveSuppressionCodeAction_Attribute.cs

示例7: Create

            public static PragmaWarningCodeAction Create(
                    SuppressionTargetInfo suppressionTargetInfo,
                    Document document,
                    Diagnostic diagnostic,
                    AbstractSuppressionCodeFixProvider fixer)
            {
                // We need to normalize the leading trivia on start token to account for
                // the trailing trivia on its previous token (and similarly normalize trailing trivia for end token).
                PragmaHelpers.NormalizeTriviaOnTokens(fixer, ref document, ref suppressionTargetInfo);

                return new PragmaWarningCodeAction(suppressionTargetInfo, document, diagnostic, fixer);
            }
開發者ID:ralfkang,項目名稱:roslyn,代碼行數:12,代碼來源:AbstractSuppressionCodeFixProvider.PragmaWarningCodeAction.cs

示例8: PragmaWarningCodeAction

 private PragmaWarningCodeAction(
     SuppressionTargetInfo suppressionTargetInfo,
     Document document,
     Diagnostic diagnostic,
     AbstractSuppressionCodeFixProvider fixer,
     bool forFixMultipleContext = false)
     : base(fixer, title: FeaturesResources.SuppressWithPragma)
 {
     _suppressionTargetInfo = suppressionTargetInfo;
     _document = document;
     _diagnostic = diagnostic;
     _forFixMultipleContext = forFixMultipleContext;
 }
開發者ID:ralfkang,項目名稱:roslyn,代碼行數:13,代碼來源:AbstractSuppressionCodeFixProvider.PragmaWarningCodeAction.cs

示例9: PragmaWarningCodeAction

 public PragmaWarningCodeAction(
     AbstractSuppressionCodeFixProvider fixer,
     SyntaxToken startToken,
     SyntaxToken endToken,
     SyntaxNode nodeWithTokens,
     Document document,
     Diagnostic diagnostic)
     : base (fixer, title: FeaturesResources.SuppressWithPragma)
 {
     _startToken = startToken;
     _endToken = endToken;
     _nodeWithTokens = nodeWithTokens;
     _document = document;
     _diagnostic = diagnostic;
 }
開發者ID:noahfalk,項目名稱:roslyn,代碼行數:15,代碼來源:AbstractSuppressionCodeFixProvider.PragmaWarningCodeAction.cs

示例10: CreateBatchPragmaFix

            public static CodeAction CreateBatchPragmaFix(
                AbstractSuppressionCodeFixProvider suppressionFixProvider,
                Document document,
                ImmutableArray<IPragmaBasedCodeAction> pragmaActions,
                ImmutableArray<Diagnostic> pragmaDiagnostics,
                FixAllContext fixAllContext)
            {
                // This is a temporary generated code action, which doesn't need telemetry, hence suppressing RS0005.
#pragma warning disable RS0005 // Do not use generic CodeAction.Create to create CodeAction
                return CodeAction.Create(
                    ((CodeAction)pragmaActions[0]).Title,
                    createChangedDocument: ct =>
                        BatchPragmaFixesAsync(suppressionFixProvider, document, pragmaActions, pragmaDiagnostics, fixAllContext.CancellationToken),
                    equivalenceKey: fixAllContext.CodeActionEquivalenceKey);
#pragma warning restore RS0005 // Do not use generic CodeAction.Create to create CodeAction
            }
開發者ID:nicro950,項目名稱:roslyn,代碼行數:16,代碼來源:AbstractSuppressionCodeFixProvider.PragmaBatchFixHelpers.cs

示例11: PragmaWarningCodeAction

            public PragmaWarningCodeAction(
                AbstractSuppressionCodeFixProvider fixer,
                SyntaxToken startToken,
                SyntaxToken endToken,
                SyntaxNode nodeWithTokens,
                Document document,
                Diagnostic diagnostic)
            {
                _fixer = fixer;
                _startToken = startToken;
                _endToken = endToken;
                _nodeWithTokens = nodeWithTokens;
                _document = document;
                _diagnostic = diagnostic;

                _title = fixer.TitleForPragmaWarningSuppressionFix;
            }
開發者ID:JRobertGit,項目名稱:roslyn,代碼行數:17,代碼來源:AbstractSuppressionCodeFixProvider.PragmaWarningCodeAction.cs

示例12: CreateAsync

 public static async Task<RemoveSuppressionCodeAction> CreateAsync(                
     SuppressionTargetInfo suppressionTargetInfo,
     Document document,
     Diagnostic diagnostic,
     AbstractSuppressionCodeFixProvider fixer,
     CancellationToken cancellationToken)
 {
     var compilation = await document.Project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
     var attribute = diagnostic.GetSuppressionInfo(compilation).Attribute;
     if (attribute != null)
     {
         return AttributeRemoveAction.Create(attribute, document, diagnostic, fixer);
     }
     else
     {
         return PragmaRemoveAction.Create(suppressionTargetInfo, document, diagnostic, fixer);
     }
 }
開發者ID:nemec,項目名稱:roslyn,代碼行數:18,代碼來源:AbstractSuppressionCodeFixProvider.RemoveSuppressionCodeAction.cs

示例13: CreateChangedSolutionAsync

            private static async Task<Solution> CreateChangedSolutionAsync(AbstractSuppressionCodeFixProvider fixer, Project triggerProject, ImmutableDictionary<Project, ImmutableArray<Diagnostic>> diagnosticsByProject, CancellationToken cancellationToken)
            {
                var currentSolution = triggerProject.Solution;
                foreach (var kvp in diagnosticsByProject)
                {
                    var oldProject = kvp.Key;
                    var currentProject = currentSolution.GetProject(oldProject.Id);
                    var diagnosticsBySymbol = await CreateDiagnosticsBySymbolAsync(fixer, oldProject, kvp.Value, cancellationToken).ConfigureAwait(false);
                    if (diagnosticsBySymbol.Any())
                    {
                        var projectCodeAction = new GlobalSuppressMessageFixAllCodeAction(fixer, diagnosticsBySymbol, currentProject);
                        var newDocument = await projectCodeAction.GetChangedSuppressionDocumentAsync(cancellationToken).ConfigureAwait(false);
                        currentSolution = newDocument.Project.Solution;
                    }
                }

                return currentSolution;
            }
開發者ID:XieShuquan,項目名稱:roslyn,代碼行數:18,代碼來源:AbstractSuppressionCodeFixProvider.GlobalSuppressMessageFixAllCodeAction.cs

示例14: CreateDiagnosticsBySymbolAsync

            private static async Task<IEnumerable<KeyValuePair<ISymbol, ImmutableArray<Diagnostic>>>> CreateDiagnosticsBySymbolAsync(AbstractSuppressionCodeFixProvider fixer, IEnumerable<KeyValuePair<Document, ImmutableArray<Diagnostic>>> diagnosticsByDocument, CancellationToken cancellationToken)
            {
                var diagnosticsMapBuilder = ImmutableDictionary.CreateBuilder<ISymbol, List<Diagnostic>>();
                foreach (var kvp in diagnosticsByDocument)
                {
                    var document = kvp.Key;
                    var diagnostics = kvp.Value;
                    foreach (var diagnostic in diagnostics)
                    {
                        Contract.ThrowIfFalse(diagnostic.Location.IsInSource);
                        var suppressionTargetInfo = await fixer.GetSuppressionTargetInfoAsync(document, diagnostic.Location.SourceSpan, cancellationToken).ConfigureAwait(false);
                        if (suppressionTargetInfo != null)
                        {
                            var targetSymbol = suppressionTargetInfo.TargetSymbol;
                            Contract.ThrowIfNull(targetSymbol);
                            AddDiagnosticForSymbolIfNeeded(targetSymbol, diagnostic, diagnosticsMapBuilder);
                        }
                    }
                }

                return CreateDiagnosticsBySymbol(diagnosticsMapBuilder);
            }
開發者ID:noahfalk,項目名稱:roslyn,代碼行數:22,代碼來源:AbstractSuppressionCodeFixProvider.GlobalSuppressMessageFixAllCodeAction.cs

示例15: GetPositionForPragmaInsertion

            private static int GetPositionForPragmaInsertion(ImmutableArray<SyntaxTrivia> triviaList, TextSpan currentDiagnosticSpan, AbstractSuppressionCodeFixProvider fixer, bool isStartToken, out SyntaxTrivia triviaAtIndex)
            {
                // Start token: Insert the #pragma disable directive just **before** the first end of line trivia prior to diagnostic location.
                // End token: Insert the #pragma disable directive just **after** the first end of line trivia after diagnostic location.

                Func<int, int> getNextIndex = cur => isStartToken ? cur - 1 : cur + 1;
                Func<SyntaxTrivia, bool> shouldConsiderTrivia = trivia =>
                    isStartToken ?
                    trivia.FullSpan.End <= currentDiagnosticSpan.Start :
                    trivia.FullSpan.Start >= currentDiagnosticSpan.End;

                var walkedPastDiagnosticSpan = false;
                var seenEndOfLineTrivia = false;
                var index = isStartToken ? triviaList.Length - 1 : 0;
                while (index >= 0 && index < triviaList.Length)
                {
                    var trivia = triviaList[index];

                    walkedPastDiagnosticSpan = walkedPastDiagnosticSpan || shouldConsiderTrivia(trivia);
                    seenEndOfLineTrivia = seenEndOfLineTrivia ||
                        (fixer.IsEndOfLine(trivia) || 
                         (trivia.HasStructure &&
                          trivia.GetStructure().DescendantTrivia().Any(t => fixer.IsEndOfLine(t))));

                    if (walkedPastDiagnosticSpan && seenEndOfLineTrivia)
                    {
                        break;
                    }

                    index = getNextIndex(index);
                }

                triviaAtIndex = index >= 0 && index < triviaList.Length ?
                    triviaList[index] :
                    default(SyntaxTrivia);

                return index;
            }
開發者ID:robertoenbarcelona,項目名稱:roslyn,代碼行數:38,代碼來源:AbstractSuppressionCodeFixProvider.PragmaHelpers.cs


注:本文中的Microsoft.CodeAnalysis.CodeFixes.Suppression.AbstractSuppressionCodeFixProvider類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。