Class RuleWithParentValueAdapter<TValue, TValidated>
An adapter class for instances of IRule<TValue, TParent>, which allows their logic to be executed as if they were instances of the non-generic IValidationLogic interface.
Inheritance
Inherited Members
Namespace: CSF.Validation.Rules
Assembly: CSF.Validation.dll
Syntax
public class RuleWithParentValueAdapter<TValue, TValidated> : IValidationLogic, IHasRuleTimeout
Type Parameters
Name | Description |
---|---|
TValue | The type of value being validated by the current instance. |
TValidated | The type of parent object being validated by the current instance. |
Constructors
| Improve this Doc View SourceRuleWithParentValueAdapter(IRule<TValue, TValidated>)
Initialises an instance of RuleWithParentValueAdapter<TValue, TValidated> from a specified rule.
Declaration
public RuleWithParentValueAdapter(IRule<TValue, TValidated> wrapped)
Parameters
Type | Name | Description |
---|---|---|
IRule<TValue, TValidated> | wrapped | The rule logic to be wrapped by the current instance. |
Properties
| Improve this Doc View SourceRuleInterface
Gets the type of rule interface that is used by this rule logic.
Declaration
public Type RuleInterface { get; }
Property Value
Type | Description |
---|---|
System.Type |
Remarks
This will be a closed-generic form of either IRule<TValidated> or IRule<TValue, TParent>.
RuleObject
Gets a reference to the original/raw rule object instance.
Declaration
public object RuleObject { get; }
Property Value
Type | Description |
---|---|
System.Object |
Methods
| Improve this Doc View SourceGetResultAsync(Object, Object, RuleContext, CancellationToken)
Executes the logic of the validation rule and returns the result.
Declaration
public ValueTask<RuleResult> GetResultAsync(object value, object parentValue, RuleContext context, CancellationToken token = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
System.Object | value | The value which is being validated by the current rule. |
System.Object | parentValue | An optional 'parent value' to the value being validated by the current rule. This is
typically the object from which the |
RuleContext | context | A validation rule context object. |
System.Threading.CancellationToken | token | An optional cancellation token to abort the validation process early. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.ValueTask<RuleResult> | A task which provides the rule result. |
GetTimeout()
Gets the timeout value for the current rule.
Declaration
public TimeSpan? GetTimeout()
Returns
Type | Description |
---|---|
System.Nullable<System.TimeSpan> | A timespan indicating the timeout duration, or a null reference if no timeout is applicable. |
Remarks
If this method returns non-null & the execution of the rule takes longer than this timeout value then:
The rule will immediately return an error result. Additionally the CancellationToken passed to the rule will be cancelled, allowing the rule logic to terminate early.