Table of Contents

Class RuleBuilder<T>

Namespace
JD.Domain.Rules
Assembly
JD.Domain.Rules.dll

Fluent builder for configuring individual rules.

public sealed class RuleBuilder<T> where T : class

Type Parameters

T

The entity type.

Inheritance
RuleBuilder<T>
Inherited Members

Methods

Build()

Builds the rule set manifest.

public RuleSetManifest Build()

Returns

RuleSetManifest

The constructed rule set manifest.

BuildCompiled()

Builds a compiled rule set that can be evaluated at runtime.

public CompiledRuleSet<T> BuildCompiled()

Returns

CompiledRuleSet<T>

The compiled rule set.

Invariant(string, Expression<Func<T, bool>>)

Adds another invariant rule to the rule set.

public RuleBuilder<T> Invariant(string id, Expression<Func<T, bool>> predicate)

Parameters

id string

The unique identifier for the rule.

predicate Expression<Func<T, bool>>

The rule predicate expression.

Returns

RuleBuilder<T>

A rule builder for further configuration.

Validator(string, Expression<Func<T, bool>>)

Adds a validator rule to the rule set.

public RuleBuilder<T> Validator(string id, Expression<Func<T, bool>> predicate)

Parameters

id string

The unique identifier for the rule.

predicate Expression<Func<T, bool>>

The rule predicate expression.

Returns

RuleBuilder<T>

A rule builder for further configuration.

WithMessage(string)

Sets the error message for rule violations.

public RuleBuilder<T> WithMessage(string message)

Parameters

message string

The error message.

Returns

RuleBuilder<T>

The rule builder for chaining.

WithMetadata(string, object?)

Adds metadata to the rule.

public RuleBuilder<T> WithMetadata(string key, object? value)

Parameters

key string

The metadata key.

value object

The metadata value.

Returns

RuleBuilder<T>

The rule builder for chaining.

WithSeverity(RuleSeverity)

Sets the severity of rule violations.

public RuleBuilder<T> WithSeverity(RuleSeverity severity)

Parameters

severity RuleSeverity

The severity level.

Returns

RuleBuilder<T>

The rule builder for chaining.

WithTag(string)

Adds a tag to the rule for categorization.

public RuleBuilder<T> WithTag(string tag)

Parameters

tag string

The tag to add.

Returns

RuleBuilder<T>

The rule builder for chaining.