示例#1
0
 public CompilerDiagnostic(int?line, int?column, DiagnosticSeverity severity, string message)
 {
     Line         = line;
     Column       = column;
     Severity     = severity;
     SeverityText = severity.ToString();
     MessageText  = message;
 }
        private Diagnostic BuildDiagnostic(DiagnosticSeverity severity = DiagnosticSeverity.Warning)
        {
            var upperSeverity = severity.ToString().ToUpper();
            var lowerSeverity = severity.ToString().ToLower();

            var id      = $"AUTO-{upperSeverity}001";
            var message = $"This is {lowerSeverity}.";

            var diagnosticDescriptor = new DiagnosticDescriptor(
                id,
                AttributeName,
                message,
                Namespace,
                severity,
                true);

            return(Diagnostic.Create(diagnosticDescriptor, Location.None));
        }
示例#3
0
        /// <summary>
        /// 创建诊断描述器
        /// </summary>
        /// <param name="id"></param>
        /// <param name="title"></param>
        /// <param name="message"></param>
        /// <param name="helpLinkUri"></param>
        /// <returns></returns>
        private static DiagnosticDescriptor Create(string id, string title, string message, DiagnosticSeverity level = DiagnosticSeverity.Error, string helpLinkUri = null)
        {
            var category = level.ToString();

            if (string.IsNullOrEmpty(helpLinkUri) == true)
            {
                helpLinkUri = Resx.helpLinkUri;
            }
            return(new DiagnosticDescriptor(id, title, message, category, level, true, helpLinkUri: helpLinkUri));
        }
示例#4
0
        /// <summary>
        /// 创建诊断描述器
        /// </summary>
        /// <param name="id"></param>
        /// <param name="title"></param>
        /// <param name="message"></param>
        /// <param name="helpLinkUri"></param>
        /// <returns></returns>
        private static DiagnosticDescriptor Create(string id, string title, string message, DiagnosticSeverity level = DiagnosticSeverity.Error, string helpLinkUri = null)
        {
            var category = level.ToString();

            if (string.IsNullOrEmpty(helpLinkUri) == true)
            {
                helpLinkUri = "https://github.com/dotnetcore/WebApiClient/wiki/WebApiClient%E5%9F%BA%E7%A1%80";
            }
            return(new DiagnosticDescriptor(id, title, message, category, level, true, helpLinkUri: helpLinkUri));
        }
示例#5
0
 private static string CreateStub(
     string id,
     string title,
     DiagnosticSeverity severity,
     string codeFileUrl,
     string category,
     string typeName,
     string description)
 {
     return(Properties.Resources.DiagnosticDocTemplate.Replace("{ID}", id)
            .Replace("## ADD TITLE HERE", $"## {title}")
            .Replace("{SEVERITY}", severity.ToString())
            .Replace("{CATEGORY}", category)
            .Replace("{URL}", codeFileUrl ?? "https://github.com/DotNetAnalyzers/WpfAnalyzers")
            .Replace("{TYPENAME}", typeName)
            .Replace("ADD DESCRIPTION HERE", description ?? "ADD DESCRIPTION HERE")
            .Replace("{TITLE}", title)
            .Replace("{TRIMMEDTYPENAME}", typeName.Substring(id.Length)));
 }
        public static ResultLevel ConvertToResultLevel(this DiagnosticSeverity severity)
        {
            switch (severity)
            {
            case DiagnosticSeverity.Error:
            {
                return(ResultLevel.Error);
            }

            case DiagnosticSeverity.Hidden:
            case DiagnosticSeverity.Warning:
            {
                return(ResultLevel.Warning);
            }

            case DiagnosticSeverity.Info:
            {
                return(ResultLevel.Note);
            }

            default:
            {
                throw new InvalidOperationException("Unrecognized diagnostic severity value: " + severity.ToString());
            }
            }
        }
        string GetDisplayName(DiagnosticSeverity severity, int count)
        {
            var numerus = count > 1 ? "s" : "";

            return(severity.ToString().ToLower() + numerus);
        }
        private static DiagnosticDescriptor Create(string id, string title, string message, DiagnosticSeverity level = DiagnosticSeverity.Error, string helpLinkUri = null)
        {
            var category = level.ToString();

            return(new DiagnosticDescriptor(id, title, message, category, level, true, helpLinkUri: helpLinkUri));
        }
 string GetDisplayName(DiagnosticSeverity severity, int count) {
     var numerus = count > 1 ? "s" : "";
     return severity.ToString().ToLower() + numerus;
 }
示例#10
0
        public static MessageKind ConvertToMessageKind(this DiagnosticSeverity severity)
        {
            switch (severity)
            {
            case DiagnosticSeverity.Hidden:
            case DiagnosticSeverity.Warning:
            case DiagnosticSeverity.Error:
            {
                return(MessageKind.Fail);
            }

            case DiagnosticSeverity.Info:
            {
                return(MessageKind.Note);
            }

            default:
            {
                throw new InvalidOperationException("Unrecognized diagnostic severity value: " + severity.ToString());
            }
            }
        }