Class TokenChangePosition
Represents a simple token-based change position for providers that use string continuation tokens.
public sealed class TokenChangePosition : ChangePosition, IEquatable<ChangePosition>
- Inheritance
-
TokenChangePosition
- Implements
- Inherited Members
- Extension Methods
Remarks
This implementation is suitable for providers like CosmosDB and DynamoDB that use opaque string tokens for position tracking. For providers with structured positions (e.g., Postgres LSN, SQL Server LSN/SeqVal), derive directly from ChangePosition.
Constructors
TokenChangePosition(string, DateTimeOffset?)
Initializes a new instance of the TokenChangePosition class.
public TokenChangePosition(string token, DateTimeOffset? timestamp = null)
Parameters
tokenstringThe continuation token representing this position.
timestampDateTimeOffset?Optional timestamp associated with this position.
Fields
Empty
Represents an invalid or uninitialized position.
public static readonly TokenChangePosition Empty
Field Value
Properties
IsValid
Gets a value indicating whether this position represents a valid point in the CDC stream.
public override bool IsValid { get; }
Property Value
- bool
true if this position can be used to resume CDC processing; false if this is an invalid or uninitialized position.
Remarks
Invalid positions typically represent:
- Uninitialized default positions
- Positions that have been invalidated (e.g., WAL segment recycled)
- Sentinel values indicating "start from beginning" or "no checkpoint"
Timestamp
Gets the timestamp associated with this position, if available.
public override DateTimeOffset? Timestamp { get; }
Property Value
- DateTimeOffset?
The timestamp when the change at this position occurred, or null if the provider does not support position timestamps.
Remarks
Not all providers include timestamps in their position representation. When available, this can be used for time-based CDC resumption or monitoring.
Token
Gets the continuation token representing this position.
public string Token { get; }
Property Value
Methods
Equals(ChangePosition?)
Indicates whether the current object is equal to another object of the same type.
public override bool Equals(ChangePosition? other)
Parameters
otherChangePositionAn object to compare with this object.
Returns
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
Parse(string)
Parses a token string to create a TokenChangePosition.
public static TokenChangePosition Parse(string token)
Parameters
tokenstringThe token to parse.
Returns
ToToken()
Converts this position to a string token suitable for storage and resumption.
public override string ToToken()
Returns
- string
A string representation of this position that can be persisted and later used to resume CDC processing from this point.
Remarks
The token format is provider-specific but must be round-trippable through
the corresponding Parse method on the derived type.
TryParse(string?, out TokenChangePosition)
Tries to parse a token string to create a TokenChangePosition.
public static bool TryParse(string? token, out TokenChangePosition position)
Parameters
tokenstringThe token to parse.
positionTokenChangePositionWhen successful, contains the parsed position.