ReteEngine 1.0
A rules engine and builder
Loading...
Searching...
No Matches
ReteCore.Token Class Reference

Represents a chain of named facts used to track the state and ancestry of rule evaluation in a rule engine. More...

Inheritance diagram for ReteCore.Token:

Public Member Functions

 Token (string name, object initialFact)
 Initializes a new instance of the Token class with the specified name and initial fact.
 Token (Token parent, string nextName, object newFact)
 Initializes a new instance of the Token class by extending the specified parent token with an additional named fact.
Get< T > (string name)
 Retrieves a fact by name and type from the collection.
override string ToString ()
bool Equals (Token? other)
override bool Equals (object? obj)
override int GetHashCode ()

Static Public Member Functions

static bool operator== (Token? left, Token? right)
static bool operator!= (Token? left, Token? right)

Properties

Dictionary< string, object > NamedFacts = new Dictionary<string, object>() [get]
 Gets a collection of named facts associated with the current instance.
Token Parent [get, set]
 Gets or sets the parent token of this token.
object Fact [get]
 Gets the fact associated with this instance.

Detailed Description

Represents a chain of named facts used to track the state and ancestry of rule evaluation in a rule engine.

A Token encapsulates a set of named facts and maintains a reference to its parent token, forming a linked structure that represents the progression of matched facts in a rule evaluation process. Tokens are typically used to accumulate and access facts as rules are matched and extended. Instances are considered equal if their facts and parent tokens are equal. This class is not thread-safe.

Constructor & Destructor Documentation

◆ Token() [1/2]

ReteCore.Token.Token ( string name,
object initialFact )

Initializes a new instance of the Token class with the specified name and initial fact.

Parameters
nameThe name to associate with the initial fact. Cannot be null.
initialFactThe initial fact to store in the token. Can be any object.

◆ Token() [2/2]

ReteCore.Token.Token ( Token parent,
string nextName,
object newFact )

Initializes a new instance of the Token class by extending the specified parent token with an additional named fact.

This constructor creates a new Token that inherits all named facts from the parent token and adds a new fact under the specified name. The resulting Token will contain all facts from the parent, plus the new fact.

Parameters
parentThe parent Token whose named facts are to be copied and extended. Cannot be null.
nextNameThe name to associate with the new fact being added. Cannot be null or empty.
newFactThe fact object to associate with the specified name. Can be any object.

Member Function Documentation

◆ Get< T >()

T ReteCore.Token.Get< T > ( string name)

Retrieves a fact by name and type from the collection.

If the fact exists but is not of type T, this method treats it as not found and throws a KeyNotFoundException.

Template Parameters
TThe expected type of the fact to retrieve.
Parameters
nameThe name of the fact to retrieve. Cannot be null.
Returns
The fact associated with the specified name, cast to type T.
Exceptions
KeyNotFoundExceptionThrown if a fact with the specified name and type T does not exist in the collection.

Property Documentation

◆ NamedFacts

Dictionary<string, object> ReteCore.Token.NamedFacts = new Dictionary<string, object>()
get

Gets a collection of named facts associated with the current instance.

The dictionary maps fact names to their corresponding values. The collection is read-only; to add or modify facts, use the provided methods or constructors of the containing class, if available.


The documentation for this class was generated from the following file:
  • ReteCore/Token.cs