ValidateMessage

Description

sealed class Tinman.Core.Validating.ValidateMessage

Represents a validation message.

A validation message is created from a localized message text and a message type, using the constructor of this class directly or indirectly via some factory method. After creation, a ValidateMessage object can be augmented with additional context information, usually for error reporting:

Validation messages have a well-defined string representation which is intended for human consumption but also provides a trivial structure for parsing. Here is a made-up example for CxInspection.CX01001:

## /path/to/the/File.cs
>> Category / Error
@: CodeUnits['File'].Declaration
1234: #region Native {0D12D3E3-8D90-4264-B264-73C00431DE47}
  ___/"""""""""""""""""""""""""""""""""""""""""""""""""""""\
  [CX01001] missing native code: CPP

The string representation can be interpreted line-by-line as follows (assuming ValidateMessageFormat.All):

  1. ValidateMessageFormat.File:
    If the line starts with "##", the trimmed remainder contains the value of FilePath.

  2. ValidateMessageFormat.Type:
    If the line starts with ">>", the trimmed remainder contains the values of Category and Type, separated by " / ". If the former is null or empty, only the latter is used without a separator.

  3. ValidateMessageFormat.Path:
    If the line starts with "@:", the trimmed remainder contains the value of DataPath.

  4. ValidateMessageFormat.Input:
    If the line starts with a digit ('0'..'9'), the part up to the colon (':') gives the one-base row number in the input (see Input) and the trimmed remainder contains the trimmed input text line. The subsequent lines are indented with two whitespaces. The first subsequent line uses ASCII art to mark the input range (see InputRange).

  5. ValidateMessageFormat.Text
    The second subsequent line (see 4) and following contain the value of Text, indented with two whitespaces, unless there are no other format flags: then the message text will then output without indenting.

  6. Empty lines (i.e. with a length of zero) have no meaning and can be ignored safely. They are included in the string representation as visual separators where the value of a part (1 to 3) changes.

Public / Constructors

Custom


[Pure]
public static method Custom → (3)

message in : string

[not-null]
The message text.

type opt : ValidateMessageType = ValidateMessageType.Error

The message type.

category opt : string = null

The message category

returns → ValidateMessage

The message object.

Creates a new custom validation message.

Directory​Not​Found


[Pure]
public static method DirectoryNotFound → (2)

path in : Path

The path.

type opt : ValidateMessageType = ValidateMessageType.Warning

The message type.

returns → ValidateMessage

The message object.

The path does not point to an existing file.

File​Not​Found


[Pure]
public static method FileNotFound → (2)

path in : Path

The path.

type opt : ValidateMessageType = ValidateMessageType.Warning

The message type.

returns → ValidateMessage

The message object.

The path does not point to an existing file.

Invalid​Value


[Pure]
public static method InvalidValue → ()

returns → ValidateMessage

The message object.

The element being validated has an invalid value.

Missing​Value


[Pure]
public static method MissingValue → ()

returns → ValidateMessage

The message object.

The element being validated does not have a value.

Path​Not​Found


[Pure]
public static method PathNotFound → (2)

path in : Path

The path.

type opt : ValidateMessageType = ValidateMessageType.Warning

The message type.

returns → ValidateMessage

The message object.

The path does not point to an existing file or directory.

Public / Methods

Log


public method Log → (2)

logger in : ILogger

[not-null]
The logger to use for outputting this message.

format opt : ValidateMessageFormat = ValidateMessageFormat.All ^ ValidateMessageFormat.Type

The message format to use.

Outputs this message to the given logger in.

Throw


public method Throw → (2)

source in : string @ Tag

The error source tag.

input opt : ICodeInput = null

The source code input to set to Input before wrapping or null to use the current value.

returns → ValidatingException

The ready-to-throw exception.

Wraps this message in an exception.

To​String

3 overloads


public method ToString2 → (2)

format in : ValidateMessageFormat

The message format to use.

previous opt : ValidateMessage = null

The message that has been output before this one. Set to null if not known. This information is used to remove redundant information from the string representation.

returns → string

The string representation.

Returns the string representation of this message.


public method ToString3 → (3)

sb in : StringBuilder

[not-null]
The string representation output.

format opt : ValidateMessageFormat = ValidateMessageFormat.All

The message format to use.

previous opt : ValidateMessage = null

The message that has been output before this one. Set to null if not known. This information is used to remove redundant information from the string representation.

Returns the string representation of this message.

With​Input

2 overloads


[Pure]
public method WithInput1 → (1)

range in : ICodeRange

The source code input range or null.

returns → ValidateMessage

The resulting ValidateMessage, which may be this.

Uses the given range in for InputRange.


[Pure]
public method WithInput2 → (1)

range in : RangeI

The source code input range.

returns → ValidateMessage

The resulting ValidateMessage, which may be this.

Uses the given range in for InputRange.

With​Path


[Pure]
public method WithPath → (1)

path in : ValidatePath

The logical data model path or null.

returns → ValidateMessage

The resulting ValidateMessage, which may be this.

Uses the given path in for DataPath.

Public / Attributes

Category


[Constant]
public attribute Category → (get)

value : string

The message category. Will either be null or non-empty.

The message category.

Data​Path


[Constant]
public attribute DataPath → (get)

value : ValidatePath

[not-null]
The logical data model path or ValidatePath.Empty if no path is available.

The logical data model path that leads to the error source.

Defaults to ValidatePath.Empty.

File​Path


[Constant]
public attribute FilePath → (get)

value : Path

[not-null]
The file path or Path.Unknown if none.

Returns the file path associated with this message.

The file path is found as follows:

  1. If Input returns a non-null value, use its IPathInfo.PathInfo value, if it is not unknown.

  2. If ValidatePath.ContextAs for IPathInfo on DataPath returns a non-null value, use its IPathInfo.PathInfo value, if it is not unknown.

  3. If ValidatePath.ContextAs for Path on DataPath returns a non-null value, use it.

  4. Otherwise, use Path.Unknown.

Input


[Constant]
public attribute Input → (get)

value : ICodeInput

The source code input or null if none.

Returns the source code input associated with this message.

The source code input is found as follows: as follows:

  1. If ValidatePath.ContextAs for ICodeInput on DataPath returns a non-null value, use its ICodeInput.Original value.

  2. Otherwise, use null.

Input​Range


[Constant]
public attribute InputRange → (get)

value : RangeI

The source code input range in Input or RangeI.Inv if none.

Returns the source code input range associated with this message.

The default value is RangeI.Inv, in which case the value is found as follows:

  1. If ValidatePath.ContextAs for ICodeRange on DataPath is not null, use its ICodeRange.Range value, if not undefined.

  2. Otherwise, return RangeI.Inv.

Message


[Constant]
public attribute Message → (get)

value : string

[not-null]
The error message.

Message that describes this error.

Type


[Constant]
public attribute Type → (get)

value : ValidateMessageType

The message type.

The message type.