ValidatePath

Description

[ShutdownSurvive]
sealed class Tinman.Core.Validating.ValidatePath

Represents a logical path into a data model with a well-defined string representation, for example:

Object.Member[123].Tags['Name']

A data model path is built from the concatenation of zero or more elements:

Public / Constants

Empty


public static readonly attribute Empty → (ValidatePath)

The empty validation path, i.e. the path with zero elements.

Public / Constructors

Build


public static method Build → ()

returns → ValidatePathBuilder

The path builder.

Creates a new instance of ValidatePath.

For


public static method For → (1)

context in : object

The context object. If null, the method will return Empty.

returns → ValidatePath

The validation path.

Creates a new instance of ValidatePath with a single path element of type ValidatePathElement.Context.

Public / Methods

Context


[Constant] [Pure]
public method Context → (2)

index opt : int32 = 0

The path element index. Will be wrapped with Wrap.

inherit opt : bool = true

Inherit context objects from preceding path elements?

returns → object

The object or null if the path element has a mismatching type or if index opt is out of range.

Returns the context object for the index opt-th ValidatePathElement.Context path element, which may have been defined by a preceding path element.

Context​As


[Constant] [Pure]
public method ContextAs → ()<T ref>

returns → T

The context object or null if not found.

Returns the first context object of the given type, starting at the last path element.

Index


[Constant] [Pure]
public method Index → (1)

index opt : int32 = 0

The path element index. Will be wrapped with Wrap.

returns → int32

The index or 0 if the path element has a mismatching type or if index opt is out of range.

Returns the index of the index opt-th ValidatePathElement.Index path element.

Name


[Constant] [Pure]
public method Name → (1)

index opt : int32 = 0

The path element index. Will be wrapped with Wrap.

returns → string

The name or null if the path element has a mismatching type or if index opt is out of range.

Returns the name of the index opt-th ValidatePathElement.Member or ValidatePathElement.Entry path element.

Rebuild


public method Rebuild → ()

returns → ValidatePathBuilder

The path builder.

Creates a new instance of ValidatePathBuilder that initially contains the elements of this validation path.

To​String

2 overloads


public method ToString2 → (1)

sb in : StringBuilder

[not-null]
The string builder to use.

Formats this validation path as a string.

The string representation of a non-empty validation path (see IsEmpty) might still be the empty string, because path elements of type ValidatePathElement.Context are not included in the string representation.

Type


[Constant] [Pure]
public method Type → (1)

index opt : int32 = 0

The path element index. Will be wrapped with Wrap.

returns → ValidatePathElement

The path element type or ValidatePathElement.None if index opt is out of range.

Returns the type of the index opt-th path element.

Wrap


[Constant] [Pure]
public method Wrap → (1)

index in : int32

The index to wrap. If negative, the value of Length will be added. Then, the value will be clamped to [0..Length-1].

returns → int32

The wrapped index. Will be -1 iff Length is zero.

Wraps the given validation path element index.

Public / Attributes

Has​Parts


public attribute HasParts → (get)

value : bool

true if this path has at least one non-context element,
false if it is empty or has only context elements.

Does this path have any elements other than ValidatePathElement.Context?

Is​Empty


public attribute IsEmpty → (get)

value : bool

true if this is the empty path,
false if not.

Is this the empty validation path?

Length


public attribute Length → (get)

value : int32

[>=0]
The length, in path elements (see ValidatePathElement).

Returns the length of this path.