Class CollectionVariable<TKey, TElement, TValidationResult>
Represents a generic collection variable.
public class CollectionVariable<TKey, TElement, TValidationResult> : VariableNode, ICollectionVariable<TKey, TElement, TValidationResult>, IReadOnlyCollectionVariable<TKey, TElement, TValidationResult>, IReadOnlyCollectionVariable<TKey, TElement>, IReadOnlyCollectionVariable, IMutableVariableNode, IVariableNode, IDisposable where TKey : notnull where TElement : notnull
Type Parameters
TKeyKey type.
TElementElement type.
TValidationResultValidation result type.
- Inheritance
-
CollectionVariable<TKey, TElement, TValidationResult>
- Implements
-
ICollectionVariable<TKey, TElement, TValidationResult>IReadOnlyCollectionVariable<TKey, TElement, TValidationResult>IReadOnlyCollectionVariable<TKey, TElement>
- Inherited Members
- Extension Methods
Constructors
CollectionVariable(IEnumerable<TElement>, IEnumerable<TElement>, Func<TElement, TKey>, IEqualityComparer<TKey>?, IEqualityComparer<TElement>?, IValidator<ICollectionVariableElements<TKey, TElement, TValidationResult>, TValidationResult>?, IValidator<ICollectionVariableElements<TKey, TElement, TValidationResult>, TValidationResult>?, IValidator<TElement, TValidationResult>?, IValidator<TElement, TValidationResult>?)
Creates a new CollectionVariable<TKey, TElement, TValidationResult> instance.
public CollectionVariable(IEnumerable<TElement> initialElements, IEnumerable<TElement> elements, Func<TElement, TKey> keySelector, IEqualityComparer<TKey>? keyComparer = null, IEqualityComparer<TElement>? elementComparer = null, IValidator<ICollectionVariableElements<TKey, TElement, TValidationResult>, TValidationResult>? errorsValidator = null, IValidator<ICollectionVariableElements<TKey, TElement, TValidationResult>, TValidationResult>? warningsValidator = null, IValidator<TElement, TValidationResult>? elementErrorsValidator = null, IValidator<TElement, TValidationResult>? elementWarningsValidator = null)
Parameters
initialElementsIEnumerable<TElement>Initial collection of elements.
elementsIEnumerable<TElement>Current collection of elements.
keySelectorFunc<TElement, TKey>Element's key selector.
keyComparerIEqualityComparer<TKey>Element key equality comparer.
elementComparerIEqualityComparer<TElement>Element equality comparer.
errorsValidatorIValidator<ICollectionVariableElements<TKey, TElement, TValidationResult>, TValidationResult>Collection of elements validator that marks result as errors.
warningsValidatorIValidator<ICollectionVariableElements<TKey, TElement, TValidationResult>, TValidationResult>Collection of elements validator that marks result as warnings.
elementErrorsValidatorIValidator<TElement, TValidationResult>Element validator that marks result as errors.
elementWarningsValidatorIValidator<TElement, TValidationResult>Element validator that marks result as warnings.
CollectionVariable(IEnumerable<TElement>, Func<TElement, TKey>, IEqualityComparer<TKey>?, IEqualityComparer<TElement>?, IValidator<ICollectionVariableElements<TKey, TElement, TValidationResult>, TValidationResult>?, IValidator<ICollectionVariableElements<TKey, TElement, TValidationResult>, TValidationResult>?, IValidator<TElement, TValidationResult>?, IValidator<TElement, TValidationResult>?)
Creates a new CollectionVariable<TKey, TElement, TValidationResult> instance.
public CollectionVariable(IEnumerable<TElement> initialElements, Func<TElement, TKey> keySelector, IEqualityComparer<TKey>? keyComparer = null, IEqualityComparer<TElement>? elementComparer = null, IValidator<ICollectionVariableElements<TKey, TElement, TValidationResult>, TValidationResult>? errorsValidator = null, IValidator<ICollectionVariableElements<TKey, TElement, TValidationResult>, TValidationResult>? warningsValidator = null, IValidator<TElement, TValidationResult>? elementErrorsValidator = null, IValidator<TElement, TValidationResult>? elementWarningsValidator = null)
Parameters
initialElementsIEnumerable<TElement>Initial collection of elements.
keySelectorFunc<TElement, TKey>Element's key selector.
keyComparerIEqualityComparer<TKey>Element key equality comparer.
elementComparerIEqualityComparer<TElement>Element equality comparer.
errorsValidatorIValidator<ICollectionVariableElements<TKey, TElement, TValidationResult>, TValidationResult>Collection of elements validator that marks result as errors.
warningsValidatorIValidator<ICollectionVariableElements<TKey, TElement, TValidationResult>, TValidationResult>Collection of elements validator that marks result as warnings.
elementErrorsValidatorIValidator<TElement, TValidationResult>Element validator that marks result as errors.
elementWarningsValidatorIValidator<TElement, TValidationResult>Element validator that marks result as warnings.
Properties
Elements
Current collection of elements.
public ICollectionVariableElements<TKey, TElement, TValidationResult> Elements { get; }
Property Value
- ICollectionVariableElements<TKey, TElement, TValidationResult>
Errors
Collection of current validation errors.
public Chain<TValidationResult> Errors { get; }
Property Value
- Chain<TValidationResult>
ErrorsValidator
Collection of elements validator that marks result as errors.
public IValidator<ICollectionVariableElements<TKey, TElement, TValidationResult>, TValidationResult> ErrorsValidator { get; }
Property Value
- IValidator<ICollectionVariableElements<TKey, TElement, TValidationResult>, TValidationResult>
InitialElements
Initial collection of elements.
public IReadOnlyDictionary<TKey, TElement> InitialElements { get; }
Property Value
- IReadOnlyDictionary<TKey, TElement>
KeySelector
Element's key selector.
public Func<TElement, TKey> KeySelector { get; }
Property Value
- Func<TElement, TKey>
OnChange
Event stream that emits events when variable's elements change.
public override sealed IEventStream<CollectionVariableChangeEvent<TKey, TElement, TValidationResult>> OnChange { get; }
Property Value
- IEventStream<CollectionVariableChangeEvent<TKey, TElement, TValidationResult>>
OnValidate
Event stream that emits events when variable's validation state changes.
public override sealed IEventStream<CollectionVariableValidationEvent<TKey, TElement, TValidationResult>> OnValidate { get; }
Property Value
- IEventStream<CollectionVariableValidationEvent<TKey, TElement, TValidationResult>>
State
Specifies this node's current state.
public override sealed VariableState State { get; }
Property Value
Warnings
Collection of current validation warnings.
public Chain<TValidationResult> Warnings { get; }
Property Value
- Chain<TValidationResult>
WarningsValidator
Collection of elements validator that marks result as warnings.
public IValidator<ICollectionVariableElements<TKey, TElement, TValidationResult>, TValidationResult> WarningsValidator { get; }
Property Value
- IValidator<ICollectionVariableElements<TKey, TElement, TValidationResult>, TValidationResult>
Methods
Add(IEnumerable<TElement>)
Adds a collection of elements to this collection.
public VariableChangeResult Add(IEnumerable<TElement> elements)
Parameters
elementsIEnumerable<TElement>Collection of elements to add.
Returns
- VariableChangeResult
Result of this change attempt.
Add(TElement)
Adds an element to this collection.
public VariableChangeResult Add(TElement element)
Parameters
elementTElementElement to add.
Returns
- VariableChangeResult
Result of this change attempt.
AddOrReplace(IEnumerable<TElement>)
Adds or replaces a collection of elements in this collection.
public VariableChangeResult AddOrReplace(IEnumerable<TElement> elements)
Parameters
elementsIEnumerable<TElement>Collection of elements to add or to replace with.
Returns
- VariableChangeResult
Result of this change attempt.
AddOrReplace(TElement)
Adds or replaces an element in this collection.
public VariableChangeResult AddOrReplace(TElement element)
Parameters
elementTElementElement to add or to replace with.
Returns
- VariableChangeResult
Result of this change attempt.
AddOrTryReplace(IEnumerable<TElement>)
Adds or attempts to replace a collection of elements in this collection. Existing elements will not be replaced when they and their replacements are considered to be equal.
public VariableChangeResult AddOrTryReplace(IEnumerable<TElement> elements)
Parameters
elementsIEnumerable<TElement>Collection of elements to add or to replace with.
Returns
- VariableChangeResult
Result of this change attempt.
AddOrTryReplace(TElement)
Adds or attempts to replace an element in this collection. Existing elements will not be replaced when they and their replacements are considered to be equal.
public VariableChangeResult AddOrTryReplace(TElement element)
Parameters
elementTElementElement to add or to replace with.
Returns
- VariableChangeResult
Result of this change attempt.
Change(IEnumerable<TElement>)
Changes the Elements. Elements that exist and are considered equal are registered as replaced.
public VariableChangeResult Change(IEnumerable<TElement> elements)
Parameters
elementsIEnumerable<TElement>Elements to set.
Returns
- VariableChangeResult
Result of this change attempt.
Clear()
Removes all elements from this collection.
public VariableChangeResult Clear()
Returns
- VariableChangeResult
Result of this change attempt.
ClearValidation()
Removes all errors and warnings from this variable.
public void ClearValidation()
ClearValidation(IEnumerable<TKey>)
Clears validation of elements associated with the provided collection keys.
public void ClearValidation(IEnumerable<TKey> keys)
Parameters
keysIEnumerable<TKey>Collection of keys to refresh.
ClearValidation(TKey)
Clears validation of an element associated with the provided key.
public void ClearValidation(TKey key)
Parameters
keyTKeyKey to refresh.
ContinueElementAddition(TElement)
Performs optional element addition validation.
[Pure]
protected virtual bool ContinueElementAddition(TElement element)
Parameters
elementTElementElement to add.
Returns
- bool
true to continue element addition, otherwise false.
ContinueElementRemoval(TElement)
Performs optional element removal validation.
[Pure]
protected virtual bool ContinueElementRemoval(TElement element)
Parameters
elementTElementElement to remove.
Returns
- bool
true to continue element removal, otherwise false.
ContinueElementReplacement(TElement, TElement)
Performs optional element replacement validation.
[Pure]
protected virtual bool ContinueElementReplacement(TElement element, TElement replacement)
Parameters
elementTElementElement to replace.
replacementTElementElement's replacement.
Returns
- bool
true to continue element replacement, otherwise false.
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.
ModifyChangeInput(IEnumerable<TElement>)
Allows to modify collection of elements to set.
[Pure]
protected virtual IEnumerable<TElement> ModifyChangeInput(IEnumerable<TElement> elements)
Parameters
elementsIEnumerable<TElement>Elements to set.
Returns
- IEnumerable<TElement>
Elements to actually set.
OnPublishChangeEvent(CollectionVariableChangeEvent<TKey, TElement, TValidationResult>)
Emits the provided change event.
protected virtual void OnPublishChangeEvent(CollectionVariableChangeEvent<TKey, TElement, TValidationResult> @event)
Parameters
eventCollectionVariableChangeEvent<TKey, TElement, TValidationResult>Event to publish.
OnPublishValidationEvent(CollectionVariableValidationEvent<TKey, TElement, TValidationResult>)
Emits the provided validation event.
protected virtual void OnPublishValidationEvent(CollectionVariableValidationEvent<TKey, TElement, TValidationResult> @event)
Parameters
eventCollectionVariableValidationEvent<TKey, TElement, TValidationResult>Event to publish.
Refresh()
Refreshes this variable.
public void Refresh()
Refresh(IEnumerable<TKey>)
Refreshes elements associated with the provided collection keys.
public void Refresh(IEnumerable<TKey> keys)
Parameters
keysIEnumerable<TKey>Collection of keys to refresh.
Refresh(TKey)
Refreshes an element associated with the provided key.
public void Refresh(TKey key)
Parameters
keyTKeyKey to refresh.
RefreshValidation()
Refreshes this variable's validation.
public void RefreshValidation()
RefreshValidation(IEnumerable<TKey>)
Refreshes validation of elements associated with the provided collection keys.
public void RefreshValidation(IEnumerable<TKey> keys)
Parameters
keysIEnumerable<TKey>Collection of keys to refresh.
RefreshValidation(TKey)
Refreshes validation of an element associated with the provided key.
public void RefreshValidation(TKey key)
Parameters
keyTKeyKey to refresh.
Remove(IEnumerable<TKey>)
Removes elements associated with the provided collection of keys.
public VariableChangeResult Remove(IEnumerable<TKey> keys)
Parameters
keysIEnumerable<TKey>Collection of keys to remove.
Returns
- VariableChangeResult
Result of this change attempt.
Remove(TKey)
Removes an element associated with the provided key.
public VariableChangeResult Remove(TKey key)
Parameters
keyTKeyKey to remove.
Returns
- VariableChangeResult
Result of this change attempt.
Replace(IEnumerable<TElement>)
Replaces a collection of existing elements in this collection.
public VariableChangeResult Replace(IEnumerable<TElement> elements)
Parameters
elementsIEnumerable<TElement>Collection of element replacements.
Returns
- VariableChangeResult
Result of this change attempt.
Replace(TElement)
Replaces an existing element in this collection.
public VariableChangeResult Replace(TElement element)
Parameters
elementTElementElement's replacement.
Returns
- VariableChangeResult
Result of this change attempt.
Reset(IEnumerable<TElement>)
Removes all errors and warnings from this variable and resets InitialElements and Elements.
public void Reset(IEnumerable<TElement> initialElements)
Parameters
initialElementsIEnumerable<TElement>Initial elements to set.
Reset(IEnumerable<TElement>, IEnumerable<TElement>)
Removes all errors and warnings from this variable and resets InitialElements and Elements.
public void Reset(IEnumerable<TElement> initialElements, IEnumerable<TElement> elements)
Parameters
initialElementsIEnumerable<TElement>Initial elements to set.
elementsIEnumerable<TElement>Elements to set.
SetReadOnly(bool)
Changes the read-only state of this variable.
public void SetReadOnly(bool enabled)
Parameters
enabledboolSpecifies whether or not the read-only state should be enabled.
ToString()
Returns a string representation of this CollectionVariable<TKey, TElement, TValidationResult> instance.
[Pure]
public override string ToString()
Returns
- string
String representation.
TryChange(IEnumerable<TElement>)
Attempts to change the Elements. Elements that exist and are considered equal are registered as refreshed.
public VariableChangeResult TryChange(IEnumerable<TElement> elements)
Parameters
elementsIEnumerable<TElement>Elements to set.
Returns
- VariableChangeResult
Result of this change attempt.
TryReplace(IEnumerable<TElement>)
Replaces a collection of existing elements in this collection, unless they and their replacements are considered to be equal.
public VariableChangeResult TryReplace(IEnumerable<TElement> elements)
Parameters
elementsIEnumerable<TElement>Collection of element replacements.
Returns
- VariableChangeResult
Result of this change attempt.
TryReplace(TElement)
Attempts to replace an existing element in this collection, unless it and its replacement are considered to be equal.
public VariableChangeResult TryReplace(TElement element)
Parameters
elementTElementElement's replacement.
Returns
- VariableChangeResult
Result of this change attempt.
Update()
Updates errors, warnings and state of this variable.
protected virtual void Update()
UpdateReadOnly(bool)
Updates state of this variable due to read-only state change.
protected virtual void UpdateReadOnly(bool enabled)
Parameters
enabledboolSpecifies whether or not the read-only state should be enabled.