/* Copyright (C) 2014-2019 de4dot@gmail.com This file is part of dnSpy dnSpy is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. dnSpy is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with dnSpy. If not, see . */ using System.Diagnostics; using System.Text; namespace dnSpy.Contracts.AsmEditor.Compiler { /// /// Compiler diagnostic /// public sealed class CompilerDiagnostic { /// /// Gets the severity /// public CompilerDiagnosticSeverity Severity { get; } /// /// Description /// public string Description { get; } /// /// Id, eg. CS0001 /// public string Id { get; } /// /// Gets the help URI or null if none /// public string? HelpUri { get; } /// /// Filename or null /// public string? Filename { get; } /// /// Location in the file or null /// public LineLocationSpan? LineLocationSpan { get; } /// /// Constructor /// /// Severity /// Description /// Id /// Help URI or null if none /// Filename or null /// Line location or null public CompilerDiagnostic(CompilerDiagnosticSeverity severity, string description, string id, string? helpUri, string? filename, LineLocationSpan? lineLocationSpan) { Severity = severity; Description = description ?? string.Empty; Id = id ?? string.Empty; HelpUri = helpUri; Filename = filename; LineLocationSpan = lineLocationSpan; } /// /// ToString() /// /// public override string ToString() { var sb = new StringBuilder(); sb.Append(Filename ?? "???"); if (LineLocationSpan is not null) sb.Append(LineLocationSpan.Value.StartLinePosition.ToString()); sb.Append(": "); switch (Severity) { case CompilerDiagnosticSeverity.Hidden: sb.Append("hidden"); break; case CompilerDiagnosticSeverity.Info: sb.Append("info"); break; case CompilerDiagnosticSeverity.Warning:sb.Append("warning"); break; case CompilerDiagnosticSeverity.Error: sb.Append("error"); break; default: Debug.Fail($"Unknown severity {Severity}"); sb.Append("???"); break; } sb.Append(' '); sb.Append(Id); sb.Append(": "); sb.Append(Description); return sb.ToString(); } } }