Show / Hide Table of Contents

Class RuleContext

A read-only model for contextual information related to the execution of a validation rule.

Inheritance
System.Object
ValueContext
RuleContext
Inherited Members
ValueContext.ObjectIdentity
ValueContext.ValueInfo
ValueContext.ActualValue
ValueContext.CollectionItemOrder
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: CSF.Validation.Rules
Assembly: CSF.Validation.Abstractions.dll
Syntax
public class RuleContext : ValueContext

Constructors

| Improve this Doc View Source

RuleContext(ManifestRule, RuleIdentifier, Object, IEnumerable<ValueContext>, Type, Nullable<Int64>)

Initialises a new instance of RuleContext.

Declaration
public RuleContext(ManifestRule manifestRule, RuleIdentifier ruleIdentifier, object actualValue, IEnumerable<ValueContext> ancestorContexts, Type ruleInterface, long? collectionItemOrder = null)
Parameters
Type Name Description
ManifestRule manifestRule

The manifest rule from which this context was created.

RuleIdentifier ruleIdentifier

The rule identifier.

System.Object actualValue

The actual validated value.

System.Collections.Generic.IEnumerable<ValueContext> ancestorContexts

A collection of ancestor contexts.

System.Type ruleInterface

The rule interface used for this rule execution.

System.Nullable<System.Int64> collectionItemOrder

An optional collection item order.

Exceptions
Type Condition
System.ArgumentNullException

Properties

| Improve this Doc View Source

AncestorContexts

Gets a collection of the ancestor validation contexts.

Declaration
public IReadOnlyList<ValueContext> AncestorContexts { get; }
Property Value
Type Description
System.Collections.Generic.IReadOnlyList<ValueContext>
Remarks

When either of the following methods is used (using a validator builder), a 'child' validation context is created and the rules which are added are placed into that new child content.

  • AddRules<TBuilder>()
  • AddRules<TBuilder>()

Equivalents to the above exist for the Manifest Model: Children and also for a Validation Manifest: Children.

If the currently-executing validation rule lies within a child context, this property provides access to all of the ancestor contexts, such as parents & grandparents. This collection may be treated a little like a 'stack'. The first item in this collection is the immediate parent context, the second item is the grandparent, the third the great-grandparent and so on. As many parent contexts are available from this collection as required in order to traverse back to the root validation context. The root validation context is the validator that was initially built and not imported into an existing validator via an AddRules method.

If the currently-executing validation rule is not part of a child context then this collection will be empty indicating that there are no ancestor contexts.

When using the IRule<TValue, TParent> interface, the first ActualValue is made available as the second parameter to GetResultAsync(TValue, TParent, RuleContext, CancellationToken).

| Improve this Doc View Source

RuleIdentifier

Gets the identifier of the executed rule.

Declaration
public RuleIdentifier RuleIdentifier { get; }
Property Value
Type Description
RuleIdentifier
Remarks

This object provides identifying information about the currently-executing validation rule.

| Improve this Doc View Source

RuleInfo

Gets a ManifestRuleInfo with information about the configuration of the current rule.

Declaration
public ManifestRuleInfo RuleInfo { get; }
Property Value
Type Description
ManifestRuleInfo
| Improve this Doc View Source

RuleInterface

Gets a reference to the rule interface which was used in order to select & execute this rule.

Declaration
public Type RuleInterface { get; }
Property Value
Type Description
System.Type
Remarks

This will be a closed-generic form of either:

  • IRule<TValidated>
  • IRule<TValue, TParent>
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX