LotSizingDataModel.Instance 2.0.1
Lot-sizing instance representation, descriptors and problem characterization.
Loading...
Searching...
No Matches
InstanceDiagnostic.cs
Go to the documentation of this file.
1using System.Collections.ObjectModel;
2
4
5/// <summary>
6/// Represents one structured diagnostic produced while checking
7/// the semantic validity of a lot-sizing instance.
8/// </summary>
9public sealed class InstanceDiagnostic
10{
11 private readonly IReadOnlyDictionary<string, string> _values;
12
13 /// <summary>
14 /// Initializes a structured instance diagnostic.
15 /// </summary>
17 string code,
19 string path,
20 string message,
21 string? relatedPath = null,
22 IReadOnlyDictionary<string, string>? values = null,
23 string? suggestedAction = null)
24 {
25 if (string.IsNullOrWhiteSpace(code))
26 {
27 throw new ArgumentException(
28 "A diagnostic code is required.",
29 nameof(code));
30 }
31
32 ArgumentNullException.ThrowIfNull(path);
33 ArgumentNullException.ThrowIfNull(message);
34
35 Code = code.Trim();
36 Severity = severity;
37 Path = path;
38 Message = message;
39 RelatedPath = relatedPath;
40 SuggestedAction = suggestedAction;
41
42 Dictionary<string, string> copy =
43 values is null
44 ? new Dictionary<string, string>(
45 StringComparer.Ordinal)
46 : new Dictionary<string, string>(
47 values,
48 StringComparer.Ordinal);
49
50 _values =
51 new ReadOnlyDictionary<string, string>(copy);
52 }
53
54 /// <summary>
55 /// Gets the stable technical code identifying the rule.
56 /// </summary>
57 public string Code { get; }
58
59 /// <summary>
60 /// Gets the diagnostic severity.
61 /// </summary>
63
64 /// <summary>
65 /// Gets the logical path of the primary model element.
66 /// </summary>
67 public string Path { get; }
68
69 /// <summary>
70 /// Gets the human-readable diagnostic message.
71 /// </summary>
72 public string Message { get; }
73
74 /// <summary>
75 /// Gets an optional related logical path.
76 /// </summary>
77 public string? RelatedPath { get; }
78
79 /// <summary>
80 /// Gets stable contextual values associated with the rule.
81 /// </summary>
82 public IReadOnlyDictionary<string, string> Values => _values;
83
84 /// <summary>
85 /// Gets an optional action suggested to the caller or UI.
86 /// </summary>
87 public string? SuggestedAction { get; }
88
89 /// <summary>
90 /// Gets a value indicating whether this diagnostic blocks
91 /// the instance from being treated as semantically valid.
92 /// </summary>
93 public bool IsBlocking =>
94 Severity is
97
98 /// <inheritdoc/>
99 public override string ToString()
100 {
101 return $"[{Severity}] {Code} at {Path}: {Message}";
102 }
103}
bool IsBlocking
Gets a value indicating whether this diagnostic blocks the instance from being treated as semanticall...
string Code
Gets the stable technical code identifying the rule.
IReadOnlyDictionary< string, string > Values
Gets stable contextual values associated with the rule.
string Path
Gets the logical path of the primary model element.
InstanceDiagnostic(string code, InstanceDiagnosticSeverity severity, string path, string message, string? relatedPath=null, IReadOnlyDictionary< string, string >? values=null, string? suggestedAction=null)
Initializes a structured instance diagnostic.
string? SuggestedAction
Gets an optional action suggested to the caller or UI.
string? RelatedPath
Gets an optional related logical path.
string Message
Gets the human-readable diagnostic message.
InstanceDiagnosticSeverity Severity
Gets the diagnostic severity.
InstanceDiagnosticSeverity
Indicates the severity of one semantic instance diagnostic.
@ Error
Blocking issue that prevents the instance from being considered semantically valid.