Table of Contents

Class Variable<TValue, TValidationResult>

Namespace
LfrlAnvil.Reactive.State
Assembly
LfrlAnvil.Reactive.State.dll

Represents a generic variable.

public class Variable<TValue, TValidationResult> : VariableNode, IVariable<TValue, TValidationResult>, IReadOnlyVariable<TValue, TValidationResult>, IReadOnlyVariable<TValue>, IReadOnlyVariable, IMutableVariableNode, IVariableNode, IDisposable

Type Parameters

TValue

Value type.

TValidationResult

Validation result type.

Inheritance
Variable<TValue, TValidationResult>
Implements
IVariable<TValue, TValidationResult>
IReadOnlyVariable<TValue, TValidationResult>
Inherited Members
Extension Methods

Constructors

Variable(TValue, IEqualityComparer<TValue>?, IValidator<TValue, TValidationResult>?, IValidator<TValue, TValidationResult>?)

Creates a new Variable<TValue, TValidationResult> instance.

public Variable(TValue initialValue, IEqualityComparer<TValue>? comparer = null, IValidator<TValue, TValidationResult>? errorsValidator = null, IValidator<TValue, TValidationResult>? warningsValidator = null)

Parameters

initialValue TValue

Initial value.

comparer IEqualityComparer<TValue>

Value comparer.

errorsValidator IValidator<TValue, TValidationResult>

Value validator that marks result as errors.

warningsValidator IValidator<TValue, TValidationResult>

Value validator that marks result as warnings.

Variable(TValue, TValue, IEqualityComparer<TValue>?, IValidator<TValue, TValidationResult>?, IValidator<TValue, TValidationResult>?)

Creates a new Variable<TValue, TValidationResult> instance.

public Variable(TValue initialValue, TValue value, IEqualityComparer<TValue>? comparer = null, IValidator<TValue, TValidationResult>? errorsValidator = null, IValidator<TValue, TValidationResult>? warningsValidator = null)

Parameters

initialValue TValue

Initial value.

value TValue

Current value.

comparer IEqualityComparer<TValue>

Value comparer.

errorsValidator IValidator<TValue, TValidationResult>

Value validator that marks result as errors.

warningsValidator IValidator<TValue, TValidationResult>

Value validator that marks result as warnings.

Properties

Comparer

Value equality comparer.

public IEqualityComparer<TValue> Comparer { get; }

Property Value

IEqualityComparer<TValue>

Errors

Collection of current validation errors.

public Chain<TValidationResult> Errors { get; }

Property Value

Chain<TValidationResult>

ErrorsValidator

Value validator that marks result as errors.

public IValidator<TValue, TValidationResult> ErrorsValidator { get; }

Property Value

IValidator<TValue, TValidationResult>

InitialValue

Initial value.

public TValue InitialValue { get; }

Property Value

TValue

OnChange

Event stream that emits events when variable's value changes.

public override sealed IEventStream<VariableValueChangeEvent<TValue, TValidationResult>> OnChange { get; }

Property Value

IEventStream<VariableValueChangeEvent<TValue, TValidationResult>>

OnValidate

Event stream that emits events when variable's validation state changes.

public override sealed IEventStream<VariableValidationEvent<TValue, TValidationResult>> OnValidate { get; }

Property Value

IEventStream<VariableValidationEvent<TValue, TValidationResult>>

State

Specifies this node's current state.

public override sealed VariableState State { get; }

Property Value

VariableState

Value

Current value.

public TValue Value { get; }

Property Value

TValue

Warnings

Collection of current validation warnings.

public Chain<TValidationResult> Warnings { get; }

Property Value

Chain<TValidationResult>

WarningsValidator

Value validator that marks result as warnings.

public IValidator<TValue, TValidationResult> WarningsValidator { get; }

Property Value

IValidator<TValue, TValidationResult>

Methods

Change(TValue)

Changes the Value, even if the value to set is equal to the current value.

public VariableChangeResult Change(TValue value)

Parameters

value TValue

Value to set.

Returns

VariableChangeResult

Result of this change attempt.

ClearValidation()

Removes all errors and warnings from this variable.

public void ClearValidation()

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public virtual void Dispose()

GetChildren()

Returns the collection of all children nodes.

[Pure]
public override IEnumerable<IVariableNode> GetChildren()

Returns

IEnumerable<IVariableNode>

New IEnumerable<T> instance.

OnPublishChangeEvent(VariableValueChangeEvent<TValue, TValidationResult>)

Emits the provided change event.

protected virtual void OnPublishChangeEvent(VariableValueChangeEvent<TValue, TValidationResult> @event)

Parameters

event VariableValueChangeEvent<TValue, TValidationResult>

Event to publish.

OnPublishValidationEvent(VariableValidationEvent<TValue, TValidationResult>)

Emits the provided validation event.

protected virtual void OnPublishValidationEvent(VariableValidationEvent<TValue, TValidationResult> @event)

Parameters

event VariableValidationEvent<TValue, TValidationResult>

Event to publish.

Refresh()

Refreshes this variable.

public void Refresh()

RefreshValidation()

Refreshes this variable's validation.

public void RefreshValidation()

Reset(TValue, TValue)

Removes all errors and warnings from this variable and resets InitialValue and Value.

public void Reset(TValue initialValue, TValue value)

Parameters

initialValue TValue

Initial value to set.

value TValue

Value to set.

SetReadOnly(bool)

Changes the read-only state of this variable.

public void SetReadOnly(bool enabled)

Parameters

enabled bool

Specifies whether or not the read-only state should be enabled.

ToString()

Returns a string representation of this Variable<TValue, TValidationResult> instance.

[Pure]
public override string ToString()

Returns

string

String representation.

TryChange(TValue)

Attempts to change the Value if the value to set is not equal to the current value.

public VariableChangeResult TryChange(TValue value)

Parameters

value TValue

Value to set.

Returns

VariableChangeResult

Result of this change attempt.

Update(TValue)

Updates value, errors, warnings and state of this variable.

protected virtual void Update(TValue value)

Parameters

value TValue

Value to set.

UpdateReadOnly(bool)

Updates state of this variable due to read-only state change.

protected virtual void UpdateReadOnly(bool enabled)

Parameters

enabled bool

Specifies whether or not the read-only state should be enabled.