• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Diagnostics.DiagnosticData类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Microsoft.CodeAnalysis.Diagnostics.DiagnosticData的典型用法代码示例。如果您正苦于以下问题:C# DiagnosticData类的具体用法?C# DiagnosticData怎么用?C# DiagnosticData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DiagnosticData类属于Microsoft.CodeAnalysis.Diagnostics命名空间,在下文中一共展示了DiagnosticData类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: PreviewPane

        object IPreviewPaneService.GetPreviewPane(DiagnosticData diagnostic, string language, string projectType, IList<object> previewContent)
        {
            var title = diagnostic?.Message;

            if (string.IsNullOrWhiteSpace(title))
            {
                if (previewContent == null)
                {
                    // Bail out in cases where there is nothing to put in the header section
                    // of the preview pane and no preview content (i.e. no diff view) either.
                    return null;
                }

                return new PreviewPane(
                    severityIcon: null, id: null, title: null, description: null, helpLink: null, helpLinkToolTipText: null,
                    previewContent: previewContent, logIdVerbatimInTelemetry: false);
            }

            var helpLinkToolTipText = string.Empty;
            Uri helpLink = GetHelpLink(diagnostic, language, projectType, out helpLinkToolTipText);

            return new PreviewPane(
                severityIcon: GetSeverityIconForDiagnostic(diagnostic),
                id: diagnostic.Id, title: title,
                description: diagnostic.Description.ToString(CultureInfo.CurrentUICulture),
                helpLink: helpLink,
                helpLinkToolTipText: helpLinkToolTipText,
                previewContent: previewContent,
                logIdVerbatimInTelemetry: diagnostic.CustomTags.Contains(WellKnownDiagnosticTags.Telemetry));
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:30,代码来源:PreviewPaneService.cs


示例2: GetSeverityIconForDiagnostic

        private static Image GetSeverityIconForDiagnostic(DiagnosticData diagnostic)
        {
            ImageMoniker? moniker = null;
            switch (diagnostic.Severity)
            {
                case DiagnosticSeverity.Error:
                    moniker = KnownMonikers.StatusError;
                    break;
                case DiagnosticSeverity.Warning:
                    moniker = KnownMonikers.StatusWarning;
                    break;
                case DiagnosticSeverity.Info:
                    moniker = KnownMonikers.StatusInformation;
                    break;
                case DiagnosticSeverity.Hidden:
                    moniker = KnownMonikers.StatusHidden;
                    break;
            }

            if (moniker.HasValue)
            {
                return new CrispImage
                {
                    Moniker = moniker.Value
                };
            }

            return null;
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:29,代码来源:PreviewPaneService.cs


示例3: CreateBingQueryUri

        public static Uri CreateBingQueryUri(DiagnosticData diagnostic)
        {
            var errorCode = diagnostic.Id;
            var title = diagnostic.ENUMessageForBingSearch;
            diagnostic.Workspace.GetLanguageAndProjectType(diagnostic.ProjectId, out var language, out var projectType);

            return CreateBingQueryUri(errorCode, title, language, projectType);
        }
开发者ID:GuilhermeSa,项目名称:roslyn,代码行数:8,代码来源:BrowserHelper.cs


示例4: GetPreviewPane

        public object GetPreviewPane(DiagnosticData diagnostic, string language, string projectType, IReadOnlyList<object> previewContents)
        {
            var contents = previewContents ?? SpecializedCollections.EmptyEnumerable<object>();

            foreach (var content in contents.OfType<IDisposable>())
            {
                content.Dispose();
            }

            // test only mock object
            return new Grid();
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:12,代码来源:MockPreviewPaneService.cs


示例5: RaiseAnalyzerChangedWarning

        private void RaiseAnalyzerChangedWarning(ProjectId projectId, string analyzerPath)
        {
            string message = string.Format(ServicesVSResources.WRN_AnalyzerChangedMessage, analyzerPath);

            DiagnosticData data = new DiagnosticData(
                IDEDiagnosticIds.AnalyzerChangedId,
                ServicesVSResources.ErrorCategory,
                message,
                ServicesVSResources.WRN_AnalyzerChangedMessage,
                severity: DiagnosticSeverity.Warning,
                isEnabledByDefault: true,
                warningLevel: 0,
                workspace: _workspace,
                projectId: projectId,
                title: ServicesVSResources.WRN_AnalyzerChangedTitle);

            _updateSource.UpdateDiagnosticsForProject(projectId, Tuple.Create(s_analyzerChangedErrorId, analyzerPath), SpecializedCollections.SingletonEnumerable(data));
        }
开发者ID:noahstein,项目名称:roslyn,代码行数:18,代码来源:AnalyzerFileWatcherService.cs


示例6: GetHelpLink

        private static Uri GetHelpLink(DiagnosticData diagnostic, string language, string projectType, out string helpLinkToolTipText)
        {
            var isBing = false;
            helpLinkToolTipText = string.Empty;
            if (!BrowserHelper.TryGetUri(diagnostic.HelpLink, out var helpLink))
            {
                // We use the ENU version of the message for bing search.
                helpLink = BrowserHelper.CreateBingQueryUri(diagnostic.Id, diagnostic.ENUMessageForBingSearch, language, projectType);
                isBing = true;
            }

            // We make sure not to use Uri.AbsoluteUri for the url displayed in the tooltip so that the url displayed in the tooltip stays human readable.
            if (helpLink != null)
            {
                helpLinkToolTipText =
                    string.Format(ServicesVSResources.Get_help_for_0_1_2_3, diagnostic.Id,
                        isBing ? ServicesVSResources.from_Bing : null, Environment.NewLine, helpLink);
            }

            return helpLink;
        }
开发者ID:GuilhermeSa,项目名称:roslyn,代码行数:21,代码来源:PreviewPaneService.cs


示例7: ReportAnalyzerDiagnostic

        public void ReportAnalyzerDiagnostic(DiagnosticAnalyzer analyzer, DiagnosticData diagnosticData, Project project)
        {
            if (diagnosticData.Workspace != this.Workspace)
            {
                return;
            }

            bool raiseDiagnosticsUpdated = true;

            var dxs = ImmutableInterlocked.AddOrUpdate(ref _analyzerHostDiagnosticsMap,
                analyzer,
                ImmutableHashSet.Create(diagnosticData),
                (a, existing) =>
                {
                    var newDiags = existing.Add(diagnosticData);
                    raiseDiagnosticsUpdated = newDiags.Count > existing.Count;
                    return newDiags;
                });

            if (raiseDiagnosticsUpdated)
            {
                RaiseDiagnosticsUpdated(MakeCreatedArgs(analyzer, dxs, project));
            }
        }
开发者ID:jkotas,项目名称:roslyn,代码行数:24,代码来源:AbstractHostDiagnosticUpdateSource.cs


示例8: UpdatePosition

            private DiagnosticData UpdatePosition(DiagnosticData diagnostic, SyntaxTree tree, int delta)
            {
                var start = Math.Min(Math.Max(diagnostic.TextSpan.Start + delta, 0), tree.Length);
                var newSpan = new TextSpan(start, start >= tree.Length ? 0 : diagnostic.TextSpan.Length);

                var mappedLineInfo = tree.GetMappedLineSpan(newSpan);
                var originalLineInfo = tree.GetLineSpan(newSpan);

                return new DiagnosticData(
                    diagnostic.Id,
                    diagnostic.Category,
                    diagnostic.Message,
                    diagnostic.MessageFormat,
                    diagnostic.Severity,
                    diagnostic.DefaultSeverity,
                    diagnostic.IsEnabledByDefault,
                    diagnostic.WarningLevel,
                    diagnostic.CustomTags,
                    diagnostic.Workspace,
                    diagnostic.ProjectId,
                    diagnostic.DocumentId,
                    newSpan,
                    mappedFilePath: mappedLineInfo.HasMappedPath ? mappedLineInfo.Path : null,
                    mappedStartLine: mappedLineInfo.StartLinePosition.Line,
                    mappedStartColumn: mappedLineInfo.StartLinePosition.Character,
                    mappedEndLine: mappedLineInfo.EndLinePosition.Line,
                    mappedEndColumn: mappedLineInfo.EndLinePosition.Character,
                    originalFilePath: originalLineInfo.Path,
                    originalStartLine: originalLineInfo.StartLinePosition.Line,
                    originalStartColumn: originalLineInfo.StartLinePosition.Character,
                    originalEndLine: originalLineInfo.EndLinePosition.Line,
                    originalEndColumn: originalLineInfo.EndLinePosition.Character,
                    description: diagnostic.Description,
                    helpLink: diagnostic.HelpLink);
            }
开发者ID:JinGuoGe,项目名称:roslyn,代码行数:35,代码来源:DiagnosticAnalyzerService.IncrementalAnalyzer.cs


示例9: UpdateRuleSetError

        protected void UpdateRuleSetError(IRuleSetFile ruleSetFile)
        {
            if (this.HostDiagnosticUpdateSource == null)
            {
                return;
            }

            if (ruleSetFile == null ||
                ruleSetFile.GetException() == null)
            {
                this.HostDiagnosticUpdateSource.ClearDiagnosticsForProject(this.Id, RuleSetErrorId);
            }
            else
            {
                string id = ServicesVSResources.ERR_CantReadRulesetFileId;
                string category = ServicesVSResources.ErrorCategory;
                string message = string.Format(ServicesVSResources.ERR_CantReadRulesetFileMessage, ruleSetFile.FilePath, ruleSetFile.GetException().Message);
                DiagnosticData data = new DiagnosticData(id, category, message, ServicesVSResources.ERR_CantReadRulesetFileMessage, DiagnosticSeverity.Error, DiagnosticSeverity.Error, true, 0, ImmutableArray<string>.Empty, this.Workspace, this.Id);

                this.HostDiagnosticUpdateSource.UpdateDiagnosticsForProject(this.Id, RuleSetErrorId, SpecializedCollections.SingletonEnumerable(data));
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:22,代码来源:AbstractProject.cs


示例10: GetSelectedItemsAsync

        /// <summary>
        /// Gets <see cref="DiagnosticData"/> objects for selected error list entries.
        /// For remove suppression, the method also returns selected external source diagnostics.
        /// </summary>
        public async Task<ImmutableArray<DiagnosticData>> GetSelectedItemsAsync(bool isAddSuppression, CancellationToken cancellationToken)
        {
            var builder = ImmutableArray.CreateBuilder<DiagnosticData>();
            Dictionary<string, Project> projectNameToProjectMapOpt = null;
            Dictionary<Project, ImmutableDictionary<string, Document>> filePathToDocumentMapOpt = null;

            foreach (var entryHandle in _tableControl.SelectedEntries)
            {
                cancellationToken.ThrowIfCancellationRequested();

                DiagnosticData diagnosticData = null;
                int index;
                var roslynSnapshot = GetEntriesSnapshot(entryHandle, out index);
                if (roslynSnapshot != null)
                {
                    diagnosticData = roslynSnapshot.GetItem(index)?.Primary;
                }
                else if (!isAddSuppression)
                {
                    // For suppression removal, we also need to handle FxCop entries.
                    bool isSuppressedEntry;
                    if (!IsNonRoslynEntrySupportingSuppressionState(entryHandle, out isSuppressedEntry) ||
                        !isSuppressedEntry)
                    {
                        continue;
                    }

                    string errorCode = null, category = null, message = null, filePath = null, projectName = null;
                    int line = -1; // FxCop only supports line, not column.
                    DiagnosticDataLocation location = null;

                    if (entryHandle.TryGetValue(StandardTableColumnDefinitions.ErrorCode, out errorCode) && !string.IsNullOrEmpty(errorCode) &&
                        entryHandle.TryGetValue(StandardTableColumnDefinitions.ErrorCategory, out category) && !string.IsNullOrEmpty(category) &&
                        entryHandle.TryGetValue(StandardTableColumnDefinitions.Text, out message) && !string.IsNullOrEmpty(message) &&
                        entryHandle.TryGetValue(StandardTableColumnDefinitions.ProjectName, out projectName) && !string.IsNullOrEmpty(projectName))
                    {
                        if (projectNameToProjectMapOpt == null)
                        {
                            projectNameToProjectMapOpt = new Dictionary<string, Project>();
                            foreach (var p in _workspace.CurrentSolution.Projects)
                            {
                                projectNameToProjectMapOpt[p.Name] = p;
                            }
                        }

                        cancellationToken.ThrowIfCancellationRequested();

                        Project project;
                        if (!projectNameToProjectMapOpt.TryGetValue(projectName, out project))
                        {
                            // bail out
                            continue;
                        }

                        Document document = null;
                        var hasLocation = (entryHandle.TryGetValue(StandardTableColumnDefinitions.DocumentName, out filePath) && !string.IsNullOrEmpty(filePath)) &&
                            (entryHandle.TryGetValue(StandardTableColumnDefinitions.Line, out line) && line >= 0);
                        if (hasLocation)
                        {
                            if (string.IsNullOrEmpty(filePath) || line < 0)
                            {
                                // bail out
                                continue;
                            }

                            ImmutableDictionary<string, Document> filePathMap;
                            filePathToDocumentMapOpt = filePathToDocumentMapOpt ?? new Dictionary<Project, ImmutableDictionary<string, Document>>();
                            if (!filePathToDocumentMapOpt.TryGetValue(project, out filePathMap))
                            {
                                filePathMap = await GetFilePathToDocumentMapAsync(project, cancellationToken).ConfigureAwait(false);
                                filePathToDocumentMapOpt[project] = filePathMap;
                            }

                            if (!filePathMap.TryGetValue(filePath, out document))
                            {
                                // bail out
                                continue;
                            }

                            var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
                            var linePosition = new LinePosition(line, 0);
                            var linePositionSpan = new LinePositionSpan(start: linePosition, end: linePosition);
                            var textSpan = (await tree.GetTextAsync(cancellationToken).ConfigureAwait(false)).Lines.GetTextSpan(linePositionSpan);
                            location = new DiagnosticDataLocation(document.Id, textSpan, filePath,
                                originalStartLine: linePosition.Line, originalStartColumn: linePosition.Character,
                                originalEndLine: linePosition.Line, originalEndColumn: linePosition.Character);
                        }

                        Contract.ThrowIfNull(project);
                        Contract.ThrowIfFalse((document != null) == (location != null));

                        // Create a diagnostic with correct values for fields we care about: id, category, message, isSuppressed, location
                        // and default values for the rest of the fields (not used by suppression fixer).
                        diagnosticData = new DiagnosticData(
                            id: errorCode,
                            category: category,
//.........这里部分代码省略.........
开发者ID:robertoenbarcelona,项目名称:roslyn,代码行数:101,代码来源:VisualStudioDiagnosticListSuppressionStateService.cs


示例11: IsSynthesizedExternalSourceDiagnostic

 public static bool IsSynthesizedExternalSourceDiagnostic(DiagnosticData diagnostic)
 {
     return HasCustomTag(diagnostic.CustomTags, SynthesizedExternalSourceDiagnosticTag);
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:4,代码来源:SuppressionHelpers.cs


示例12: IsNotConfigurableDiagnostic

 public static bool IsNotConfigurableDiagnostic(DiagnosticData diagnostic)
 {
     return HasCustomTag(diagnostic.CustomTags, WellKnownDiagnosticTags.NotConfigurable);
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:4,代码来源:SuppressionHelpers.cs


示例13: CreateDiagnosticAndFireEvents

            internal void CreateDiagnosticAndFireEvents(Location location)
            {
                var document = _workspace.CurrentSolution.Projects.Single().Documents.Single();
                _diagnostic = DiagnosticData.Create(document,
                    Diagnostic.Create(DiagnosticId, "MockCategory", "MockMessage", DiagnosticSeverity.Error, DiagnosticSeverity.Error, isEnabledByDefault: true, warningLevel: 0,
                    location: location));

                DiagnosticsUpdated?.Invoke(this, DiagnosticsUpdatedArgs.DiagnosticsCreated(
                    this, _workspace, _workspace.CurrentSolution,
                    GetProjectId(), GetDocumentId(),
                    ImmutableArray.Create(_diagnostic)));
            }
开发者ID:otawfik-ms,项目名称:roslyn,代码行数:12,代码来源:DiagnosticsSquiggleTaggerProviderTests.cs


示例14: TryCreate

        public static bool TryCreate(DiagnosticDescriptor descriptor, string[] messageArguments, ProjectId projectId, Workspace workspace, out DiagnosticData diagnosticData, CancellationToken cancellationToken = default(CancellationToken))
        {
            diagnosticData = null;
            var project = workspace.CurrentSolution.GetProject(projectId);
            if (project == null)
            {
                return false;
            }

            var diagnostic = Diagnostic.Create(descriptor, Location.None, messageArguments);
            if (project.SupportsCompilation)
            {
                // Get diagnostic with effective severity.
                // Additionally, if the diagnostic was suppressed by a source suppression, effectiveDiagnostics will have a diagnostic with IsSuppressed = true.
                var compilation = project.GetCompilationAsync(cancellationToken).WaitAndGetResult(cancellationToken);
                var effectiveDiagnostics = CompilationWithAnalyzers.GetEffectiveDiagnostics(SpecializedCollections.SingletonEnumerable(diagnostic), compilation);
                if (effectiveDiagnostics == null || effectiveDiagnostics.IsEmpty())
                {
                    // Rule is disabled by compilation options.
                    return false;
                }

                diagnostic = effectiveDiagnostics.Single();
            }

            diagnosticData = diagnostic.ToDiagnosticData(project);
            return true;
        }
开发者ID:TyOverby,项目名称:roslyn,代码行数:28,代码来源:DiagnosticData.cs


示例15: IsSynthesizedNonRoslynDiagnostic

 public bool IsSynthesizedNonRoslynDiagnostic(DiagnosticData diagnostic)
 {
     var tags = diagnostic.CustomTags;
     return tags != null && tags.Contains(SynthesizedFxCopDiagnostic);
 }
开发者ID:nemec,项目名称:roslyn,代码行数:5,代码来源:VisualStudioDiagnosticListSuppressionStateService.cs


示例16: CreateDiagnostic

        private DiagnosticData CreateDiagnostic(ProjectId projectId, AnalyzerDependencyConflict conflict)
        {
            string message = string.Format(
                ServicesVSResources.WRN_AnalyzerDependencyConflictMessage,
                conflict.AnalyzerFilePath1,
                conflict.AnalyzerFilePath2,
                conflict.Identity.ToString());

            DiagnosticData data = new DiagnosticData(
                IDEDiagnosticIds.AnalyzerDependencyConflictId,
                FeaturesResources.ErrorCategory,
                message,
                ServicesVSResources.WRN_AnalyzerDependencyConflictMessage,
                severity: DiagnosticSeverity.Warning,
                defaultSeverity: DiagnosticSeverity.Warning,
                isEnabledByDefault: true,
                warningLevel: 0,
                customTags: ImmutableArray<string>.Empty,
                properties: ImmutableDictionary<string, string>.Empty,
                workspace: _workspace,
                projectId: projectId,
                title: ServicesVSResources.WRN_AnalyzerDependencyConflictTitle);

            return data;
        }
开发者ID:stephenbreen,项目名称:roslyn,代码行数:25,代码来源:AnalyzerDependencyCheckingService.cs


示例17: DiagnosticTaskItem

 public DiagnosticTaskItem(DiagnosticData diagnostic)
 {
     _diagnostic = diagnostic;
 }
开发者ID:GloryChou,项目名称:roslyn,代码行数:4,代码来源:DiagnosticTaskItem.cs


示例18: VerifyTextSpanAsync

        private static async Task VerifyTextSpanAsync(string code, int startLine, int startColumn, int endLine, int endColumn, TextSpan span)
        {
            using (var workspace = new TestWorkspace(TestExportProvider.ExportProviderWithCSharpAndVisualBasic))
            {
                var document = workspace.CurrentSolution.AddProject("TestProject", "TestProject", LanguageNames.CSharp).AddDocument("TestDocument", code);

                var data = new DiagnosticData(
                    "test1", "Test", "test1 message", "test1 message format",
                    DiagnosticSeverity.Info, false, 1,
                    workspace, document.Project.Id, new DiagnosticDataLocation(document.Id,
                        null, "originalFile1", startLine, startColumn, endLine, endColumn));

                var text = await document.GetTextAsync();
                var actual = data.GetExistingOrCalculatedTextSpan(text);

                Assert.Equal(span, actual);
            }
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:18,代码来源:DiagnosticDataTests.cs


示例19: IsEntryWithConfigurableSuppressionState

 /// <summary>
 /// Returns true if an entry's suppression state can be modified.
 /// </summary>
 /// <returns></returns>
 private static bool IsEntryWithConfigurableSuppressionState(DiagnosticData entry)
 {
     // Compiler diagnostics with severity 'Error' are not configurable.
     // Additionally, diagnostics coming from build are from a snapshot (as opposed to live diagnostics) and cannot be configured.
     return entry != null &&
         !SuppressionHelpers.IsNotConfigurableDiagnostic(entry) &&
         !entry.IsBuildDiagnostic();
 }
开发者ID:jkotas,项目名称:roslyn,代码行数:12,代码来源:VisualStudioDiagnosticListSuppressionStateService.cs


示例20: TestDiagnosticUpdateSource

 public TestDiagnosticUpdateSource(bool support, DiagnosticData[] diagnosticData)
 {
     _support = support;
     _diagnosticData = (diagnosticData ?? Array.Empty<DiagnosticData>()).ToImmutableArray();
 }
开发者ID:uwe-baumann,项目名称:roslyn,代码行数:5,代码来源:DiagnosticServiceTests.cs



注:本文中的Microsoft.CodeAnalysis.Diagnostics.DiagnosticData类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# EngineV1.DiagnosticAnalyzerDriver类代码示例发布时间:2022-05-26
下一篇:
C# Diagnostics.DiagnosticAnalyzer类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap