Class ExceptionHandlingRuleLogicDecorator
A decorator class for the IValidationLogic interface which catches unhandled exceptions raised by the wrapped rule logic and instead returns a RuleResult with Errored.
Inheritance
Inherited Members
Namespace: CSF.Validation.Rules
Assembly: CSF.Validation.dll
Syntax
public class ExceptionHandlingRuleLogicDecorator : IValidationLogic, IHasRuleTimeout
Constructors
| Improve this Doc View SourceExceptionHandlingRuleLogicDecorator(IValidationLogic)
Initialises an instance of ExceptionHandlingRuleLogicDecorator.
Declaration
public ExceptionHandlingRuleLogicDecorator(IValidationLogic wrapped)
Parameters
Type | Name | Description |
---|---|---|
IValidationLogic | 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 async 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.