Language

TurnState Class

Definition

Per-turn state storage backed by a dictionary, supporting both key-value and typed object access. This type is not thread-safe; each instance is scoped to a single turn.

public class TurnState
type TurnState = class
Public Class TurnState
Inheritance
TurnState

Constructors

Name Description
TurnState()

Initializes a new, empty TurnState.

Properties

Name Description
IsCompleted

Returns true once this state scope has been sealed at end of turn.

IsDirty

Returns true if any value has been added, modified, or removed since the state was loaded.

IsEmpty

Returns true when the scope contains no values.

Methods

Name Description
Clear()

Removes every value from the scope. A persisted scope emptied this way is deleted from storage on save.

ContainsKey(String)

Returns true if the key exists in state.

FromDictionary(Dictionary<String,Object>)

Creates a TurnState from an existing dictionary. Useful for testing.

FromJsonBytes(Byte[])

Deserializes a TurnState from a JSON byte array. Returns an empty, non-dirty state when bytes is null or empty.

Get<T>()

Gets a typed state object. Creates a new instance via parameterless constructor if not present.

Get<T>(String)

Gets a value by key. Returns default if the key is not present or the value cannot be converted.

Has<T>()

Returns true if a typed state object of this type exists.

Remove(String)

Removes a key from state.

Remove<T>()

Removes the typed state object of this type.

Set<T>(String, T)

Sets a value by key.

Set<T>(T)

Sets a typed state object, replacing any existing instance of the same type.

ToJsonBytes()

Serializes the state to a JSON byte array.

TryGet<T>(String, T)

Attempts to get a value by key. Returns true if the key exists and the value can be converted to T.

Applies to