当前位置: 首页>>代码示例>>C#>>正文


C# Diagnostic.GetMessage方法代码示例

本文整理汇总了C#中Diagnostic.GetMessage方法的典型用法代码示例。如果您正苦于以下问题:C# Diagnostic.GetMessage方法的具体用法?C# Diagnostic.GetMessage怎么用?C# Diagnostic.GetMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Diagnostic的用法示例。


在下文中一共展示了Diagnostic.GetMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Format

        /// <summary>
        /// Formats the <see cref="Diagnostic"/> message using the optional <see cref="IFormatProvider"/>.
        /// </summary>
        /// <param name="diagnostic">The diagnostic.</param>
        /// <param name="formatter">The formatter; or null to use the default formatter.</param>
        /// <returns>The formatted message.</returns>
        public virtual string Format(Diagnostic diagnostic, IFormatProvider formatter = null)
        {
            if (diagnostic == null)
            {
                throw new ArgumentNullException("diagnostic");
            }

            var culture = formatter as CultureInfo;

            switch (diagnostic.Location.Kind)
            {
                case LocationKind.SourceFile:
                case LocationKind.XmlFile:
                    var span = diagnostic.Location.GetLineSpan();
                    var mappedSpan = diagnostic.Location.GetMappedLineSpan();
                    if (!span.IsValid || !mappedSpan.IsValid)
                    {
                        goto default;
                    }

                    string path, basePath;
                    if (mappedSpan.HasMappedPath)
                    {
                        path = mappedSpan.Path;
                        basePath = span.Path;
                    }
                    else
                    {
                        path = span.Path;
                        basePath = null;
                    }

                    return string.Format(formatter, "{0}{1}: {2}: {3}",
                                         FormatSourcePath(path, basePath, formatter),
                                         FormatSourceSpan(mappedSpan.Span, formatter),
                                         GetMessagePrefix(diagnostic, culture),
                                         diagnostic.GetMessage(culture));

                case LocationKind.MetadataFile:
                    return string.Format(formatter, "{0}: {1}: {2}",
                                         diagnostic.Location.MetadataModule.Name,
                                         GetMessagePrefix(diagnostic, culture),
                                         diagnostic.GetMessage(culture));

                default:
                    return string.Format(formatter, "{0}: {1}",
                                         GetMessagePrefix(diagnostic, culture),
                                         diagnostic.GetMessage(culture));
            }
        }
开发者ID:riversky,项目名称:roslyn,代码行数:56,代码来源:DiagnosticFormatter.cs

示例2: LogDiagnostic

        public void LogDiagnostic(Diagnostic diagnostic)
        {
            _writer.WriteObjectStart(); // result
            _writer.Write("ruleId", diagnostic.Id);

            string ruleKey = _descriptors.Add(diagnostic.Descriptor);
            if (ruleKey != diagnostic.Id)
            {
                _writer.Write("ruleKey", ruleKey);
            }

            _writer.Write("level", GetLevel(diagnostic.Severity));

            string message = diagnostic.GetMessage(_culture);
            if (!string.IsNullOrEmpty(message))
            {
                _writer.Write("message", message);
            }

            if (diagnostic.IsSuppressed)
            {
                _writer.WriteArrayStart("suppressionStates");
                _writer.Write("suppressedInSource");
                _writer.WriteArrayEnd();
            }

            WriteLocations(diagnostic.Location, diagnostic.AdditionalLocations);
            WriteProperties(diagnostic);

            _writer.WriteObjectEnd(); // result
        }
开发者ID:rgani,项目名称:roslyn,代码行数:31,代码来源:ErrorLogger.cs

示例3: LogDiagnostic

        internal void LogDiagnostic(Diagnostic diagnostic, CultureInfo culture)
        {
            _writer.WriteObjectStart(); // result
            _writer.Write("ruleId", diagnostic.Id);
            _writer.Write("kind", GetKind(diagnostic.Severity));

            WriteLocations(diagnostic.Location, diagnostic.AdditionalLocations);

            string message = diagnostic.GetMessage(culture);
            if (string.IsNullOrEmpty(message))
            {
                message = "<None>";
            }

            string description = diagnostic.Descriptor.Description.ToString(culture);
            if (string.IsNullOrEmpty(description))
            {
                _writer.Write("fullMessage", message);
            }
            else
            {
                _writer.Write("shortMessage", message);
                _writer.Write("fullMessage", description);
            }

            _writer.Write("isSuppressedInSource", diagnostic.IsSuppressed);

            WriteTags(diagnostic);

            WriteProperties(diagnostic, culture);

            _writer.WriteObjectEnd(); // result
        }
开发者ID:vmussak,项目名称:roslyn,代码行数:33,代码来源:ErrorLogger.cs

示例4: DiagnosticResult

		public DiagnosticResult (Diagnostic diagnostic) : base (GetSpan (diagnostic), diagnostic.GetMessage ())
		{
			if (diagnostic == null)
				throw new ArgumentNullException ("diagnostic");
			this.diagnostic = diagnostic;

			SetSeverity (diagnostic.Severity, GetIssueMarker ()); 
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:8,代码来源:DiagnosticResult.cs

示例5: ProcessingResultDiagnostic

        public ProcessingResultDiagnostic(Diagnostic diagnostic)
        {
            Id = diagnostic.Id;
            Severity = diagnostic.Severity;
            Message = diagnostic.GetMessage();

            var lineSpan = diagnostic.Location.GetMappedLineSpan();
            Start = new ProcessingResultDiagnosticLocation(lineSpan.StartLinePosition);
            End = new ProcessingResultDiagnosticLocation(lineSpan.EndLinePosition);
        }
开发者ID:i3arnon,项目名称:TryRoslyn,代码行数:10,代码来源:ProcessingResultDiagnostic.cs

示例6: Format

        public static string Format(Diagnostic diagnostic, FrameworkName targetFramework, IFormatProvider formatter = null)
        {
            if (diagnostic == null)
            {
                throw new ArgumentNullException(nameof(diagnostic));
            }

            var culture = formatter as CultureInfo;

            switch (diagnostic.Location.Kind)
            {
                case LocationKind.SourceFile:
                case LocationKind.XmlFile:
                case LocationKind.ExternalFile:
                    var span = diagnostic.Location.GetLineSpan();
                    var mappedSpan = diagnostic.Location.GetMappedLineSpan();
                    if (!span.IsValid || !mappedSpan.IsValid)
                    {
                        goto default;
                    }

                    string path, basePath;
                    if (mappedSpan.HasMappedPath)
                    {
                        path = mappedSpan.Path;
                        basePath = span.Path;
                    }
                    else
                    {
                        path = span.Path;
                        basePath = null;
                    }

                    var start = mappedSpan.Span.Start;
                    var framework = targetFramework == null ? string.Empty : $" {targetFramework.FullName}";
                    return $"{path}({start.Line + 1},{start.Character + 1}):{framework} {GetMessagePrefix(diagnostic)}: {diagnostic.GetMessage(culture)}";
                default:
                    return $"{GetMessagePrefix(diagnostic)}: {diagnostic.GetMessage(culture)}";
            }
        }
开发者ID:leloulight,项目名称:dnx,代码行数:40,代码来源:RoslynDiagnosticFormatter.cs

示例7: Format

        public override string Format(Diagnostic diagnostic, IFormatProvider formatter = null)
        {
            if (diagnostic == null)
            {
                throw new ArgumentNullException(nameof(diagnostic));
            }

            var culture = formatter as CultureInfo;

            return string.Format(formatter, "{0}: {1}",
                                         GetMessagePrefix(diagnostic),
                                         diagnostic.GetMessage(culture));
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:13,代码来源:DebuggerDiagnosticFormatter.cs

示例8: MakeQuickFix

        private static QuickFix MakeQuickFix(Diagnostic diagnostic)
        {
            var span = diagnostic.Location.GetMappedLineSpan();
            var quickFix = new QuickFix();
            quickFix.FileName = span.Path;
            quickFix.Line = span.StartLinePosition.Line + 1;
            quickFix.Column = span.StartLinePosition.Character + 1;
            quickFix.EndLine = span.EndLinePosition.Line + 1;
            quickFix.EndColumn = span.EndLinePosition.Character + 1;
            quickFix.Text = diagnostic.GetMessage();
            quickFix.LogLevel = diagnostic.Severity.ToString();

            return quickFix;
        }
开发者ID:Jenkin0603,项目名称:myvim,代码行数:14,代码来源:OmnisharpController.Diagnostics.cs

示例9: MakeQuickFix

 private static QuickFix MakeQuickFix(Diagnostic diagnostic)
 {
     var span = diagnostic.Location.GetMappedLineSpan();
     return new DiagnosticLocation
     {
         FileName = span.Path,
         Line = span.StartLinePosition.Line + 1,
         Column = span.StartLinePosition.Character + 1,
         EndLine = span.EndLinePosition.Line + 1,
         EndColumn = span.EndLinePosition.Character + 1,
         Text = diagnostic.GetMessage(),
         LogLevel = diagnostic.Severity.ToString()
     };
 }
开发者ID:tugberkugurlu,项目名称:omnisharp-roslyn,代码行数:14,代码来源:OmnisharpController.Diagnostics.cs

示例10: LogDiagnostic

        internal static void LogDiagnostic(Diagnostic diagnostic, CultureInfo culture, ErrorLogger errorLogger)
        {
            if (errorLogger != null)
            {
#pragma warning disable RS0013 // We need to invoke Diagnostic.Descriptor here to log all the metadata properties of the diagnostic.
                var issue = new Issue(diagnostic.Id, diagnostic.GetMessage(culture),
                    diagnostic.Descriptor.Description.ToString(culture), diagnostic.Descriptor.Title.ToString(culture),
                    diagnostic.Category, diagnostic.Descriptor.HelpLinkUri, diagnostic.IsEnabledByDefault, diagnostic.IsSuppressed,
                    diagnostic.DefaultSeverity, diagnostic.Severity, diagnostic.WarningLevel, diagnostic.Location,
                    diagnostic.AdditionalLocations, diagnostic.CustomTags, diagnostic.Properties);
#pragma warning restore RS0013

                errorLogger.LogIssue(issue);
            }
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:15,代码来源:ErrorLogger.cs

示例11: PreviewPane

        object IPreviewPaneService.GetPreviewPane(Diagnostic diagnostic, object previewContent)
        {
            var telemetry = diagnostic == null ? false : diagnostic.Descriptor.CustomTags.Contains(WellKnownDiagnosticTags.Telemetry);

            if ((diagnostic == null) || (diagnostic.Descriptor is TriggerDiagnosticDescriptor))
            {
                return new PreviewPane(
                    null, null, null, null, null, null, telemetry, previewContent, _serviceProvider);
            }
            else
            {
                return new PreviewPane(
                    GetSeverityIconForDiagnostic(diagnostic),
                    diagnostic.Id, diagnostic.GetMessage(),
                    diagnostic.Descriptor.MessageFormat.ToString(DiagnosticData.USCultureInfo),
                    diagnostic.Descriptor.Description.ToString(CultureInfo.CurrentUICulture),
                    diagnostic.Descriptor.HelpLinkUri, telemetry, previewContent, _serviceProvider);
            }
        }
开发者ID:JinGuoGe,项目名称:roslyn,代码行数:19,代码来源:PreviewPaneService.cs

示例12: GetHelpLink

        private static Uri GetHelpLink(Diagnostic diagnostic, out string helpLinkToolTipText)
        {
            var isBing = false;
            helpLinkToolTipText = string.Empty;

            Uri helpLink;
            if (!BrowserHelper.TryGetUri(diagnostic.Descriptor.HelpLinkUri, out helpLink))
            {
                // We use the ENU version of the message for bing search.
                helpLink = BrowserHelper.CreateBingQueryUri(diagnostic.Id, diagnostic.GetMessage(DiagnosticData.USCultureInfo));
                isBing = true;
            }

            if (helpLink != null)
            {
                helpLinkToolTipText =
                    string.Format(ServicesVSResources.DiagnosticIdHyperlinkTooltipText, diagnostic.Id,
                        isBing ? ServicesVSResources.FromBing : null, Environment.NewLine, helpLink);
            }

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

示例13: GetHelpLink

        private static Uri GetHelpLink(Diagnostic diagnostic, string language, string projectType, out string helpLinkToolTipText)
        {
            var isBing = false;
            helpLinkToolTipText = string.Empty;

            Uri helpLink;
            if (!BrowserHelper.TryGetUri(diagnostic.Descriptor.HelpLinkUri, out helpLink))
            {
                // We use the ENU version of the message for bing search.
                helpLink = BrowserHelper.CreateBingQueryUri(diagnostic.Id, diagnostic.GetMessage(DiagnosticData.USCultureInfo), 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.DiagnosticIdHyperlinkTooltipText, diagnostic.Id,
                        isBing ? ServicesVSResources.FromBing : null, Environment.NewLine, helpLink);
            }

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

示例14: IsDiagnosticSuppressed

        public bool IsDiagnosticSuppressed(Diagnostic diagnostic, ISymbol symbolOpt = null)
        {
            // Suppress duplicate analyzer exception diagnostics from the analyzer driver.
            if (diagnostic.CustomTags.Contains(WellKnownDiagnosticTags.AnalyzerException))
            {
                if (_faultedAnalyzerMessages == null)
                {
                    Interlocked.CompareExchange(ref _faultedAnalyzerMessages, new ConcurrentSet<string>(), null);
                }

                var message = diagnostic.GetMessage();
                if (!_faultedAnalyzerMessages.Add(message))
                {
                    return true;
                }
            }

            if (symbolOpt != null && IsDiagnosticSuppressed(diagnostic.Id, symbolOpt))
            {
                return true;
            }

            return IsDiagnosticSuppressed(diagnostic.Id, diagnostic.Location);
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:24,代码来源:SuppressMessageAttributeState.cs

示例15: Create

        public static DiagnosticData Create(Document document, Diagnostic diagnostic)
        {
            var location = CreateLocation(document, diagnostic.Location);

            var additionalLocations = diagnostic.AdditionalLocations.Count == 0
                ? (IReadOnlyCollection<DiagnosticDataLocation>)SpecializedCollections.EmptyArray<DiagnosticDataLocation>()
                : diagnostic.AdditionalLocations.Where(loc => loc.IsInSource)
                                                .Select(loc => CreateLocation(document.Project.GetDocument(loc.SourceTree), loc))
                                                .WhereNotNull()
                                                .ToReadOnlyCollection();

            return new DiagnosticData(
                diagnostic.Id,
                diagnostic.Descriptor.Category,
                diagnostic.GetMessage(CultureInfo.CurrentUICulture),
                diagnostic.GetBingHelpMessage(),
                diagnostic.Severity,
                diagnostic.DefaultSeverity,
                diagnostic.Descriptor.IsEnabledByDefault,
                diagnostic.WarningLevel,
                diagnostic.Descriptor.CustomTags.AsImmutableOrEmpty(),
                diagnostic.Properties,
                document.Project.Solution.Workspace,
                document.Project.Id,
                location,
                additionalLocations,
                title: diagnostic.Descriptor.Title.ToString(CultureInfo.CurrentUICulture),
                description: diagnostic.Descriptor.Description.ToString(CultureInfo.CurrentUICulture),
                helpLink: diagnostic.Descriptor.HelpLinkUri,
                isSuppressed: diagnostic.IsSuppressed);
        }
开发者ID:robertoenbarcelona,项目名称:roslyn,代码行数:31,代码来源:DiagnosticData.cs


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